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

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