Skip to content

Commit ad24d46

Browse files
[MEDIUM] Patch gcc for CVE-2021-32256 (microsoft#13503)
Co-authored-by: kgodara912 <[email protected]>
1 parent fdaaaeb commit ad24d46

File tree

7 files changed

+269
-46
lines changed

7 files changed

+269
-46
lines changed

SPECS/gcc/CVE-2021-32256.patch

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
From c20164630509c015414c4dbef467a04377dbc6ca Mon Sep 17 00:00:00 2001
2+
From: archana25-ms <[email protected]>
3+
Date: Fri, 18 Apr 2025 08:04:25 +0000
4+
Subject: [PATCH] Address CVE-2021-32256
5+
Upstream Patch Reference : https://gcc.gnu.org/pipermail/gcc-patches/attachments/20220324/63021510/attachment.bin
6+
---
7+
libiberty/rust-demangle.c | 29 ++++++++++++++++++++---------
8+
1 file changed, 20 insertions(+), 9 deletions(-)
9+
10+
diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c
11+
index 449941b56..13c3e7b20 100644
12+
--- a/libiberty/rust-demangle.c
13+
+++ b/libiberty/rust-demangle.c
14+
@@ -120,7 +120,7 @@ parse_integer_62 (struct rust_demangler *rdm)
15+
return 0;
16+
17+
x = 0;
18+
- while (!eat (rdm, '_'))
19+
+ while (!eat (rdm, '_') && !rdm->errored)
20+
{
21+
c = next (rdm);
22+
x *= 62;
23+
@@ -1114,6 +1114,15 @@ demangle_const (struct rust_demangler *rdm)
24+
if (rdm->errored)
25+
return;
26+
27+
+ if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
28+
+ {
29+
+ ++ rdm->recursion;
30+
+ if (rdm->recursion > RUST_MAX_RECURSION_COUNT)
31+
+ /* FIXME: There ought to be a way to report
32+
+ that the recursion limit has been reached. */
33+
+ goto fail_return;
34+
+ }
35+
+
36+
if (eat (rdm, 'B'))
37+
{
38+
backref = parse_integer_62 (rdm);
39+
@@ -1124,7 +1133,7 @@ demangle_const (struct rust_demangler *rdm)
40+
demangle_const (rdm);
41+
rdm->next = old_next;
42+
}
43+
- return;
44+
+ goto pass_return;
45+
}
46+
47+
ty_tag = next (rdm);
48+
@@ -1133,7 +1142,7 @@ demangle_const (struct rust_demangler *rdm)
49+
/* Placeholder. */
50+
case 'p':
51+
PRINT ("_");
52+
- return;
53+
+ goto pass_return;
54+
55+
/* Unsigned integer types. */
56+
case 'h':
57+
@@ -1166,18 +1175,21 @@ demangle_const (struct rust_demangler *rdm)
58+
break;
59+
60+
default:
61+
- rdm->errored = 1;
62+
- return;
63+
+ goto fail_return;
64+
}
65+
66+
- if (rdm->errored)
67+
- return;
68+
-
69+
- if (rdm->verbose)
70+
+ if (!rdm->errored && rdm->verbose)
71+
{
72+
PRINT (": ");
73+
PRINT (basic_type (ty_tag));
74+
}
75+
+
76+
+ goto pass_return;
77+
+ fail_return:
78+
+ rdm->errored = 1;
79+
+ pass_return:
80+
+ if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
81+
+ -- rdm->recursion;
82+
}
83+
84+
static void
85+
--
86+
2.45.3
87+
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
From f10bec5ffa487ad3033ed5f38cfd0fc7d696deab Mon Sep 17 00:00:00 2001
2+
From: Nick Clifton <[email protected]>
3+
Date: Mon, 31 Jan 2022 14:28:42 +0000
4+
Subject: libiberty: Fix infinite recursion in rust demangler.
5+
6+
libiberty/
7+
PR demangler/98886
8+
PR demangler/99935
9+
* rust-demangle.c (struct rust_demangler): Add a recursion
10+
counter.
11+
(demangle_path): Increment/decrement the recursion counter upon
12+
entry and exit. Fail if the counter exceeds a fixed limit.
13+
(demangle_type): Likewise.
14+
(rust_demangle_callback): Initialise the recursion counter,
15+
disabling if requested by the option flags.
16+
---
17+
libiberty/rust-demangle.c | 47 +++++++++++++++++++++++++++++++++++++++++------
18+
1 file changed, 41 insertions(+), 6 deletions(-)
19+
20+
diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c
21+
index 18c760491bdc..3b24d63892a9 100644
22+
--- a/libiberty/rust-demangle.c
23+
+++ b/libiberty/rust-demangle.c
24+
@@ -74,6 +74,12 @@ struct rust_demangler
25+
/* Rust mangling version, with legacy mangling being -1. */
26+
int version;
27+
28+
+ /* Recursion depth. */
29+
+ unsigned int recursion;
30+
+ /* Maximum number of times demangle_path may be called recursively. */
31+
+#define RUST_MAX_RECURSION_COUNT 1024
32+
+#define RUST_NO_RECURSION_LIMIT ((unsigned int) -1)
33+
+
34+
uint64_t bound_lifetime_depth;
35+
};
36+
37+
@@ -671,6 +677,15 @@ demangle_path (struct rust_demangler *rdm, int in_value)
38+
if (rdm->errored)
39+
return;
40+
41+
+ if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
42+
+ {
43+
+ ++ rdm->recursion;
44+
+ if (rdm->recursion > RUST_MAX_RECURSION_COUNT)
45+
+ /* FIXME: There ought to be a way to report
46+
+ that the recursion limit has been reached. */
47+
+ goto fail_return;
48+
+ }
49+
+
50+
switch (tag = next (rdm))
51+
{
52+
case 'C':
53+
@@ -688,10 +703,7 @@ demangle_path (struct rust_demangler *rdm, int in_value)
54+
case 'N':
55+
ns = next (rdm);
56+
if (!ISLOWER (ns) && !ISUPPER (ns))
57+
- {
58+
- rdm->errored = 1;
59+
- return;
60+
- }
61+
+ goto fail_return;
62+
63+
demangle_path (rdm, in_value);
64+
65+
@@ -776,9 +788,15 @@ demangle_path (struct rust_demangler *rdm, int in_value)
66+
}
67+
break;
68+
default:
69+
- rdm->errored = 1;
70+
- return;
71+
+ goto fail_return;
72+
}
73+
+ goto pass_return;
74+
+
75+
+ fail_return:
76+
+ rdm->errored = 1;
77+
+ pass_return:
78+
+ if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
79+
+ -- rdm->recursion;
80+
}
81+
82+
static void
83+
@@ -870,6 +888,19 @@ demangle_type (struct rust_demangler *rdm)
84+
return;
85+
}
86+
87+
+ if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
88+
+ {
89+
+ ++ rdm->recursion;
90+
+ if (rdm->recursion > RUST_MAX_RECURSION_COUNT)
91+
+ /* FIXME: There ought to be a way to report
92+
+ that the recursion limit has been reached. */
93+
+ {
94+
+ rdm->errored = 1;
95+
+ -- rdm->recursion;
96+
+ return;
97+
+ }
98+
+ }
99+
+
100+
switch (tag)
101+
{
102+
case 'R':
103+
@@ -1030,6 +1061,9 @@ demangle_type (struct rust_demangler *rdm)
104+
rdm->next--;
105+
demangle_path (rdm, 0);
106+
}
107+
+
108+
+ if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
109+
+ -- rdm->recursion;
110+
}
111+
112+
/* A trait in a trait object may have some "existential projections"
113+
@@ -1320,6 +1354,7 @@ rust_demangle_callback (const char *mangled, int options,
114+
rdm.skipping_printing = 0;
115+
rdm.verbose = (options & DMGL_VERBOSE) != 0;
116+
rdm.version = 0;
117+
+ rdm.recursion = (options & DMGL_NO_RECURSE_LIMIT) ? RUST_NO_RECURSION_LIMIT : 0;
118+
rdm.bound_lifetime_depth = 0;
119+
120+
/* Rust symbols always start with _R (v0) or _ZN (legacy). */
121+
--
122+
cgit
123+

SPECS/gcc/gcc.spec

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@
5656
Summary: Contains the GNU compiler collection
5757
Name: gcc
5858
Version: 11.2.0
59-
Release: 8%{?dist}
59+
Release: 9%{?dist}
6060
License: GPLv2+
6161
Vendor: Microsoft Corporation
6262
Distribution: Mariner
6363
Group: Development/Tools
6464
URL: https://gcc.gnu.org/
6565
Source0: https://ftp.gnu.org/gnu/gcc/%{name}-%{version}/%{name}-%{version}.tar.xz
6666
Patch0: CVE-2023-4039.patch
67+
Patch1: fix-infinite-recursion.patch
68+
Patch2: CVE-2021-32256.patch
6769

6870
BuildRequires: gmp-devel
6971
BuildRequires: mpfr-devel
@@ -397,6 +399,12 @@ chmod +x %{__ar_no_strip}
397399
%undefine __strip
398400
%global __strip %{__ar_no_strip}
399401

402+
# Copy libcc1 library files on the systems where it is not copied
403+
if [[ ! -f %{buildroot}%{_libdir}/libcc1.so ]]
404+
then
405+
cp -p %{buildroot}%{_lib64dir}/libcc1.* %{buildroot}%{_libdir}/
406+
fi
407+
400408
%check
401409
ulimit -s 32768
402410

@@ -425,6 +433,8 @@ $tests_ok
425433
%exclude %{_bindir}/*gfortran
426434
%exclude %{_bindir}/*c++
427435
%exclude %{_bindir}/*g++
436+
%exclude %{_lib64dir}/libcc1.*
437+
%exclude %{_libdir}/libcc1.*
428438
%{_bindir}/*
429439
# Libraries
430440
%{_lib64dir}/*
@@ -520,6 +530,9 @@ $tests_ok
520530
%do_files aarch64-linux-gnu %{build_cross}
521531

522532
%changelog
533+
* Fri Apr 18 2025 Archana Shettigar <[email protected]> - 11.2.0-9
534+
- Patch CVE-2021-32256 along with supporting patch
535+
523536
* Mon Dec 11 2023 Pawel Winogrodzki <[email protected]> - 11.2.0-8
524537
- Added cross-compilation support for aarch64.
525538
- Used Fedora 36 spec (license: MIT) for guidance.

toolkit/resources/manifests/package/pkggen_core_aarch64.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ mpfr-4.1.0-2.cm2.aarch64.rpm
2020
mpfr-devel-4.1.0-2.cm2.aarch64.rpm
2121
libmetalink-0.1.3-1.cm2.aarch64.rpm
2222
libmpc-1.2.1-1.cm2.aarch64.rpm
23-
libgcc-11.2.0-8.cm2.aarch64.rpm
24-
libgcc-atomic-11.2.0-8.cm2.aarch64.rpm
25-
libgcc-devel-11.2.0-8.cm2.aarch64.rpm
26-
libstdc++-11.2.0-8.cm2.aarch64.rpm
27-
libstdc++-devel-11.2.0-8.cm2.aarch64.rpm
28-
libgomp-11.2.0-8.cm2.aarch64.rpm
29-
libgomp-devel-11.2.0-8.cm2.aarch64.rpm
30-
gcc-11.2.0-8.cm2.aarch64.rpm
31-
gcc-c++-11.2.0-8.cm2.aarch64.rpm
23+
libgcc-11.2.0-9.cm2.aarch64.rpm
24+
libgcc-atomic-11.2.0-9.cm2.aarch64.rpm
25+
libgcc-devel-11.2.0-9.cm2.aarch64.rpm
26+
libstdc++-11.2.0-9.cm2.aarch64.rpm
27+
libstdc++-devel-11.2.0-9.cm2.aarch64.rpm
28+
libgomp-11.2.0-9.cm2.aarch64.rpm
29+
libgomp-devel-11.2.0-9.cm2.aarch64.rpm
30+
gcc-11.2.0-9.cm2.aarch64.rpm
31+
gcc-c++-11.2.0-9.cm2.aarch64.rpm
3232
libpkgconf-1.8.0-3.cm2.aarch64.rpm
3333
pkgconf-1.8.0-3.cm2.aarch64.rpm
3434
pkgconf-m4-1.8.0-3.cm2.noarch.rpm

toolkit/resources/manifests/package/pkggen_core_x86_64.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ mpfr-4.1.0-2.cm2.x86_64.rpm
2020
mpfr-devel-4.1.0-2.cm2.x86_64.rpm
2121
libmetalink-0.1.3-1.cm2.x86_64.rpm
2222
libmpc-1.2.1-1.cm2.x86_64.rpm
23-
libgcc-11.2.0-8.cm2.x86_64.rpm
24-
libgcc-atomic-11.2.0-8.cm2.x86_64.rpm
25-
libgcc-devel-11.2.0-8.cm2.x86_64.rpm
26-
libstdc++-11.2.0-8.cm2.x86_64.rpm
27-
libstdc++-devel-11.2.0-8.cm2.x86_64.rpm
28-
libgomp-11.2.0-8.cm2.x86_64.rpm
29-
libgomp-devel-11.2.0-8.cm2.x86_64.rpm
30-
gcc-11.2.0-8.cm2.x86_64.rpm
31-
gcc-c++-11.2.0-8.cm2.x86_64.rpm
23+
libgcc-11.2.0-9.cm2.x86_64.rpm
24+
libgcc-atomic-11.2.0-9.cm2.x86_64.rpm
25+
libgcc-devel-11.2.0-9.cm2.x86_64.rpm
26+
libstdc++-11.2.0-9.cm2.x86_64.rpm
27+
libstdc++-devel-11.2.0-9.cm2.x86_64.rpm
28+
libgomp-11.2.0-9.cm2.x86_64.rpm
29+
libgomp-devel-11.2.0-9.cm2.x86_64.rpm
30+
gcc-11.2.0-9.cm2.x86_64.rpm
31+
gcc-c++-11.2.0-9.cm2.x86_64.rpm
3232
libpkgconf-1.8.0-3.cm2.x86_64.rpm
3333
pkgconf-1.8.0-3.cm2.x86_64.rpm
3434
pkgconf-m4-1.8.0-3.cm2.noarch.rpm

toolkit/resources/manifests/package/toolchain_aarch64.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ flex-debuginfo-2.6.4-7.cm2.aarch64.rpm
9191
flex-devel-2.6.4-7.cm2.aarch64.rpm
9292
gawk-5.1.1-1.cm2.aarch64.rpm
9393
gawk-debuginfo-5.1.1-1.cm2.aarch64.rpm
94-
gcc-11.2.0-8.cm2.aarch64.rpm
95-
gcc-c++-11.2.0-8.cm2.aarch64.rpm
96-
gcc-debuginfo-11.2.0-8.cm2.aarch64.rpm
94+
gcc-11.2.0-9.cm2.aarch64.rpm
95+
gcc-c++-11.2.0-9.cm2.aarch64.rpm
96+
gcc-debuginfo-11.2.0-9.cm2.aarch64.rpm
9797
gdbm-1.21-1.cm2.aarch64.rpm
9898
gdbm-debuginfo-1.21-1.cm2.aarch64.rpm
9999
gdbm-devel-1.21-1.cm2.aarch64.rpm
100100
gdbm-lang-1.21-1.cm2.aarch64.rpm
101101
gettext-0.21-3.cm2.aarch64.rpm
102102
gettext-debuginfo-0.21-3.cm2.aarch64.rpm
103-
gfortran-11.2.0-8.cm2.aarch64.rpm
103+
gfortran-11.2.0-9.cm2.aarch64.rpm
104104
glib-2.71.0-7.cm2.aarch64.rpm
105105
glib-debuginfo-2.71.0-7.cm2.aarch64.rpm
106106
glib-devel-2.71.0-7.cm2.aarch64.rpm
@@ -150,7 +150,7 @@ libarchive-devel-3.6.1-7.cm2.aarch64.rpm
150150
libassuan-2.5.5-2.cm2.aarch64.rpm
151151
libassuan-debuginfo-2.5.5-2.cm2.aarch64.rpm
152152
libassuan-devel-2.5.5-2.cm2.aarch64.rpm
153-
libbacktrace-static-11.2.0-8.cm2.aarch64.rpm
153+
libbacktrace-static-11.2.0-9.cm2.aarch64.rpm
154154
libcap-2.60-4.cm2.aarch64.rpm
155155
libcap-debuginfo-2.60-4.cm2.aarch64.rpm
156156
libcap-devel-2.60-4.cm2.aarch64.rpm
@@ -160,14 +160,14 @@ libcap-ng-devel-0.8.2-2.cm2.aarch64.rpm
160160
libffi-3.4.2-3.cm2.aarch64.rpm
161161
libffi-debuginfo-3.4.2-3.cm2.aarch64.rpm
162162
libffi-devel-3.4.2-3.cm2.aarch64.rpm
163-
libgcc-11.2.0-8.cm2.aarch64.rpm
164-
libgcc-atomic-11.2.0-8.cm2.aarch64.rpm
165-
libgcc-devel-11.2.0-8.cm2.aarch64.rpm
163+
libgcc-11.2.0-9.cm2.aarch64.rpm
164+
libgcc-atomic-11.2.0-9.cm2.aarch64.rpm
165+
libgcc-devel-11.2.0-9.cm2.aarch64.rpm
166166
libgcrypt-1.10.3-1.cm2.aarch64.rpm
167167
libgcrypt-debuginfo-1.10.3-1.cm2.aarch64.rpm
168168
libgcrypt-devel-1.10.3-1.cm2.aarch64.rpm
169-
libgomp-11.2.0-8.cm2.aarch64.rpm
170-
libgomp-devel-11.2.0-8.cm2.aarch64.rpm
169+
libgomp-11.2.0-9.cm2.aarch64.rpm
170+
libgomp-devel-11.2.0-9.cm2.aarch64.rpm
171171
libgpg-error-1.46-1.cm2.aarch64.rpm
172172
libgpg-error-debuginfo-1.46-1.cm2.aarch64.rpm
173173
libgpg-error-devel-1.46-1.cm2.aarch64.rpm
@@ -202,8 +202,8 @@ libsolv-tools-0.7.24-1.cm2.aarch64.rpm
202202
libssh2-1.9.0-4.cm2.aarch64.rpm
203203
libssh2-debuginfo-1.9.0-4.cm2.aarch64.rpm
204204
libssh2-devel-1.9.0-4.cm2.aarch64.rpm
205-
libstdc++-11.2.0-8.cm2.aarch64.rpm
206-
libstdc++-devel-11.2.0-8.cm2.aarch64.rpm
205+
libstdc++-11.2.0-9.cm2.aarch64.rpm
206+
libstdc++-devel-11.2.0-9.cm2.aarch64.rpm
207207
libtasn1-4.19.0-2.cm2.aarch64.rpm
208208
libtasn1-debuginfo-4.19.0-2.cm2.aarch64.rpm
209209
libtasn1-devel-4.19.0-2.cm2.aarch64.rpm

0 commit comments

Comments
 (0)