Blame SOURCES/ghostscript-remove-as-many-non-standard-operators-as-possible.patch

8812f8
From: Ken Sharp <ken.sharp@artifex.com>
8812f8
Date: Thu, 11 May 2017 12:09:29 +0000 (+0100)
8812f8
Subject: Remove as many non-standard operators as possible
8812f8
8812f8
Remove as many non-standard operators as possible
8812f8
8812f8
Remove all the Display PostScript operators and all the NeXT extensions
8812f8
8812f8
Remove all the operators which do not appear to be used in our code
8812f8
8812f8
Remove all the operators which are only used in bound procedures defined
8812f8
at startup and which can therefore subsequently be removed.
8812f8
8812f8
The operators to be undefined are stored in arrays in PostScript and
8812f8
the C support code is untouched. This means that it is relatively
8812f8
simple for an end user to restore an operator if required.
8812f8
8812f8
Operators which are used in our test suite files are listed in the
8812f8
arrays but commented out.
8812f8
8812f8
Operators which are used (by our own code) in a way which requires them
8812f8
to be present are also listed in the arrays, but commented out.
8812f8
8812f8
https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=1497d65039885a52b598b137dd8622bd4672f9be
8812f8
8812f8
From: Ken Sharp <ken.sharp@artifex.com>
8812f8
Date: Sat, 17 Jun 2017 10:17:52 +0000 (+0100)
8812f8
Subject: Make operator hiding work with DELAYBIND
8812f8
8812f8
Make operator hiding work with DELAYBIND
8812f8
8812f8
Commit 1497d65039885a52b598b137dd8622bd4672f9be undefines as many operators
8812f8
as possible once startup is completed, in order to prevent potantially
8812f8
malicious PostScript or PDF files using them.
8812f8
8812f8
However, if DELAYBIND (itself a gaping security hole if used) is
8812f8
specified, this leads to an endless loop. Instead we must undefine the
8812f8
operators during .bindnow (after the deferred binding has occured).
8812f8
8812f8
https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=971472c83a345a16dac9f90f91258bb22dd77f22
8812f8
---
8812f8
8812f8
diff -up a/Resource/Init/gs_init.ps.cve-2018-16585 b/Resource/Init/gs_init.ps
8812f8
--- a/Resource/Init/gs_init.ps.cve-2018-16585	2018-11-14 07:51:00.933247401 +0100
8812f8
+++ b/Resource/Init/gs_init.ps	2018-11-14 07:51:27.637826808 +0100
8812f8
@@ -2068,6 +2068,118 @@ readonly def
8812f8
 % If we are running in SAFER mode, lock things down
8812f8
 SAFER { .setsafe } if
8812f8
 
8812f8
+/UndefinePostScriptOperators {
8812f8
+
8812f8
+%% This list is of Display PostScript operators. We believe that Display PostScript
8812f8
+%% was never fully implemented and the only known user, GNUStep, is no longer
8812f8
+%% using it. So lets remove it.
8812f8
+[
8812f8
+/condition /currentcontext /detach /.fork /join /.localfork /lock /monitor /notify
8812f8
+/wait /yield /.currentscreenphase /.setscreenphase /.image2 /eoviewclip /initviewclip
8812f8
+/viewclip /viewclippath /defineusername
8812f8
+%% NeXT DPS extensions
8812f8
+/currentalpha /setalpha /.alphaimage /composite /compositerect /dissolve /sizeimagebox /.sizeimageparams
8812f8
+]
8812f8
+{systemdict exch .forceundef} forall
8812f8
+
8812f8
+%% This list is of operators which no longer appear to be used, and which we do not believe
8812f8
+%% to have any real use. For now we will undefine the operstors so they cannot easily be used
8812f8
+%% but can be easily restored (just delete the name from the list in the array). In future
8812f8
+%% we may remove the operator and the code implementation entirely.
8812f8
+[
8812f8
+/.bitadd /.charboxpath /.currentblackptcomp /.setblackptcomp /.cond /.countexecstack /.execstack /.runandhide /.popdevicefilter
8812f8
+/.execfile /.filenamesplit /.file_name_parent
8812f8
+/.setdefaultmatrix /.isprocfilter /.unread /.psstringencode
8812f8
+/.buildsampledfunction /.isencapfunction /.currentaccuratecurves /.currentcurvejoin /.currentdashadapt /.currentdotlength
8812f8
+/.currentlimitclamp /.dotorientation /.setaccuratecurves /.setcurvejoin /.setdashadapt /.setdotorientation
8812f8
+/.setlimitclamp /.currentscreenlevels /.dashpath /.pathbbox /.identeq /.identne /.tokenexec /.forgetsave /.pantonecallback
8812f8
+
8812f8
+%% Used by our own test suite files
8812f8
+%%/.setdotlength % Bug687720.ps
8812f8
+]
8812f8
+{systemdict exch .forceundef} forall
8812f8
+
8812f8
+%% This list of operators are used internally by various parts of the Ghostscript startup code.
8812f8
+%% Since each operator is a potential security vulnerability, and any operator listed here
8812f8
+%% is not required once the initislisation is complete and functions are bound, we undefine
8812f8
+%% the ones that aren't needed at runtime.
8812f8
+[
8812f8
+/.callinstall /.callbeginpage /.callendpage
8812f8
+/.currentstackprotect /.setstackprotect /.errorexec /.finderrorobject /.installsystemnames /.bosobject /.fontbbox
8812f8
+/.type1execchar /.type2execchar /.type42execchar /.setweightvector /.getuseciecolor /processcolors /.includecolorspace
8812f8
+/.execn /.instopped /.stop /.stopped /.setcolorrendering /.setdevicecolorrendering /.buildcolorrendering1 /.builddevicecolorrendering1
8812f8
+/.TransformPQR_scale_WB0 /.TransformPQR_scale_WB1 /.TransformPQR_scale_WB2 /.currentoverprintmode /.copydevice2
8812f8
+/.devicename /.doneshowpage /flushpage /.getbitsrect /.getdevice /.getdefaultdevice /.getdeviceparams /.gethardwareparams
8812f8
+/makewordimagedevice /.outputpage /.putdeviceparams /.setdevice /.currentshowpagecount
8812f8
+/.setpagedevice /.currentpagedevice /.knownundef /.setmaxlength /.rectappend /.initialize_dsc_parser /.parse_dsc_comments
8812f8
+/.fillCIDMap /.fillIdentityCIDMap /.buildcmap /.filenamelistseparator /.libfile /.getfilename
8812f8
+/.file_name_combine /.file_name_is_absolute /.file_name_separator /.file_name_directory_separator /.file_name_current /.filename
8812f8
+/.peekstring /.writecvp /.subfiledecode /.setupUnicodeDecoder /.jbig2makeglobalctx /.registerfont /.parsecff
8812f8
+/.getshowoperator /.getnativefonts /.beginform /.endform /.get_form_id /.repeatform /.reusablestream /.rsdparams
8812f8
+/.buildfunction /.currentfilladjust2 /.setfilladjust2 /.sethpglpathmode /.currenthpglpathmode
8812f8
+/.currenthalftone /.sethalftone5 /.image1 /.imagemask1 /.image3 /.image4
8812f8
+/.getiodevice /.getdevparms /.putdevparams /.bbox_transform /.matchmedia /.matchpagesize /.defaultpapersize
8812f8
+/.oserrno /.setoserrno /.oserrorstring /.getCPSImode
8812f8
+/.getscanconverter /.setscanconverter /.type1encrypt /.type1decrypt/.languagelevel /.setlanguagelevel /.eqproc /.fillpage /.buildpattern1 /.saslprep
8812f8
+/.buildshading1 /.buildshadin2 /.buildshading3 /.buildshading4 /.buildshading5 /.buildshading6 /.buildshading7 /.buildshadingpattern
8812f8
+/.argindex /.bytestring /.namestring /.stringbreak /.stringmatch /.globalvmarray /.globalvmdict /.globalvmpackedarray /.globalvmstring
8812f8
+/.localvmarray /.localvmdict /.localvmpackedarray /.localvmstring /.systemvmarray /.systemvmdict /.systemvmpackedarray /.systemvmstring /.systemvmfile /.systemvmlibfile
8812f8
+/.systemvmSFD /.settrapparams /.currentsystemparams /.currentuserparams /.getsystemparam /.getuserparam /.setsystemparams /.setuserparams
8812f8
+/.checkpassword /.locale_to_utf8 /.currentglobal /.gcheck /.imagepath
8812f8
+
8812f8
+% Used by our own test suite files
8812f8
+%/.fileposition %image-qa.ps
8812f8
+%/.makeoperator /.setCPSImode % gs_cet.ps
8812f8
+
8812f8
+% Either our code uses these in ways which mean they can't be undefined, or they are used directly by
8812f8
+% test files/utilities, or engineers expressed a desire to keep them visible.
8812f8
+%
8812f8
+%/currentdevice /.sort /.buildfont0 /.buildfont1 /.buildfont2 /.buildfont3 /.buildfont4 /.buildfont9 /.buildfont10 /.buildfont11
8812f8
+%/.buildfotn32 /.buildfont42 /.type9mapcid /.type11mapcid /.swapcolors
8812f8
+%/currentdevice  /.quit /.setuseciecolor /.needinput /.setoverprintmode /.special_op /.dicttomark /.knownget
8812f8
+%/.FAPIavailable /.FAPIpassfont /.FAPIrebuildfont /.FAPIBuildGlyph /.FAPIBuildChar /.FAPIBuildGlyph9
8812f8
+%/.tempfile /.numicc_components /.set_outputintent  /.max /.min /.shfill /.vmreclaim /.getpath /.setglobal
8812f8
+%/.setdebug /.mementolistnewblocks /getenv
8812f8
+]
8812f8
+{systemdict exch .forceundef} forall
8812f8
+
8812f8
+//systemdict /UndefinePostScriptOperators .forceundef
8812f8
+} bind def
8812f8
+
8812f8
+/UndefinePDFOperators {
8812f8
+%% This list of operators are used internally by various parts of the Ghostscript PDF interpreter.
8812f8
+%% Since each operator is a potential security vulnerability, and any operator listed here
8812f8
+%% is not required once the initislisation is complete and functions are bound, we undefine
8812f8
+%% the ones that aren't needed at runtime.
8812f8
+[
8812f8
+/.pdfawidthshow /.pdfwidthshow
8812f8
+/.setfillcolor /.setfillcolorspace /.setstrokecolor /.setstrokecolorspace /.currentrenderingintent /.setrenderingintent
8812f8
+/.currenttextrenderingmode /.settextspacing /.currenttextspacing /.settextleading /.currenttextleading
8812f8
+/.settextrise /.currenttextrise /.setwordspacing /.currentwordspacing /.settexthscaling /.currenttexthscaling
8812f8
+/.settextlinematrix /.currenttextlinematrix /.currenttextmatrix /.settextmatrix /.currentblendmode
8812f8
+/.currentopacityalpha /.currentshapealpha /.currenttextknockout
8812f8
+/.pushextendedgstate /.popextendedgstate /.begintransparencytextgroup
8812f8
+/.endtransparencytextgroup /.begintransparencymaskgroup /.begintransparencymaskimage /.endtransparencymask /.image3x
8812f8
+/.abortpdf14devicefilter /.pdfinkpath /.pdfFormName /.setstrokeconstantalpha
8812f8
+/.setfillconstantalpha /.setalphaisshape /.currentalphaisshape
8812f8
+/.settextspacing /.currenttextspacing /.settextleading /.currenttextleading /.settextrise /.currenttextrise
8812f8
+/.setwordspacing /.currentwordspacing /.settexthscaling /.currenttexthscaling
8812f8
+
8812f8
+% Used by our own test suite files
8812f8
+%/.pushpdf14devicefilter    % transparency-example.ps
8812f8
+%/.poppdf14devicefilter     % transparency-example.ps
8812f8
+%/.setopacityalpha          % transparency-example.ps
8812f8
+%/.setshapealpha            % transparency-example.ps
8812f8
+%/.endtransparencygroup     % transparency-example.ps
8812f8
+
8812f8
+% undefining these causes errors/incorrect output
8812f8
+%/.settextrenderingmode /.setblendmode /.begintransparencygroup /.settextknockout /check_r6_password /.setstrokeoverprint /.setfilloverprint
8812f8
+%/.currentstrokeoverprint /.currentfilloverprint /.currentfillconstantalpha /.currentstrokeconstantalpha
8812f8
+]
8812f8
+{systemdict exch .forceundef} forall
8812f8
+//systemdict /UndefinePDFOperators .forceundef
8812f8
+} bind def
8812f8
+
8812f8
 % If we delayed binding, make it possible to do it later.
8812f8
 /.bindnow {
8812f8
   currentuserparams /IdiomRecognition .knownget {
8812f8
@@ -2081,6 +2193,8 @@ SAFER { .setsafe } if
8812f8
   //systemdict /.delaybind {} .forceput	% reclaim the space
8812f8
   //systemdict /.bindnow .forceundef	% ditto
8812f8
   put
8812f8
+%  //systemdict /UndefinePostScriptOperators get exec
8812f8
+%  //systemdict /UndefinePDFOperators get exec
8812f8
   //systemdict /.forcecopynew .forceundef	% remove temptation
8812f8
   //systemdict /.forcedef .forceundef		% ditto
8812f8
   //systemdict /.forceput .forceundef		% ditto
8812f8
@@ -2180,6 +2294,13 @@ currentdict /.patterntypes .undef
8812f8
 currentdict /.shadingtypes .undef
8812f8
 currentdict /.wheredict .undef
8812f8
 currentdict /.renderingintentdict .undef
8812f8
+
8812f8
+%% If we are using DELAYBIND we have to defer the undefinition
8812f8
+%% until .bindnow.
8812f8
+DELAYBIND not {
8812f8
+  //systemdict /UndefinePostScriptOperators get exec
8812f8
+  //systemdict /UndefinePDFOperators .forceundef
8812f8
+} if
8812f8
 end
8812f8
 
8812f8
 % Clean up VM, and enable GC. Use .vmreclaim to force the GC.
8812f8
@@ -2197,6 +2318,10 @@ currentdict /superexec .knownget {
8812f8
   1183615869 internaldict /superexec 3 -1 roll put
8812f8
   currentdict /superexec .undef
8812f8
 } if
8812f8
+
8812f8
+%% Can't remove this one until the last minute :-)
8812f8
+systemdict /.undef .undef
8812f8
+
8812f8
 WRITESYSTEMDICT not { systemdict readonly pop } if
8812f8
 (END GC) VMDEBUG
8812f8
 
8812f8
diff -up a/Resource/Init/pdf_main.ps.cve-2018-16585 b/Resource/Init/pdf_main.ps
8812f8
--- a/Resource/Init/pdf_main.ps.cve-2018-16585	2018-11-14 07:50:45.158495856 +0100
8812f8
+++ b/Resource/Init/pdf_main.ps	2018-11-14 07:51:16.245006245 +0100
8812f8
@@ -2347,3 +2347,32 @@ currentdict /PDF2PS_matrix_key undef
8812f8
 
8812f8
 end			% pdfdict
8812f8
 .setglobal
8812f8
+
8812f8
+DELAYBIND not {
8812f8
+%% This list of operators are used internally by various parts of the Ghostscript PDF interpreter.
8812f8
+%% Since each operator is a potential security vulnerability, and any operator listed here
8812f8
+%% is not required once the initislisation is complete and functions are bound, we undefine
8812f8
+%% the ones that aren't needed at runtime.
8812f8
+[
8812f8
+/.pdfawidthshow /.pdfwidthshow
8812f8
+/.setfillcolor /.setfillcolorspace /.setstrokecolor /.setstrokecolorspace /.currentrenderingintent /.setrenderingintent
8812f8
+/.currentstrokeoverprint /.setstrokeoverprint /.currentfilloverprint /.setfilloverprint
8812f8
+/.currenttextrenderingmode /.settextspacing /.currenttextspacing /.settextleading /.currenttextleading
8812f8
+/.settextrise /.currenttextrise /.setwordspacing /.currentwordspacing /.settexthscaling /.currenttexthscaling
8812f8
+/.setTextLineMatrix /.currentTextLineMatrix /.currentTextMatrix /.setTextMatrix /.currentblendmode
8812f8
+/.currentopacityalpha /.currentshapealpha /.currenttextknockout
8812f8
+/.pushextendedgstate /.popextendedgstate /.begintransparencytextgroup
8812f8
+/.endtransparencytextgroup /.begintransparencymaskgroup /.begintransparencymaskimage /.endtransparencymask /.image3x
8812f8
+/.abortpdf14devicefilter /.pdfinkpath /.pdfFormName
8812f8
+
8812f8
+% Used by our own test suite files
8812f8
+%/.pushpdf14devicefilter    % transparency-example.ps
8812f8
+%/.poppdf14devicefilter     % transparency-example.ps
8812f8
+%/.setopacityalpha          % transparency-example.ps
8812f8
+%/.setshapealpha            % transparency-example.ps
8812f8
+%/.endtransparencygroup     % transparency-example.ps
8812f8
+
8812f8
+%/.settextrenderingmode /.setblendmode /.begintransparencygroup /.settextknockout /check_r6_password
8812f8
+]
8812f8
+{systemdict exch .undef} forall
8812f8
+} if