Skip to content

Commit 976368d

Browse files
[AUTO-CHERRYPICK] Patch pytorch for CVE-2025-32434, CVE-2025-3730 [Critical] - branch 3.0-dev (#13563)
Co-authored-by: Kanishk Bansal <103916909+Kanishk-Bansal@users.noreply.github.com>
1 parent 564a214 commit 976368d

3 files changed

Lines changed: 121 additions & 1 deletion

File tree

SPECS/pytorch/CVE-2025-32434.patch

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
From d62cafe6ad9af635318d51d61f870ee038275cfe Mon Sep 17 00:00:00 2001
2+
From: Kanishk-Bansal <kbkanishk975@gmail.com>
3+
Date: Wed, 23 Apr 2025 06:09:50 +0000
4+
Subject: [PATCH] Address CVE-2025-32434
5+
6+
Upstream Patch Reference : https://github.com/pytorch/pytorch/commit/8d4b8a920a2172523deb95bf20e8e52d50649c04
7+
8+
Signed-off-by: Kanishk-Bansal <kbkanishk975@gmail.com>
9+
---
10+
test/test_serialization.py | 6 +++++-
11+
torch/serialization.py | 17 ++++++++++++-----
12+
2 files changed, 17 insertions(+), 6 deletions(-)
13+
14+
diff --git a/test/test_serialization.py b/test/test_serialization.py
15+
index c7fdbe7..6126fb2 100644
16+
--- a/test/test_serialization.py
17+
+++ b/test/test_serialization.py
18+
@@ -426,7 +426,11 @@ class SerializationMixin:
19+
b += [a[0].storage()]
20+
b += [a[0].reshape(-1)[1:4].clone().storage()]
21+
path = download_file('https://download.pytorch.org/test_data/legacy_serialized.pt')
22+
- c = torch.load(path, weights_only=weights_only)
23+
+ if weights_only:
24+
+ with self.assertRaisesRegex(RuntimeError,
25+
+ "Cannot use ``weights_only=True`` with files saved in the legacy .tar format."):
26+
+ c = torch.load(path, weights_only=weights_only)
27+
+ c = torch.load(path, weights_only=False)
28+
self.assertEqual(b, c, atol=0, rtol=0)
29+
self.assertTrue(isinstance(c[0], torch.FloatTensor))
30+
self.assertTrue(isinstance(c[1], torch.FloatTensor))
31+
diff --git a/torch/serialization.py b/torch/serialization.py
32+
index 9d02efd..a67bff1 100644
33+
--- a/torch/serialization.py
34+
+++ b/torch/serialization.py
35+
@@ -35,6 +35,13 @@ FILE_LIKE: TypeAlias = Union[str, os.PathLike, BinaryIO, IO[bytes]]
36+
MAP_LOCATION: TypeAlias = Optional[Union[Callable[[torch.Tensor, str], torch.Tensor], torch.device, str, Dict[str, str]]]
37+
STORAGE: TypeAlias = Union[Storage, torch.storage.TypedStorage, torch.UntypedStorage]
38+
39+
+UNSAFE_MESSAGE = (
40+
+ "In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` "
41+
+ "from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, "
42+
+ "but it can result in arbitrary code execution. Do it only if you got the file from a "
43+
+ "trusted source."
44+
+)
45+
+
46+
__all__ = [
47+
'SourceChangeWarning',
48+
'mkdtemp',
49+
@@ -970,11 +977,6 @@ def load(
50+
>>> torch.load('module.pt', encoding='ascii', weights_only=False)
51+
"""
52+
torch._C._log_api_usage_once("torch.load")
53+
- UNSAFE_MESSAGE = (
54+
- "Weights only load failed. Re-running `torch.load` with `weights_only` set to `False`"
55+
- " will likely succeed, but it can result in arbitrary code execution."
56+
- "Do it only if you get the file from a trusted source. WeightsUnpickler error: "
57+
- )
58+
# Add ability to force safe only weight loads via environment variable
59+
if os.getenv("TORCH_FORCE_WEIGHTS_ONLY_LOAD", "0").lower() in ['1', 'y', 'yes', 'true']:
60+
weights_only = True
61+
@@ -1125,6 +1127,11 @@ def _legacy_load(f, map_location, pickle_module, **pickle_load_args):
62+
63+
with closing(tarfile.open(fileobj=f, mode='r:', format=tarfile.PAX_FORMAT)) as tar, \
64+
mkdtemp() as tmpdir:
65+
+ if pickle_module is _weights_only_unpickler:
66+
+ raise RuntimeError(
67+
+ "Cannot use ``weights_only=True`` with files saved in the "
68+
+ "legacy .tar format. " + UNSAFE_MESSAGE
69+
+ )
70+
71+
tar.extract('storages', path=tmpdir)
72+
with open(os.path.join(tmpdir, 'storages'), 'rb', 0) as f:
73+
--
74+
2.45.2
75+

SPECS/pytorch/CVE-2025-3730.patch

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From 76a501810c4444cea0f5959d8650539b450ecbe6 Mon Sep 17 00:00:00 2001
2+
From: Kanishk-Bansal <kbkanishk975@gmail.com>
3+
Date: Wed, 23 Apr 2025 06:12:30 +0000
4+
Subject: [PATCH] Address CVE-2025-3730
5+
6+
Upstream Patch Reference : https://github.com/timocafe/pytorch/commit/46fc5d8e360127361211cb237d5f9eef0223e567
7+
8+
Signed-off-by: Kanishk-Bansal <kbkanishk975@gmail.com>
9+
---
10+
aten/src/ATen/native/LossCTC.cpp | 1 +
11+
aten/src/ATen/native/cuda/LossCTC.cu | 1 +
12+
2 files changed, 2 insertions(+)
13+
14+
diff --git a/aten/src/ATen/native/LossCTC.cpp b/aten/src/ATen/native/LossCTC.cpp
15+
index 595eaf9..47c2c40 100644
16+
--- a/aten/src/ATen/native/LossCTC.cpp
17+
+++ b/aten/src/ATen/native/LossCTC.cpp
18+
@@ -119,6 +119,7 @@ std::tuple<Tensor, Tensor, size_t, std::vector<int64_t>> ctc_loss_allocate_outpu
19+
// the alphas from the user by only returning the loss.
20+
template<typename scalar_t, ScalarType target_scalar_type>
21+
std::tuple<Tensor, Tensor> ctc_loss_cpu_template(const Tensor& log_probs, const Tensor& targets, IntArrayRef input_lengths, IntArrayRef target_lengths, int64_t BLANK) {
22+
+ TORCH_CHECK(log_probs.numel() > 0, "log_probs tensor must not be empty");
23+
// log_probs: input_len x batch_size x num_labels
24+
// targets [int64]: batch_size x target_length OR sum(target_lengths)
25+
constexpr scalar_t neginf = -std::numeric_limits<scalar_t>::infinity();
26+
diff --git a/aten/src/ATen/native/cuda/LossCTC.cu b/aten/src/ATen/native/cuda/LossCTC.cu
27+
index 5fb86d1..4bb90fc 100644
28+
--- a/aten/src/ATen/native/cuda/LossCTC.cu
29+
+++ b/aten/src/ATen/native/cuda/LossCTC.cu
30+
@@ -211,6 +211,7 @@ ctc_loss_log_alpha_gpu_kernel(scalar_t* __restrict__ log_alpha_data,
31+
// backward. The dispatch function will only return the loss.
32+
template<typename scalar_t, ScalarType target_scalar_type>
33+
std::tuple<Tensor, Tensor> ctc_loss_gpu_template(const Tensor& log_probs, const Tensor& targets, IntArrayRef input_lengths, IntArrayRef target_lengths, int64_t BLANK) {
34+
+ TORCH_CHECK(log_probs.numel() > 0, "log_probs tensor must not be empty");
35+
// log_probs: input_len x batch_size x num_labels
36+
// targets [int64]: batch_size x target_length OR sum(target_lengths)
37+
CheckedFrom c = "ctc_loss_gpu";
38+
--
39+
2.45.2
40+

SPECS/pytorch/pytorch.spec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration.
33
Name: pytorch
44
Version: 2.2.2
5-
Release: 5%{?dist}
5+
Release: 6%{?dist}
66
License: BSD-3-Clause
77
Vendor: Microsoft Corporation
88
Distribution: Azure Linux
@@ -29,6 +29,8 @@ Patch4: CVE-2024-27319.patch
2929
Patch5: CVE-2021-22918.patch
3030
Patch6: CVE-2024-7776.patch
3131
Patch7: CVE-2021-22569.patch
32+
Patch8: CVE-2025-32434.patch
33+
Patch9: CVE-2025-3730.patch
3234

3335
%description
3436
PyTorch is a Python package that provides two high-level features:
@@ -90,6 +92,9 @@ cp -arf docs %{buildroot}/%{_pkgdocdir}
9092
%{_docdir}/*
9193

9294
%changelog
95+
* Wed Apr 23 2025 Kanishk Bansal <kanbansal@microsoft.com> - 2.2.2-6
96+
- Patch CVE-2025-32434, CVE-2025-3730
97+
9398
* Mon Mar 31 2025 Kanishk Bansal <kanbansal@microsoft.com> - 2.2.2-5
9499
- Patch CVE-2021-22569, CVE-2024-7776
95100

0 commit comments

Comments
 (0)