Skip to content

Commit b8bd2d6

Browse files
[AUTO-CHERRYPICK] Patch tensorflow for CVE-2024-35195 - branch 3.0-dev (#11962)
Co-authored-by: Kanishk Bansal <[email protected]>
1 parent c9785c0 commit b8bd2d6

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

SPECS/tensorflow/CVE-2024-35195.patch

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
From 645c871ad0578ac7fc79ea84e64380984423af0c Mon Sep 17 00:00:00 2001
2+
From: Kanishk-Bansal <[email protected]>
3+
Date: Thu, 19 Dec 2024 06:10:36 +0000
4+
Subject: [PATCH] Fix CVE-2024-35195
5+
6+
---
7+
.../site-packages/requests/adapters.py | 58 ++++++++++++++++++-
8+
1 file changed, 57 insertions(+), 1 deletion(-)
9+
10+
diff --git a/pypi_requests/site-packages/requests/adapters.py b/pypi_requests/site-packages/requests/adapters.py
11+
index 78e3bb6..03cd069 100644
12+
--- a/pypi_requests/site-packages/requests/adapters.py
13+
+++ b/pypi_requests/site-packages/requests/adapters.py
14+
@@ -8,6 +8,7 @@ and maintain connections.
15+
16+
import os.path
17+
import socket # noqa: F401
18+
+import typing
19+
20+
from urllib3.exceptions import ClosedPoolError, ConnectTimeoutError
21+
from urllib3.exceptions import HTTPError as _HTTPError
22+
@@ -61,12 +62,38 @@ except ImportError:
23+
raise InvalidSchema("Missing dependencies for SOCKS support.")
24+
25+
26+
+if typing.TYPE_CHECKING:
27+
+ from .models import PreparedRequest
28+
+
29+
+
30+
DEFAULT_POOLBLOCK = False
31+
DEFAULT_POOLSIZE = 10
32+
DEFAULT_RETRIES = 0
33+
DEFAULT_POOL_TIMEOUT = None
34+
35+
36+
+def _urllib3_request_context(
37+
+ request: "PreparedRequest", verify: "bool | str | None"
38+
+) -> "(typing.Dict[str, typing.Any], typing.Dict[str, typing.Any])":
39+
+ host_params = {}
40+
+ pool_kwargs = {}
41+
+ parsed_request_url = urlparse(request.url)
42+
+ scheme = parsed_request_url.scheme.lower()
43+
+ port = parsed_request_url.port
44+
+ cert_reqs = "CERT_REQUIRED"
45+
+ if verify is False:
46+
+ cert_reqs = "CERT_NONE"
47+
+ if isinstance(verify, str):
48+
+ pool_kwargs["ca_certs"] = verify
49+
+ pool_kwargs["cert_reqs"] = cert_reqs
50+
+ host_params = {
51+
+ "scheme": scheme,
52+
+ "host": parsed_request_url.hostname,
53+
+ "port": port,
54+
+ }
55+
+ return host_params, pool_kwargs
56+
+
57+
+
58+
class BaseAdapter:
59+
"""The Base Transport Adapter"""
60+
61+
@@ -328,6 +355,35 @@ class HTTPAdapter(BaseAdapter):
62+
63+
return response
64+
65+
+ def _get_connection(self, request, verify, proxies=None):
66+
+ # Replace the existing get_connection without breaking things and
67+
+ # ensure that TLS settings are considered when we interact with
68+
+ # urllib3 HTTP Pools
69+
+ proxy = select_proxy(request.url, proxies)
70+
+ try:
71+
+ host_params, pool_kwargs = _urllib3_request_context(request, verify)
72+
+ except ValueError as e:
73+
+ raise InvalidURL(e, request=request)
74+
+ if proxy:
75+
+ proxy = prepend_scheme_if_needed(proxy, "http")
76+
+ proxy_url = parse_url(proxy)
77+
+ if not proxy_url.host:
78+
+ raise InvalidProxyURL(
79+
+ "Please check proxy URL. It is malformed "
80+
+ "and could be missing the host."
81+
+ )
82+
+ proxy_manager = self.proxy_manager_for(proxy)
83+
+ conn = proxy_manager.connection_from_host(
84+
+ **host_params, pool_kwargs=pool_kwargs
85+
+ )
86+
+ else:
87+
+ # Only scheme should be lower case
88+
+ conn = self.poolmanager.connection_from_host(
89+
+ **host_params, pool_kwargs=pool_kwargs
90+
+ )
91+
+
92+
+ return conn
93+
+
94+
def get_connection(self, url, proxies=None):
95+
"""Returns a urllib3 connection for the given URL. This should not be
96+
called from user code, and is only exposed for use when subclassing the
97+
@@ -451,7 +507,7 @@ class HTTPAdapter(BaseAdapter):
98+
"""
99+
100+
try:
101+
- conn = self.get_connection(request.url, proxies)
102+
+ conn = self._get_connection(request, verify, proxies)
103+
except LocationValueError as e:
104+
raise InvalidURL(e, request=request)
105+
106+
--
107+
2.45.2
108+

SPECS/tensorflow/tensorflow.spec

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Summary: TensorFlow is an open source machine learning framework for everyone.
22
Name: tensorflow
33
Version: 2.16.1
4-
Release: 7%{?dist}
4+
Release: 8%{?dist}
55
License: ASL 2.0
66
Vendor: Microsoft Corporation
77
Distribution: Azure Linux
@@ -13,6 +13,7 @@ Patch0: CVE-2024-7592.patch
1313
Patch1: CVE-2024-6232.patch
1414
Patch2: CVE-2024-8088.patch
1515
Patch3: CVE-2024-3651.patch
16+
Patch4: CVE-2024-35195.patch
1617
BuildRequires: bazel
1718
BuildRequires: binutils
1819
BuildRequires: build-essential
@@ -89,6 +90,11 @@ pushd /root/.cache/bazel/_bazel_$USER/$MD5_HASH/external/python_x86_64-unknown-l
8990
patch -p1 < %{PATCH3}
9091
popd
9192

93+
# Need to patch CVE-2024-35195 in the bundled python for applicable archs: `ExclusiveArch: x86_64`
94+
pushd /root/.cache/bazel/_bazel_$USER/$MD5_HASH/external/
95+
patch -p1 < %{PATCH4}
96+
popd
97+
9298
export TF_PYTHON_VERSION=3.12
9399
ln -s %{_bindir}/python3 %{_bindir}/python
94100

@@ -118,6 +124,9 @@ bazel --batch build //tensorflow/tools/pip_package:build_pip_package
118124
%{_bindir}/toco_from_protos
119125

120126
%changelog
127+
* Wed Jan 15 2025 Kanishk Bansal <[email protected]> - 2.16.1-8
128+
- Address CVE-2024-35195 with an upstream patch
129+
121130
* Wed Sep 25 2024 Archana Choudhary <[email protected]> - 2.16.1-7
122131
- Bump release to build with new python3 to fix CVE-2024-6232, CVE-2024-8088, CVE-2024-3651
123132

0 commit comments

Comments
 (0)