Bug 1348470

Summary: Arbitrary code execution due to insecure loading of Python module(s) from CWD
Product: [Fedora] Fedora Reporter: Dhiru Kholia <dkholia>
Component: python2Assignee: Charalampos Stratakis <cstratak>
Status: CLOSED WONTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: 29CC: bkabrda, cstratak, dmalcolm, ivazqueznet, jonathansteffan, mhroncok, pviktori, rkuska, tomspur, torsava, vstinner
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-11-26 13:04:22 UTC Type: Bug
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:    
Bug Blocks: 1348410    

Description Dhiru Kholia 2016-06-21 09:09:06 UTC
The /usr/bin/pynche script from the python-tools package tries to load the "distutils" Python module from the current working directory (CWD).

Steps to Reproduce:

$ cat > distutils.py
print("boom!")

$ pynche  # run /usr/bin/pynche
...boom!...

Additional info:

This bug is very similar to https://bugzilla.redhat.com/show_bug.cgi?id=995060

Comment 1 Fedora End Of Life 2017-07-25 21:09:08 UTC
This message is a reminder that Fedora 24 is nearing its end of life.
Approximately 2 (two) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 24. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '24'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 24 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 2 Miro Hrončok 2017-07-26 09:42:41 UTC
Also reproduced on Fedora 26.

Comment 3 Miro Hrončok 2017-07-26 10:23:25 UTC
Changing the script to the following fixes the issue:

#!/bin/bash
exec `python -s -c "import sys; del sys.path[0]; from distutils.sysconfig import get_python_lib; print(get_python_lib(plat_specific = True))"`/pynche/pynche

Also note that is still works even if sys.py (with print('boom!')) is in CWD.

Comment 4 Petr Viktorin (pviktori) 2017-07-26 11:51:28 UTC
FWIW, that mess is added in Fedora, to work around multilib trouble (see bug #831437)

I propose to chane it to the following instead:

#!/usr/bin/python
from pynche import Main
Main.main()


(This is technically private API, but I don't see it changing in Python2's lifetime.)

Comment 5 Petr Viktorin (pviktori) 2017-07-26 11:53:21 UTC
er, #!/usr/bin/python2 of course

Comment 6 Fedora End Of Life 2017-11-16 18:31:04 UTC
This message is a reminder that Fedora 25 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 25. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '25'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 25 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 7 Fedora End Of Life 2018-05-03 08:39:57 UTC
This message is a reminder that Fedora 26 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 26. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '26'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 26 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 8 Miro Hrončok 2018-06-21 14:32:25 UTC
This is a low priority for us and we'll probably never get to it, unless somebody says it's a higher priority for them.

Comment 9 Jan Kurik 2018-08-14 11:00:52 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 29 development cycle.
Changing version to '29'.

Comment 10 Victor Stinner 2018-11-12 13:15:03 UTC
Sadly, the described behavior is a deliberate choice to make Python "practical" to use.

This issue has been fixed in Python 3.4 by adding a new -I (isolated mode) which prevents to add the path of script or the current directory to sys.path. Example:

$ python3  -c 'import pprint, sys; pprint.pprint(sys.path)'
['',
 '/usr/lib64/python36.zip',
 '/usr/lib64/python3.6',
 '/usr/lib64/python3.6/lib-dynload',
 ...]

$ python3 -I -c 'import pprint, sys; pprint.pprint(sys.path)'
['/usr/lib64/python36.zip',
 '/usr/lib64/python3.6',
 '/usr/lib64/python3.6/lib-dynload',
 ...]

The default behavior has not been changed, it's an opt-in option.