跳到正文
DEV Community· frank chu·· 1 小時前AI 評分75

Ghostscript 字體漏洞如何透過 .png 檔案波及 10 款應用程式

Ghostscript's font bug reached 10 apps through a `.png`

AI 導讀

Ghostscript 的 CVE-2026-125396 字體載入器漏洞,可讓含 PostScript 內容、但副檔名為 .png 的檔案經由 10 款應用程式觸發遠端程式碼執行,並繞過 -dSAFER。

正文

Ghostscript's font bug reached 10 apps through a .png

A file named .png that contains PostScript can reach Ghostscript from ten different applications — and a use-after-free in Ghostscript's Type 1 font loader turns that into remote code execution, past the -dSAFER sandbox. CVE-2026-125396, published November 9. Pre-auth RCE was confirmed against Debian 13's CUPS, Roundcube, WordPress, and Google's own document pipeline.

The bug: an error handler that resumes in the wrong place

The writeup is from pwn.ai ("How We Hacked the Pipes"), and it is unusually complete. The flaw is in .putgstringcopy, a helper in Ghostscript's Resource/Init/gs_fonts.ps that loads Type 1 fonts. Ghostscript implements parts of its own font loading in PostScript, and this helper needed to write into protected font dictionaries, so it used an internal operation called .forceput. The relevant sequence in the vulnerable version:

dup length string copy
.forceput setglobal

The helper never checked that its operands were of the expected types. The researchers registered a Type 1 font in Fontmap, loaded it with findfont, and used the font's loading code to swap the filename string on the loader's operand stack for a local array. length and the string allocation succeeded; copy then raised typecheck because its source was an array. Their error handler returned with the stack prepared for the next operation in the already-bound helper — the privileged .forceput — with attacker-chosen dictionary, key, and value on the stack. They never called the hidden operator directly; the error did the calling for them.

A protected dictionary write alone is not native code execution. The next step broke a separate rule: a reference must not remain usable after its object has been reclaimed. .forceput temporarily treats systemdict as local while it stores the value, so the researchers could put a local array into a global dictionary that survives a later restore. After restore freed the local object, the dictionary still pointed at the storage — and reusing the allocation made the stale reference point at live interpreter memory. Their probe made the reuse visible before touching native memory:

/AttackSave save def
userdict /ForceValue 8 array put
userdict /ForceValue get 0 31337 put
{ /GSLoaderProbe findfont pop } stopped pop
AttackSave restore
8 array userdict exch /Replacement exch put
userdict /Replacement get 0 4242 put
systemdict /GS_FORCEPUT_DANGLING_ARRAY get 1 5151 put
userdict /Replacement get 1 get ==

If the freed allocation is reused, Replacement[1] reads 5151 — the write went through the stale reference, the read came back through the live one. Same bytes, two names. From there the native proof walks Ghostscript's own pointers (currentdevice → psi_device_ref → gx_device → gs_memory_t → gs_lib_ctx → path_control_active) and flips the flag that enforces -dSAFER. The sandbox is a check inside the interpreter, not a kernel filter — once you control interpreter memory, the check is just a byte.

One detail worth noting: the writeup credits the discovery to "GPT 5.6 Sol, working with @PaulosYibelo." An AI model found the bug; the humans built the exploit chain around it. The Ubuntu advisory names Paulos Yibelo as the discoverer of the operand-validation flaw.

The blast radius: ten confirmed executions

The researchers' index records ten application chains where execution was confirmed, not just theorized. The file never had to be a font or a PostScript document — it only had to reach a renderer:

Debian 13 CUPS        anonymous IPP print job to a shared queue   command as uid=7(lp)            20/20 local conversions
Roundcube 1.7.2       external sender; recipient views message    command as uid=33(www-data)     5/5 trials, no click
Forminator 1.55.1     signed-out public PDF form, WP 7.0.2        command as uid=33(www-data)     5/5 HTTP trials
Elementor Addons 6.7  signed-out login/register widget upload     command as uid=33(www-data)     5/5 HTTP trials
MediaWiki 1.46        anonymous PDF upload + thumbnail            command as uid=33(www-data)     5/5 HTTP trials
DokuWiki 2026-07-14  open wiki upload + resize                   command as uid=33(www-data)     5/5 HTTP trials
Mayan EDMS 4.11.5     email to a configured POP3 inbox            command as uid=1000 in container 1 email run; parser 5/5
ResourceSpace 11.0    authenticated upload / upload-share         command in the preview worker    5/5 API trials
WordPress Core        Author+ upload_files, Imagick + Ghostscript RCE confirmed, exact delegate as uid=33  10/10 trials
Plesk Obsidian 18     Roundcube thumbnail path, Ghostscript 9.54  command as uid=995(roundcube_sysuser) 5/5 trials

Roundcube is the one that should worry you: no attachment click, no login — an external sender's email gets thumbnailed when the recipient views the message, and the thumbnail path runs the proof as www-data. WordPress Core needed upload_files (Author+ by default), and the affected branches were 7.0.0–7.0.3 and 6.9.0–6.9.6; WordPress shipped its own fix as CVE-2026-65640. Google's image and document pipeline was reached with a signed-out request for an attacker-hosted file and mitigated November 10. Dropbox, Box, and Zoom are named in the teaser as reached; their individual case studies are still unpublished.

The common thread is not Ghostscript — it is the decoders in front of it. The researchers traced 145 benign calls across 29 image APIs. The ones that reached Ghostscript when handed EPS content, even named .png:

Pillow Image.load() / crop()          Pillow EPS decoder -> Ghostscript directly
imageio.imread() / skimage.io.imread() image reader -> Pillow -> Ghostscript
PHP Imagick::readImage()              ImageMagick PostScript delegate -> Ghostscript
libvips thumbnail()                   magickload -> ImageMagick -> Ghostscript (build dependent)
Qt QImageReader.read()                KImageFormats EPS plugin -> Ghostscript (plugin dependent)

PHP GD, OpenCV, prebuilt Sharp, Jimp, Java ImageIO, and Go's standard decoders did not start Ghostscript for these inputs. Copying or storing a file did not render it either — the later preview or conversion is the step to inspect. Image.open() alone only identifies the file; loading pixels is what starts the renderer.

I ran the route on my own machine

I did not run the exploit — the proof-of-concept is not public and the writeup omits the font setup. What I ran is the route, on a stock Ubuntu 24.04 box with nothing pre-installed:

$ apt-get install -y ghostscript
$ gs --version
10.02.1

First, the version question. Ubuntu's USN-8949-1 (October 21) lists exactly 10.02.1~dfsg1-0ubuntu7.10 as the fixed build for 24.04 noble — the version apt just installed. The vulnerable versions in the researchers' index were 10.05.1 (Debian 13, WordPress, Roundcube), 10.05.0 (Google), and 9.54.0 (Plesk). Upstream fixed it in 10.08.0 on September 8; Debian shipped 10.05.1~dfsg-1+deb13u3 on October 10.

Second, the fix itself, visible in the installed file. The patched .putgstringcopy in /usr/share/ghostscript/10.02.1/Resource/Init/gs_fonts.ps opens with the check the writeup says was missing:

/.putgstringcopy  %   <dict> <name> <string> .putgstringcopy -
{
  % Check operand types
  dup type /stringtype eq 2 index type /nametype eq and 3 index type /dicttype eq and {
    ...
      dup length string copy
      .forceput setglobal
    ...
  }
  {
      /.putgstringcopy cvx /typecheck signalerror
  } ifelse
} .bind executeonly odef

Same two lines — dup length string copy, .forceput setglobal — but now they only run after the operand types are verified, and a wrong type signals typecheck immediately, before any partial state exists for an error handler to resume into. The fix is a type check, not a sandbox redesign. That is the whole patch, and you can read it in a file your distro already ships.

Third, the Pillow route, end to end. I wrote a 100×100 EPS file, named it fake.png, and ran the exact call pattern from the writeup with Pillow 10.2.0:

$ python3 -c "from PIL import Image; im = Image.open('fake.png'); im.load()"
format: EPS size: (100, 100)
Pillow load OK, mode: RGB

Pillow trusts the bytes, not the name — it identified EPS content under a .png name and rendered it. To prove Ghostscript was the renderer and not something else, I hid gs from the PATH and ran the same code again:

load FAILED without gs: OSError Unable to locate Ghostscript on paths

Same file, same calls, only gs missing: the load fails. The route is live on this machine with the patched Ghostscript underneath it — which is exactly the configuration the researchers' matrix describes.

Fourth, the sandbox itself, on the patched build. A PostScript file that tries to read /etc/passwd:

$ gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=txtwrite -sOutputFile=- safer_probe.ps
Error: /invalidfileaccess in --file--

-dSAFER holds. The point of Upload2Shell is that the sandbox was never the weak part — the font loader was. A memory-safety bug in the interpreter lets an untrusted document rewrite the flag the sandbox checks, and then the sandbox is a byte that says yes.

What to do

Update Ghostscript. The fixed versions: upstream 10.08.0, Debian 10.05.1~dfsg-1+deb13u3, Ubuntu USN-8949-1 (noble: 10.02.1~dfsg1-0ubuntu7.10). Then audit the route, not the extension: any upload path that thumbnails, previews, crops, or converts images can hand EPS bytes to Ghostscript regardless of the filename. If your stack renders user-supplied images with Pillow, ImageMagick, libvips, or Qt image readers, the question is not "do we accept PostScript" — it is "does our decoder reach Ghostscript." The researchers' matrix is the checklist: Pillow, imageio, Imagick, libvips, and Qt's EPS plugin do; GD, OpenCV, Sharp, Jimp, Java ImageIO, and Go's standard decoders do not.

Limitations, stated plainly

  • I did not run the exploit. The proof-of-concept is not public, the writeup omits the font setup, and I did not attempt to reconstruct it. The UAF mechanics, the probe values (31337, 4242, 5151, 0x12345678), and the structure offsets are the researchers', from their writeup.
  • I tested the patched Ubuntu build only (10.02.1). I did not install a vulnerable version to confirm the exploit path, and the Pillow version here (10.2.0) is older than the researchers' tested 13.0.0 — the route behaved the same way.
  • The per-application trial counts (5/5, 10/10, 20/20) and the Google/Dropbox/Box/Zoom claims are the researchers'; the unpublished case studies may revise them.

Sources: pwn.ai, "How We Hacked the Pipes — Upload2Shell" (technical writeup); pwn.ai, "Upload2Shell · CVE-2026-125396" (evidence index); Ubuntu USN-8949-1: Ghostscript vulnerabilities (Oct 21, 2026); CVE-2026-125396. All local results are from my own Ubuntu 24.04 machine, November 21, 2026.

來源:DEV Community · dev.to