psf-ghostscript-upload2shell-check(8)
Ghostscript Upload2Shell -dSAFER sandbox escape check/mitigate (v1)
CVE-2026-125396
If this software is helpful, consider a donation to our 501c3 nonprofit:
https://privacysafe.foundation
CVE-2026-125396 ("Upload2Shell"), found by pwn.ai, fixed in Ghostscript
10.08.0. A use-after-free in the Type 1 font loader: the .putgstringcopy
procedure in gs_fonts.ps calls the privileged .forceput operator without
checking operand types; a crafted font in a PostScript, EPS or PDF
document triggers a type error, a custom error handler recovers
.forceput, and a use-after-free across a save/restore boundary lets the
attacker execute arbitrary code as the user running Ghostscript, even
with -dSAFER set. No Ghostscript setting disables Type 1 font loading, so
there is no in-Ghostscript configuration workaround; the only fixes are
upgrading Ghostscript itself or keeping files that might contain crafted
fonts away from it entirely (see 'mitigate' and 'rules').
The file does not need to look like a PostScript file: Ghostscript (and
the libraries that silently invoke it) identify the format by content,
not by name or declared MIME type, so a file uploaded as '.png' or
'.jpg' that is actually PostScript, EPS or a PDF carrying an embedded
Type 1 font still reaches this code path. pwn.ai's own write-up
documents working chains through, among others: ImageMagick/Imagick
(its default delegate for PS/EPS/PDF input), Pillow (which opens EPS by
shelling out to Ghostscript once pixels are requested, a separate issue
from Pillow's own CVE-2026-112900), WordPress uploads by Authors and
above or a public upload form (WordPress's own CVE-2026-65640 covers
that specific upload route), Roundcube attachment thumbnails (fixed
separately in Roundcube's own CVE-2026-114727), DokuWiki's image resize
pipeline, and CUPS print queues shared without a login. On a desktop,
simply opening a malicious file in a Ghostscript-based viewer is enough.
Usage:
./ghostscript-upload2shell-check.sh [command] [...]
check - read-only. Finds every Ghostscript install this host's
package manager knows about (dpkg or rpm) plus any gs
binary on PATH, and reports each one's version against
10.08.0. A distribution's own backport is checked against
its own package changelog the same way other scripts in
this collection handle a backport that does not change
the upstream version string. One real trap: Ghostscript's
own 10.08.0 release candidate, tagged before the fix
commit, also reports its version as plain "10.08.0" with
nothing in `gs --version` distinguishing it from the final
release; this script cannot tell the two apart from the
version string alone and says so wherever gs reports
exactly 10.08.0 outside a distribution package. Also
audits ImageMagick's policy.xml, if present, for whether
the PS/EPS/XPS coders this mitigation would disable are
already blocked. Exits 1 if an exposed Ghostscript is
found (or the RC ambiguity could not be resolved), 0 if
every one found is confirmed at or above the fix (or
fully blocked by policy.xml), 2 if none was found.
hunt - read-only. Looks for Ghostscript crash signatures (a
segfault or abort naming gs, libgs, or a Type 1 charstring
routine) in the system journal and dmesg; this is a weak
signal at best, since a successful exploit need not crash
the process, and an unrelated Ghostscript bug could also
produce the same crash signature.
mitigate [--include-pdf] [--dry-run] [--force] - adds the
long-standing community-documented ImageMagick policy.xml
lines that block the PS, PS2, PS3, EPS and XPS coders (the
formats always routed through Ghostscript with no
alternative renderer), backing up the file first and
checking the result is still well-formed XML. PDF is left
alone by default, since many ImageMagick users genuinely
need PDF read/write and not every PDF workflow touches
Ghostscript's Type 1 loader; --include-pdf also blocks the
PDF coder, which is more thorough but breaks any PDF
rasterization or thumbnailing ImageMagick does. This
covers only ImageMagick. It has no effect on Pillow,
WordPress, Roundcube, DokuWiki, or a print queue that
calls Ghostscript directly; see 'rules' for those.
Blocking these coders has a real cost, not just a benefit:
it stops ImageMagick processing those formats at all, even
where that is wanted. So by default, mitigate only acts
when 'check' would report a Ghostscript here as exposed or
undetermined (never found counts as undetermined, not
clear, since that could mean a reachable copy this host's
package manager simply does not know about); when every
Ghostscript found is confirmed fixed, it changes nothing
and says so, unless --force is given to add the hardening
anyway regardless of what was found. Requires root (or
whatever account owns policy.xml), unless --dry-run is
given, which prints a diff of what would change and
writes nothing, so it needs no privilege (and skips the
exposure gate, so you can preview the change either way).
rollback [--dry-run] - restores the policy.xml 'mitigate' backed up.
Requires root, unless --dry-run is given, which prints
which file would be restored from which backup and
writes nothing, so it needs no privilege.
rules - prints the guidance 'mitigate' cannot automate: upgrading,
the Pillow formats= argument, WordPress and Roundcube
version thresholds, and print-queue authentication.
version - prints this script's version.
Environment: IMAGEMAGICK_POLICY_FILES, a space-separated list of
policy.xml paths, replacing the usual ImageMagick 6/7 locations.
FIXED_BUILDS, additional known-fixed distribution package strings,
space-separated, checked alongside the ones this script already knows.
PSF_BACKUP_DIR, where backups and the restore manifest are kept (default
/var/backups/psf-security-patches/ghostscript-upload2shell).
PSF_LOCK_WAIT: seconds a run that changes the host waits for another one
that is already changing it (default 30), then exit 2.The Security Patches software and this documentation are dedicated to the public domain under CC0 1.0 Universal. Other pages on privacysafe.app/docs are CC BY-SA 4.0 unless the page says otherwise.