Blame SOURCES/00391-cve-2022-42919.patch

02752f
From 85178d5849a4d9b5b46e7b91b1ebad7425139b44 Mon Sep 17 00:00:00 2001
02752f
From: "Gregory P. Smith" <greg@krypto.org>
02752f
Date: Thu, 20 Oct 2022 15:30:09 -0700
02752f
Subject: [PATCH] gh-97514: Don't use Linux abstract sockets for
02752f
 multiprocessing (GH-98501)
02752f
02752f
Linux abstract sockets are insecure as they lack any form of filesystem
02752f
permissions so their use allows anyone on the system to inject code into
02752f
the process.
02752f
02752f
This removes the default preference for abstract sockets in
02752f
multiprocessing introduced in Python 3.9+ via
02752f
https://github.com/python/cpython/pull/18866 while fixing
02752f
https://github.com/python/cpython/issues/84031.
02752f
02752f
Explicit use of an abstract socket by a user now generates a
02752f
RuntimeWarning.  If we choose to keep this warning, it should be
02752f
backported to the 3.7 and 3.8 branches.
02752f
(cherry picked from commit 49f61068f49747164988ffc5a442d2a63874fc17)
02752f
02752f
Co-authored-by: Gregory P. Smith <greg@krypto.org>
02752f
---
02752f
 Lib/multiprocessing/connection.py                 |  5 -----
02752f
 .../2022-09-07-10-42-00.gh-issue-97514.Yggdsl.rst | 15 +++++++++++++++
02752f
 2 files changed, 15 insertions(+), 5 deletions(-)
02752f
 create mode 100644 Misc/NEWS.d/next/Security/2022-09-07-10-42-00.gh-issue-97514.Yggdsl.rst
02752f
02752f
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
02752f
index 510e4b5aba44..8e2facf92a94 100644
02752f
--- a/Lib/multiprocessing/connection.py
02752f
+++ b/Lib/multiprocessing/connection.py
02752f
@@ -73,11 +73,6 @@ def arbitrary_address(family):
02752f
     if family == 'AF_INET':
02752f
         return ('localhost', 0)
02752f
     elif family == 'AF_UNIX':
02752f
-        # Prefer abstract sockets if possible to avoid problems with the address
02752f
-        # size.  When coding portable applications, some implementations have
02752f
-        # sun_path as short as 92 bytes in the sockaddr_un struct.
02752f
-        if util.abstract_sockets_supported:
02752f
-            return f"\0listener-{os.getpid()}-{next(_mmap_counter)}"
02752f
         return tempfile.mktemp(prefix='listener-', dir=util.get_temp_dir())
02752f
     elif family == 'AF_PIPE':
02752f
         return tempfile.mktemp(prefix=r'\\.\pipe\pyc-%d-%d-' %
02752f
diff --git a/Misc/NEWS.d/next/Security/2022-09-07-10-42-00.gh-issue-97514.Yggdsl.rst b/Misc/NEWS.d/next/Security/2022-09-07-10-42-00.gh-issue-97514.Yggdsl.rst
02752f
new file mode 100644
02752f
index 000000000000..02d95b570520
02752f
--- /dev/null
02752f
+++ b/Misc/NEWS.d/next/Security/2022-09-07-10-42-00.gh-issue-97514.Yggdsl.rst
02752f
@@ -0,0 +1,15 @@
02752f
+On Linux the :mod:`multiprocessing` module returns to using filesystem backed
02752f
+unix domain sockets for communication with the *forkserver* process instead of
02752f
+the Linux abstract socket namespace.  Only code that chooses to use the
02752f
+:ref:`"forkserver" start method <multiprocessing-start-methods>` is affected.
02752f
+
02752f
+Abstract sockets have no permissions and could allow any user on the system in
02752f
+the same `network namespace
02752f
+<https://man7.org/linux/man-pages/man7/network_namespaces.7.html>`_ (often the
02752f
+whole system) to inject code into the multiprocessing *forkserver* process.
02752f
+This was a potential privilege escalation. Filesystem based socket permissions
02752f
+restrict this to the *forkserver* process user as was the default in Python 3.8
02752f
+and earlier.
02752f
+
02752f
+This prevents Linux `CVE-2022-42919
02752f
+<https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-42919>`_.