Bug 2002271 (CVE-2021-3781)

Summary: CVE-2021-3781 ghostscript: sandbox escape using '%pipe%'
Product: [Other] Security Response Reporter: Cedric Buissart <cbuissar>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED NOTABUG QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: unspecifiedCC: akhaitovich, kyoneyam, mjg, mosvald, psampaio, rlescak, security-response-team, yozone, zdohnal
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: ghostpdl 9.55.0 Doc Type: If docs needed, set a value
Doc Text:
A trivial sandbox (enabled with the `-dSAFER` option) escape flaw was found in the ghostscript interpreter by injecting a specially crafted pipe command. This flaw allows a specially crafted document to execute arbitrary commands on the system in the context of the ghostscript interpreter. The highest threat from this vulnerability is to confidentiality, integrity, as well as system availability.
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-10-29 07:25:03 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2002625, 2003085    
Bug Blocks: 2002161, 2002605    

Description Cedric Buissart 2021-09-08 11:46:13 UTC
The file access protection built into Ghostscript proved insufficient for the "%pipe%" PostScript device, when combined with Ghostscript's requirement to be able to create and control temporary files in the conventional temporary file directories (for example, "/tmp" or "/temp). This exploit is restricted to Unix-like systems (i.e., it doesn't affect Windows). The most severe claimed results are only feasible if the exploit is run as a "high privilege" user (root/superuser level) -- a practice we would discourage under any circumstances. 

Resolution: The solution involves including the device specifier string ("%pipe%") in the permissions checking, meaning the entire file name string is validated, rather than (as before) only the sub-string following the device specifier. 

This flaw allows to trivially escape the sandbox (enabled with the `-dSAFER` option). A specially crafted document could use this flaw to execute command on the system, in the context of the ghostscript interpreter.

This flaw affects only version from 9.50 onward.

Upstream bug :
https://bugs.ghostscript.com/show_bug.cgi?id=704342

Comment 5 Cedric Buissart 2021-09-10 10:57:45 UTC
Created ghostscript tracking bugs for this issue:

Affects: fedora-all [bug 2003085]

Comment 6 Cedric Buissart 2021-09-10 14:28:34 UTC
*** Bug 2002800 has been marked as a duplicate of this bug. ***