summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohini Sangam <rsangam@mvista.com>2024-09-04 17:25:10 +0530
committerSteve Sakoman <steve@sakoman.com>2024-09-07 05:38:17 -0700
commit630e7d60005040a2fda74c659f977d8554a9247f (patch)
treec58509ec9e1adde8ef31b3958ef10d2e1eb1ecb3
parentdd123d8eda6b4a5dbfd384eaae1477d363cf434b (diff)
downloadpoky-630e7d60005040a2fda74c659f977d8554a9247f.tar.gz
python3: Security fix for CVE-2024-8088
CVE fixed: - CVE-2024-8088: python: cpython: denial of service in zipfile Upstream-Status: Backport from https://github.com/python/cpython/commit/e0264a61119d551658d9445af38323ba94fc16db (From OE-Core rev: 295addec33c83443423a3ef87905c3a70f44a4e7) Signed-off-by: Rohini Sangam <rsangam@mvista.com> Signed-off-by: Siddharth Doshi <sdoshi@mvista.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-devtools/python/python3/CVE-2024-8088.patch124
-rw-r--r--meta/recipes-devtools/python/python3_3.10.14.bb1
2 files changed, 125 insertions, 0 deletions
diff --git a/meta/recipes-devtools/python/python3/CVE-2024-8088.patch b/meta/recipes-devtools/python/python3/CVE-2024-8088.patch
new file mode 100644
index 0000000000..10d28a9e65
--- /dev/null
+++ b/meta/recipes-devtools/python/python3/CVE-2024-8088.patch
@@ -0,0 +1,124 @@
1From e0264a61119d551658d9445af38323ba94fc16db Mon Sep 17 00:00:00 2001
2From: "Jason R. Coombs" <jaraco@jaraco.com>
3Date: Thu, 22 Aug 2024 19:24:33 -0400
4Subject: [PATCH] CVE-2024-8088: Sanitize names in zipfile.Path. (GH-122906)
5
6Upstream-Status: Backport from https://github.com/python/cpython/commit/e0264a61119d551658d9445af38323ba94fc16db
7CVE: CVE-2024-8088
8
9Signed-off-by: Rohini Sangam <rsangam@mvista.com>
10---
11 Lib/test/test_zipfile.py | 17 ++++++
12 Lib/zipfile.py | 61 ++++++++++++++++++-
13 2 files changed, 77 insertions(+), 1 deletion(-)
14
15diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
16index 32c0170..a60dc11 100644
17--- a/Lib/test/test_zipfile.py
18+++ b/Lib/test/test_zipfile.py
19@@ -3280,6 +3280,23 @@ with zipfile.ZipFile(io.BytesIO(), "w") as zf:
20 zipfile.Path(zf)
21 zf.extractall(source_path.parent)
22
23+ def test_malformed_paths(self):
24+ """
25+ Path should handle malformed paths.
26+ """
27+ data = io.BytesIO()
28+ zf = zipfile.ZipFile(data, "w")
29+ zf.writestr("/one-slash.txt", b"content")
30+ zf.writestr("//two-slash.txt", b"content")
31+ zf.writestr("../parent.txt", b"content")
32+ zf.filename = ''
33+ root = zipfile.Path(zf)
34+ assert list(map(str, root.iterdir())) == [
35+ 'one-slash.txt',
36+ 'two-slash.txt',
37+ 'parent.txt',
38+ ]
39+
40
41 class StripExtraTests(unittest.TestCase):
42 # Note: all of the "z" characters are technically invalid, but up
43diff --git a/Lib/zipfile.py b/Lib/zipfile.py
44index 7d18bc2..cbac8d9 100644
45--- a/Lib/zipfile.py
46+++ b/Lib/zipfile.py
47@@ -9,6 +9,7 @@ import io
48 import itertools
49 import os
50 import posixpath
51+import re
52 import shutil
53 import stat
54 import struct
55@@ -2182,7 +2183,65 @@ def _difference(minuend, subtrahend):
56 return itertools.filterfalse(set(subtrahend).__contains__, minuend)
57
58
59-class CompleteDirs(ZipFile):
60+class SanitizedNames:
61+ """
62+ ZipFile mix-in to ensure names are sanitized.
63+ """
64+
65+ def namelist(self):
66+ return list(map(self._sanitize, super().namelist()))
67+
68+ @staticmethod
69+ def _sanitize(name):
70+ r"""
71+ Ensure a relative path with posix separators and no dot names.
72+ Modeled after
73+ https://github.com/python/cpython/blob/bcc1be39cb1d04ad9fc0bd1b9193d3972835a57c/Lib/zipfile/__init__.py#L1799-L1813
74+ but provides consistent cross-platform behavior.
75+ >>> san = SanitizedNames._sanitize
76+ >>> san('/foo/bar')
77+ 'foo/bar'
78+ >>> san('//foo.txt')
79+ 'foo.txt'
80+ >>> san('foo/.././bar.txt')
81+ 'foo/bar.txt'
82+ >>> san('foo../.bar.txt')
83+ 'foo../.bar.txt'
84+ >>> san('\\foo\\bar.txt')
85+ 'foo/bar.txt'
86+ >>> san('D:\\foo.txt')
87+ 'D/foo.txt'
88+ >>> san('\\\\server\\share\\file.txt')
89+ 'server/share/file.txt'
90+ >>> san('\\\\?\\GLOBALROOT\\Volume3')
91+ '?/GLOBALROOT/Volume3'
92+ >>> san('\\\\.\\PhysicalDrive1\\root')
93+ 'PhysicalDrive1/root'
94+ Retain any trailing slash.
95+ >>> san('abc/')
96+ 'abc/'
97+ Raises a ValueError if the result is empty.
98+ >>> san('../..')
99+ Traceback (most recent call last):
100+ ...
101+ ValueError: Empty filename
102+ """
103+
104+ def allowed(part):
105+ return part and part not in {'..', '.'}
106+
107+ # Remove the drive letter.
108+ # Don't use ntpath.splitdrive, because that also strips UNC paths
109+ bare = re.sub('^([A-Z]):', r'\1', name, flags=re.IGNORECASE)
110+ clean = bare.replace('\\', '/')
111+ parts = clean.split('/')
112+ joined = '/'.join(filter(allowed, parts))
113+ if not joined:
114+ raise ValueError("Empty filename")
115+ return joined + '/' * name.endswith('/')
116+
117+
118+class CompleteDirs(SanitizedNames, ZipFile):
119 """
120 A ZipFile subclass that ensures that implied directories
121 are always included in the namelist.
122--
1232.35.7
124
diff --git a/meta/recipes-devtools/python/python3_3.10.14.bb b/meta/recipes-devtools/python/python3_3.10.14.bb
index b5bc80ab88..14ab3f6155 100644
--- a/meta/recipes-devtools/python/python3_3.10.14.bb
+++ b/meta/recipes-devtools/python/python3_3.10.14.bb
@@ -36,6 +36,7 @@ SRC_URI = "http://www.python.org/ftp/python/${PV}/Python-${PV}.tar.xz \
36 file://deterministic_imports.patch \ 36 file://deterministic_imports.patch \
37 file://0001-Avoid-shebang-overflow-on-python-config.py.patch \ 37 file://0001-Avoid-shebang-overflow-on-python-config.py.patch \
38 file://0001-test_storlines-skip-due-to-load-variability.patch \ 38 file://0001-test_storlines-skip-due-to-load-variability.patch \
39 file://CVE-2024-8088.patch \
39 " 40 "
40 41
41SRC_URI:append:class-native = " \ 42SRC_URI:append:class-native = " \