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

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