Skip to content

Commit 21e42ec

Browse files
azurelinux-securityakhila-gurujuarchana25-ms
authored
[AutoPR- Security] Patch pytorch for CVE-2025-55560, CVE-2025-46152 [MEDIUM] (#14762)
Co-authored-by: akhila-guruju <v-guakhila@microsoft.com> Co-authored-by: Archana Shettigar <v-shettigara@microsoft.com>
1 parent 8d6b0ba commit 21e42ec

3 files changed

Lines changed: 174 additions & 1 deletion

File tree

SPECS/pytorch/CVE-2025-46152.patch

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
From f95e54328b15315c3563792fccae7193439d1312 Mon Sep 17 00:00:00 2001
2+
From: AllSpark <allspark@microsoft.com>
3+
Date: Mon, 29 Sep 2025 19:34:39 +0000
4+
Subject: [PATCH] inductor: guard bitwise shifts with max_shift and add tests
5+
for corner inputs; fixes ghissues 143555 and 143566
6+
7+
Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com>
8+
Upstream-reference: AI Backport of https://patch-diff.githubusercontent.com/raw/pytorch/pytorch/pull/143635.patch
9+
---
10+
test/inductor/test_cpu_repro.py | 17 ++++++++++++++++++
11+
torch/_inductor/codegen/cpp.py | 34 ++++++++++++++++++--
12+
2 files changed, 49 insertions(+), 2 deletions(-)
13+
14+
diff --git a/test/inductor/test_cpu_repro.py b/test/inductor/test_cpu_repro.py
15+
index 925c0f62..9ed4b79d 100644
16+
--- a/test/inductor/test_cpu_repro.py
17+
+++ b/test/inductor/test_cpu_repro.py
18+
@@ -2315,6 +2315,23 @@ class CPUReproTests(TestCase):
19+
self.common(fn2, (x,))
20+
assert metrics.generated_cpp_vec_kernel_count == 1
21+
22+
+ def test_bitwise_shift_corner_inputs(self):
23+
+ # Fix https://github.com/pytorch/pytorch/issues/143555
24+
+ # and https://github.com/pytorch/pytorch/issues/143566
25+
+ bitwise_fns = (
26+
+ torch.bitwise_left_shift,
27+
+ torch.bitwise_right_shift,
28+
+ )
29+
+ for bitwise_fn in bitwise_fns:
30+
+ torch._dynamo.reset()
31+
+ metrics.reset()
32+
+ x = torch.tensor(1000, dtype=torch.int64)
33+
+ bit_num = torch.tensor(64, dtype=torch.int64)
34+
+ res_aten_eager = bitwise_fn(x, bit_num)
35+
+ cfn = torch.compile(bitwise_fn)
36+
+ res = cfn(x, bit_num)
37+
+ self.assertEqual(res_aten_eager, res)
38+
+
39+
def test_transpose_vertical_sum_cpu_only(self):
40+
def fn(a, b):
41+
c = a * b
42+
diff --git a/torch/_inductor/codegen/cpp.py b/torch/_inductor/codegen/cpp.py
43+
index b94ede02..af5ed42a 100644
44+
--- a/torch/_inductor/codegen/cpp.py
45+
+++ b/torch/_inductor/codegen/cpp.py
46+
@@ -801,11 +801,41 @@ class CppOverrides(OpOverrides):
47+
48+
@staticmethod
49+
def bitwise_left_shift(a, b):
50+
- return f"decltype({a})({a} << {b})"
51+
+ code = BracesBuffer()
52+
+ code.writeline("[&]()")
53+
+ with code.indent():
54+
+ scalar_t = DTYPE_TO_CPP[a.dtype]
55+
+ code.writeline(
56+
+ f"constexpr decltype({b}) max_shift = sizeof({scalar_t}) * CHAR_BIT;"
57+
+ )
58+
+ code.writeline(
59+
+ f"if ((static_cast<std::make_signed_t<{scalar_t}>>({b}) < 0) || ({b} >= max_shift))"
60+
+ )
61+
+ with code.indent():
62+
+ code.writeline(f"return decltype({a})(0);")
63+
+ code.writeline(
64+
+ f"return decltype({a})(static_cast<std::make_unsigned_t<{scalar_t}>>({a}) << {b});"
65+
+ )
66+
+ code.writeline("()")
67+
+ return code
68+
69+
@staticmethod
70+
def bitwise_right_shift(a, b):
71+
- return f"decltype({a})({a} >> {b})"
72+
+ code = BracesBuffer()
73+
+ code.writeline("[&]()")
74+
+ with code.indent():
75+
+ scalar_t = DTYPE_TO_CPP[a.dtype]
76+
+ code.writeline(
77+
+ f"constexpr decltype({b}) max_shift = sizeof({scalar_t}) * CHAR_BIT - std::is_signed_v<{scalar_t}>;"
78+
+ )
79+
+ code.writeline(
80+
+ f"if ((static_cast<std::make_signed_t<{scalar_t}>>({b}) < 0) || ({b} >= max_shift))"
81+
+ )
82+
+ with code.indent():
83+
+ code.writeline(f"return decltype({a})({a} >> max_shift);")
84+
+ code.writeline(f"return decltype({a})({a} >> {b});")
85+
+ code.writeline("()")
86+
+ return code
87+
88+
@staticmethod
89+
def rand(seed: sympy.Expr, offset: sympy.Expr):
90+
--
91+
2.45.4
92+

SPECS/pytorch/CVE-2025-55560.patch

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
From 225742838bcbf4656a90010257062188f7fcae82 Mon Sep 17 00:00:00 2001
2+
From: Zhiyi Zhang <violin1781@gmail.com>
3+
Date: Sat, 26 Apr 2025 21:02:29 +0000
4+
Subject: [PATCH] Add an additional check to trigger graph break for sparse
5+
tensor (#151897)
6+
7+
Fixes #151522
8+
9+
This PR fixes the issue that Dynamo fails to trigger a graph break for sparse tensors in certain code paths. I added an additional check to handle this case, and it resolves the original problem.
10+
11+
Pull Request resolved: https://github.com/pytorch/pytorch/pull/151897
12+
Approved by: https://github.com/jansel
13+
14+
Modified to apply to Azure Linux
15+
Upstream Patch Reference: https://github.com/pytorch/pytorch/commit/225742838bcbf4656a90010257062188f7fcae82.patch
16+
---
17+
test/dynamo/test_compile.py | 13 +++++++++++++
18+
torch/_dynamo/variables/builtin.py | 11 +++++++++++
19+
2 files changed, 24 insertions(+)
20+
21+
diff --git a/test/dynamo/test_compile.py b/test/dynamo/test_compile.py
22+
index 5b2de2b7..a38c1d3e 100644
23+
--- a/test/dynamo/test_compile.py
24+
+++ b/test/dynamo/test_compile.py
25+
@@ -71,6 +71,19 @@ class InPlaceCompilationTests(unittest.TestCase):
26+
loaded_model = torch.jit.load(os.path.join(tmpdirname, "model.pt"))
27+
loaded_model(torch.randn(1, 10))
28+
29+
+ def test_to_sparse_to_dense_with_graph_break(self):
30+
+ def fn(x):
31+
+ x = x.to_sparse()
32+
+ x = x.to_dense()
33+
+ return x
34+
+
35+
+ x = torch.tensor([[1.0]])
36+
+ c_fn = torch.compile(fn)
37+
+
38+
+ output = fn(x)
39+
+ c_output = c_fn(x)
40+
+ self.assertEqual(output, c_output)
41+
+
42+
43+
# The private variants of the below functions are extensively tested
44+
# So as long as the signatures match we're good
45+
diff --git a/torch/_dynamo/variables/builtin.py b/torch/_dynamo/variables/builtin.py
46+
index 2a2e9893..beababef 100644
47+
--- a/torch/_dynamo/variables/builtin.py
48+
+++ b/torch/_dynamo/variables/builtin.py
49+
@@ -11,6 +11,7 @@ from typing import Dict, List
50+
51+
import torch
52+
from torch import sym_float, sym_int
53+
+from torch._subclasses.meta_utils import is_sparse_any
54+
55+
from .. import config, polyfill, variables
56+
from ..exc import (
57+
@@ -1226,6 +1227,16 @@ class BuiltinVariable(VariableTracker):
58+
variables.UserDefinedObjectVariable,
59+
),
60+
):
61+
+
62+
+ if isinstance(obj, TensorVariable):
63+
+ fake_val = obj.proxy.node.meta["example_value"]
64+
+ if (
65+
+ isinstance(fake_val, torch.Tensor)
66+
+ and is_sparse_any(fake_val)
67+
+ and (not tx.export or not config.capture_sparse_compute)
68+
+ ):
69+
+ unimplemented("torch.compile does not support sparse Tensors")
70+
+
71+
try:
72+
return obj.var_getattr(tx, name).clone(source=source)
73+
except NotImplementedError:
74+
--
75+
2.43.0
76+

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: 7%{?dist}
5+
Release: 8%{?dist}
66
License: BSD-3-Clause
77
Vendor: Microsoft Corporation
88
Distribution: Azure Linux
@@ -32,6 +32,8 @@ Patch7: CVE-2021-22569.patch
3232
Patch8: CVE-2025-32434.patch
3333
Patch9: CVE-2025-3730.patch
3434
Patch10: CVE-2025-2953.patch
35+
Patch11: CVE-2025-55560.patch
36+
Patch12: CVE-2025-46152.patch
3537

3638
%description
3739
PyTorch is a Python package that provides two high-level features:
@@ -93,6 +95,9 @@ cp -arf docs %{buildroot}/%{_pkgdocdir}
9395
%{_docdir}/*
9496

9597
%changelog
98+
* Wed Oct 01 2025 Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> - 2.2.2-8
99+
- Patch for CVE-2025-55560 & CVE-2025-46152
100+
96101
* Tue Apr 29 2025 Archana Shettigar <v-shettigara@microsoft.com> - 2.2.2-7
97102
- Patch CVE-2025-2953
98103

0 commit comments

Comments
 (0)