Bug 1194205 (CVE-2015-1877)

Summary: CVE-2015-1877 xdg-utils: command injection vulnerability due to local variables collision in xdg-open
Product: [Other] Security Response Reporter: Vasyl Kaigorodov <vkaigoro>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: alexl, carnil, jrusnack, pertusus, rdieter
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-06-08 02:38:56 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: 1194209, 1194210, 1194211    
Bug Blocks: 1194208    

Description Vasyl Kaigorodov 2015-02-19 10:43:51 UTC
Command injection was reported [1] in xdg-utils running with dash.
Suggested patch:
https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=xdg-open.diff;att=1;bug=777722
Upstream bug report:
https://bugs.freedesktop.org/show_bug.cgi?id=89129

This issue only affects systems with "dash" shell set as default system shell.

[1]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=777722

Comment 2 Vasyl Kaigorodov 2015-02-19 10:47:38 UTC
Created xdg-utils tracking bugs for this issue:

Affects: fedora-all [bug 1194209]

Comment 3 Ján Rusnačko 2015-02-25 10:13:26 UTC
Analysis:

xdg-open is used to open a file or URL in users preferred application. During the process of finding the correct app to run, it recursively searches Desktop file in function search_desktop_file(). This function uses local variable $file to store the path to the searched Desktop file and runs function get_key() on the $file. get_key() searched for 

[Desktop Entry]
Exec=...

in the $file and content of Exec= is later executed.

The problem is that variable name $file is also used earlier in function open_generic() and stores path to the file being opened. Now assuming that system`s shell *does not* reset the content of $file when it is declared as local variable *again*, then the file being opened will be searched as Desktop file. If it contains expected [Desktop Entry] along with Exec=, it leads to arbitrary command execution.

The assumption about reset of local variable contents hold for dash, but not bash:
$ cat testme
testme() {
   x=backfromthedead
   local x
   echo $x
}
testme

$ dash testme 
backfromthedead

$ bash testme 

Also, this does not work if the local variable is initialized:

$ cat testme 
testme() {
   x=backfromthedead
   local x=""
   echo $x
}
testme

$ dash testme 

$ bash testme 

xdg-open as shipped in Fedora and RHEL-7 does initialize $file variable, and uses bash as default /bin/sh.

Comment 4 Ján Rusnačko 2015-02-25 10:15:33 UTC
Statement:

This issue did not affect the versions of xdg-utils as shipped with Red Hat Enterprise Linux 6 and 7.