From: Chris Liddell <chris.liddell@artifex.com>
Date: Sat, 25 Aug 2018 06:45:45 +0000 (+0100)
Subject: Bug 699654(2): preserve LockSafetyParams in the nulldevice
Bug 699654(2): preserve LockSafetyParams in the nulldevice
The nulldevice does not necessarily use the normal setpagedevice machinery,
but can be set using the nulldevice operator. In which case, we don't preserve
the settings from the original device (in the way setpagedevice does).
Since nulldevice does nothing, this is not generally a problem, but in the case
of LockSafetyParams it *is* important when we restore back to the original
device, when LockSafetyParams not being set is "preserved" into the post-
restore configuration.
We have to initialise the value to false because the nulldevice is used during
initialisation (before any other device exists), and *must* be writable for
that.
http://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=79cccf641486a6595c43f1de1cd7ade696020a31
From: Ken Sharp <ken.sharp@artifex.com>
Date: Tue, 28 Aug 2018 15:27:53 +0000 (+0100)
Subject: Bug #699654 (again) and Bug #699677 Improve operator removal for SAFER
Bug #699654 (again) and Bug #699677 Improve operator removal for SAFER
Take inspiration from the code to remove unused/dangerous operators
and, when SAFER is true, remove a bunch more non-standard operators
or routines.
In particular remove the .bindnow operator, which should have been
removed previously for Bug #699677 and remove the
.pushpdf14devicefilter for Bug #699654. Only the PDF interpreter
needs to use that, and the device in question only expects to be used
carefully and in the correct sequence. Make sure nobody can meddle with
it.
In addition I removed a number of other operators which are not needed
in normal operation. Some of them, however, are useful so these
(with the exception of .bindnow which is always removed) are only
undefined if SAFER is true.
This allows our QA procedure to continue to use them, which is
particularly important in the case of .makeoperator and .setCPSImode.
At a later date we may choose to move some of these into the regular
undefinition code, ie not dependent on SAFER.
https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=520bb0ea7519aa3e79db78aaf0589dae02103764
---
diff -up ghostscript-9.07/base/gsdevice.c.cve-2018-16863 ghostscript-9.07/base/gsdevice.c
--- ghostscript-9.07/base/gsdevice.c.cve-2018-16863 2018-11-26 10:45:38.685308279 +0100
+++ ghostscript-9.07/base/gsdevice.c 2018-11-26 11:42:31.405515105 +0100
@@ -599,13 +599,17 @@ gx_device_retain(gx_device *dev, bool re
int
gs_nulldevice(gs_state * pgs)
{
+ int code = 0;
+ bool saveLockSafety = false;
if (pgs->device == 0 || !gx_device_is_null(pgs->device)) {
gx_device *ndev;
- int code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device,
+ code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device,
pgs->memory);
if (code < 0)
return code;
+ if (gs_currentdevice_inline(pgs) != NULL)
+ saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams;
/*
* Internal devices have a reference count of 0, not 1,
* aside from references from graphics states.
@@ -623,9 +627,11 @@ gs_nulldevice(gs_state * pgs)
set_dev_proc(ndev, get_profile, gx_default_get_profile);
}
- return gs_setdevice_no_erase(pgs, ndev);
+ if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0)
+ gs_free_object(pgs->memory, ndev, "gs_copydevice(device)");
+ gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety;
}
- return 0;
+ return code;
}
/* Close a device. The client is responsible for ensuring that */
diff -up ghostscript-9.07/Resource/Init/gs_init.ps.cve-2018-16863 ghostscript-9.07/Resource/Init/gs_init.ps
--- ghostscript-9.07/Resource/Init/gs_init.ps.cve-2018-16863 2018-11-26 10:51:31.658358967 +0100
+++ ghostscript-9.07/Resource/Init/gs_init.ps 2018-11-26 11:39:03.566039786 +0100
@@ -2083,6 +2083,26 @@ readonly def
% If we are running in SAFER mode, lock things down
SAFER { .setsafe } if
+/SAFERUndefinePostScriptOperators {
+[
+% Used by our own test suite files
+/.pushpdf14devicefilter % transparency-example.ps
+/.poppdf14devicefilter % transparency-example.ps
+/.setopacityalpha % transparency-example.ps
+/.setshapealpha % transparency-example.ps
+/.endtransparencygroup % transparency-example.ps
+/.setdotlength % Bug687720.ps
+/.sort /.setdebug /.mementolistnewblocks /getenv
+
+/.makeoperator /.setCPSImode % gs_cet.ps, this won't work on cluster with -dSAFER
+
+/unread
+]
+{systemdict exch .forceundef} forall
+
+//systemdict /SAFERUndefinePostScriptOperators .forceundef
+}bind def
+
/UndefinePostScriptOperators {
%% This list is of Display PostScript operators. We believe that Display PostScript
@@ -2153,7 +2173,7 @@ SAFER { .setsafe } if
%/.buildfotn32 /.buildfont42 /.type9mapcid /.type11mapcid /.swapcolors
%/currentdevice /.quit /.setuseciecolor /.needinput /.setoverprintmode /.special_op /.dicttomark /.knownget
%/.FAPIavailable /.FAPIpassfont /.FAPIrebuildfont /.FAPIBuildGlyph /.FAPIBuildChar /.FAPIBuildGlyph9
-%/.tempfile /.numicc_components /.set_outputintent /.max /.min /.shfill /.vmreclaim /.getpath /.setglobal
+%/.tempfile /.numicc_components /.set_outputintent /.max /.min /.vmreclaim /.getpath /.setglobal
%/.setdebug /.mementolistnewblocks /getenv
]
{systemdict exch .forceundef} forall
@@ -2180,13 +2200,6 @@ SAFER { .setsafe } if
/.settextspacing /.currenttextspacing /.settextleading /.currenttextleading /.settextrise /.currenttextrise
/.setwordspacing /.currentwordspacing /.settexthscaling /.currenttexthscaling
-% Used by our own test suite files
-%/.pushpdf14devicefilter % transparency-example.ps
-%/.poppdf14devicefilter % transparency-example.ps
-%/.setopacityalpha % transparency-example.ps
-%/.setshapealpha % transparency-example.ps
-%/.endtransparencygroup % transparency-example.ps
-
% undefining these causes errors/incorrect output
%/.settextrenderingmode /.setblendmode /.begintransparencygroup /.settextknockout /check_r6_password /.setstrokeoverprint /.setfilloverprint
%/.currentstrokeoverprint /.currentfilloverprint /.currentfillconstantalpha /.currentstrokeconstantalpha
@@ -2208,6 +2221,9 @@ SAFER { .setsafe } if
//systemdict /.delaybind {} .forceput % reclaim the space
//systemdict /.bindnow .forceundef % ditto
put
+ SAFER {
+ //systemdict /SAFERUndefinePostScriptOperators get exec
+ } if
% //systemdict /UndefinePostScriptOperators get exec
% //systemdict /UndefinePDFOperators get exec
//systemdict /.forcecopynew .forceundef % remove temptation
@@ -2313,6 +2329,9 @@ currentdict /.renderingintentdict .undef
%% If we are using DELAYBIND we have to defer the undefinition
%% until .bindnow.
DELAYBIND not {
+ SAFER {
+ //systemdict /SAFERUndefinePostScriptOperators get exec
+ } if
//systemdict /UndefinePostScriptOperators get exec
//systemdict /UndefinePDFOperators .forceundef
} if
@@ -2323,6 +2342,7 @@ end
{ pop NOGC not { 2 .vmreclaim 0 vmreclaim } if
} if
DELAYBIND not {
+ systemdict /.bindnow .undef % We only need this for DELAYBIND
systemdict /.forcecopynew .undef % remove temptation
systemdict /.forcedef .undef % ditto
systemdict /.forceput .undef % ditto