Blame SOURCES/ghostscript-cve-2018-16863.patch

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