binutils: Fix CVE-2021-3530
PATCH v2 1/1 binutils: Fix CVE-2021-3530
CVE: CVE-2015-3530
Upstream-Status: Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=25162c795b1a2becf936bb3581d86a307ea491eb]
Upstream-Status: Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=999566402e3]
--- .../binutils/binutils-2.36.inc | 2 + .../binutils/0017-CVE-2021-3530.patch | 102 ++++++++++++++++++ .../binutils/0018-CVE-2021-3530.patch | 64 +++++++++++ 3 files changed, 168 insertions(+) create mode 100644 meta/recipes-devtools/binutils/binutils/0017-CVE-2021-3530.patch create mode 100644 meta/recipes-devtools/binutils/binutils/0018-CVE-2021-3530.patch
meta/recipes-devtools/binutils/binutils-2.36.inc +2 -0
@@ -44,5 +44,7 @@ SRC_URI = "\ file://0001-CVE-2021-20197.patch \ file://0002-CVE-2021-20197.patch \ file://0003-CVE-2021-20197.patch \ + file://0017-CVE-2021-3530.patch \ + file://0018-CVE-2021-3530.patch \ " S = "${WORKDIR}/git"
meta/recipes-devtools/binutils/binutils/0017-CVE-2021-3530.patch new file +102 -0
102 lines not on this page · raw message
meta/recipes-devtools/binutils/binutils/0018-CVE-2021-3530.patch new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 1 line · Pgowda
CVE: CVE-2015-3530
Did you mean CVE-2021-3530 here and in the patches below as well?
Thanks,
Anuj
Quoted 226 lines
Upstream-Status:
Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=25162c795b1a2becf936bb3581d86a307ea491eb ]
Upstream-Status:
Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=999566402e3
]Signed-off-by Pgowda <[email protected]>---
.../binutils/binutils-2.36.inc | 2 + .../binutils/0017-CVE-2021-3530.patch | 102
++++++++++++++++++
.../binutils/0018-CVE-2021-3530.patch | 64 +++++++++++3 files changed, 168 insertions(+)create mode 100644 meta/recipes-devtools/binutils/binutils/0017-CVE- 2021-3530.patch
create mode 100644 meta/recipes-devtools/binutils/binutils/0018-CVE- 2021-3530.patchmeta/recipes-devtools/binutils/binutils-2.36.inc +2
-0@@ -44,5 +44,7 @@ SRC_URI = "\ file://0001-CVE-2021-20197.patch \ file://0002-CVE-2021-20197.patch \ file://0003-CVE-2021-20197.patch \ + file://0017-CVE-2021-3530.patch \ + file://0018-CVE-2021-3530.patch \"
S = "${WORKDIR}/git"(quoted diff) +0
-03530.patch b/meta/recipes-devtools/binutils/binutils/0017-CVE-2021- 3530.patch
new file mode 100644
index 0000000000..3eba99132bmeta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +0
-03530.patch
meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +1
-0@@ -0,0 +1,102 @@ +From 25162c795b1a2becf936bb3581d86a307ea491eb Mon Sep 17 00:00:002001
meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +3
-0+From: Nick Clifton <[email protected]> +Date: Thu, 15 Jul 2021 16:51:56 +0100 +Subject: [PATCH] Fix a stack exhaustion problem in the Rustdemangling code in
+ the libiberty library.meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +6
-0+ + PR 99935 + * rust-demangle.c: Add recursion limit. + +CVE: CVE-2015-3530 +Upstream-Status:Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=25162c795b1a2becf936bb3581d86a307ea491eb ]
meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +31
-0+Signed-off-by: Pgowda <[email protected]> + +--- + libiberty/ChangeLog | 5 +++++ + libiberty/rust-demangle.c | 31 +++++++++++++++++++++++++------ + 2 files changed, 30 insertions(+), 6 deletions(-) + +diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog +index bc1b35b97c4..8e39fd28eba 100644 +--- a/libiberty/ChangeLog ++++ b/libiberty/ChangeLog +@@ -1,3 +1,8 @@ ++2021-07-15 Nick Clifton <[email protected]> ++ ++ PR 99935 ++ * rust-demangle.c: Add recursion limit. ++ + 2021-01-04 Martin Liska <[email protected]> + + * strverscmp.c: Convert to utf8 from iso8859. +diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c +index 449941b56dc..df09b7b8fdd 100644 +--- a/libiberty/rust-demangle.c ++++ b/libiberty/rust-demangle.c +@@ -74,6 +74,12 @@ struct rust_demangler + /* Rust mangling version, with legacy mangling being -1. */ + int version; + ++ /* Recursion depth. */ ++ uint recursion; ++ /* Maximum number of times demangle_path may be calledrecursively. */
++#define RUST_MAX_RECURSION_COUNT 1024
++#define RUST_NO_RECURSION_LIMIT ((uint) -1)
++
+uint64_tbound_lifetime_depth;
+ };
+
+@@ -671,6 +677,15 @@demangle_path(structrust_demangler*rd + if (rdm->errored)
+ return;
+
++ if (rdm->recursion!=RUST_NO_RECURSION_LIMIT) ++ {
++ ++rdm->recursion;
++ if (rdm->recursion>RUST_MAX_RECURSION_COUNT) ++ /* FIXME: There ought to be a way to report ++ that the recursion limit has been reached. */ ++ gotofail_return;
++ }
++
+ switch (tag = next (rdm))
+ {
+ case 'C':
+@@ -688,10 +703,7 @@demangle_path(structrust_demangler*rd + case 'N':
+ ns = next (rdm);
+ if (!ISLOWER (ns) && !ISUPPER (ns))+- { +- rdm->errored = 1; +- return; +- }++ goto
fail_return;
+
+demangle_path(rdm,in_value);
+
+@@ -776,9 +788,15 @@demangle_path(structrust_demangler*rd + }
+ break;
+ default:+- rdm->errored = 1; +- return;++ goto
fail_return;
+ }
++ gotopass_return;
++
++fail_return:
++rdm->errored= 1;
++pass_return:
++ if (rdm->recursion!=RUST_NO_RECURSION_LIMIT)
++ --rdm->recursion;
+ }
+
+ static void
+@@ -1317,6 +1335,7 @@rust_demangle_callback(const char *mang + rdm.skipping_printing = 0;
+ rdm.verbose = (options &DMGL_VERBOSE) != 0;
+ rdm.version = 0;
++ rdm.recursion = (options &DMGL_NO_RECURSE_LIMIT) ?RUST_NO_RECURSION_LIMIT: 0;
+ rdm.bound_lifetime_depth = 0;
+
+ /* Rust symbols always start with _R (v0) or_ZN(legacy). */(quoted diff) +0
-03530.patch b/meta/recipes-devtools/binutils/binutils/0018-CVE-2021- 3530.patch
new file mode 100644
index 0000000000..857ac5b3d0meta/recipes-devtools/binutils/binutils/0018-CVE-2021- new file +0
-03530.patch
meta/recipes-devtools/binutils/binutils/0018-CVE-2021- new file +1
-0@@ -0,0 +1,64 @@ +From 999566402e3d7c69032bbf47e28b44fc0926fe62 Mon Sep 17 00:00:002001
meta/recipes-devtools/binutils/binutils/0018-CVE-2021- new file +22
-0+From: Christopher Wellons <[email protected]> +Date: Sun, 18 Jul 2021 16:57:19 -0400 +Subject: [PATCH] Change "uint" to "unsigned" + +This fixes a defect introduced in 25162c795. The "uint" type has not +been explicitly defined here on mingw, causing compilation to fail. + +On linux we have this in /usr/include/sys/types.h + +/* Old compatibility names for C types. */ +typedef unsigned long int ulong; +typedef unsigned short int ushort; +typedef unsigned int uint; + +So it's easy to see how such bugs can creep in. + + * rust-demangle.c (struct rust_demangler): Change type of + "recursion" to unsigned. + (RUST_NO_RECURSION_LIMIT): Similarly in cast. + +CVE: CVE-2015-3530 +Upstream-Status:Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=999566402e3 ]
meta/recipes-devtools/binutils/binutils/0018-CVE-2021- new file +32
-0+Signed-off-by: Pgowda <[email protected]> + +--- + libiberty/ChangeLog | 6 ++++++ + libiberty/rust-demangle.c | 4 ++-- + 2 files changed, 8 insertions(+), 2 deletions(-) + +diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog +index 8e39fd28eba..3f749455f05 100644 +--- a/libiberty/ChangeLog ++++ b/libiberty/ChangeLog +@@ -1,3 +1,9 @@ ++2021-07-19 Christopher Wellons <[email protected]> ++ ++ * rust-demangle.c (struct rust_demangler): Change type of ++ "recursion" to unsigned. ++ (RUST_NO_RECURSION_LIMIT): Similarly in cast. ++ + 2021-07-15 Nick Clifton <[email protected]> + + PR 99935 +diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c +index df09b7b8fdd..ac1eb8eb02c 100644 +--- a/libiberty/rust-demangle.c ++++ b/libiberty/rust-demangle.c +@@ -75,10 +75,10 @@ struct rust_demangler + int version; + + /* Recursion depth. */ +- uint recursion; ++ unsigned recursion; + /* Maximum number of times demangle_path may be calledrecursively. */
+ #define RUST_MAX_RECURSION_COUNT 1024 +-#define RUST_NO_RECURSION_LIMIT ((uint) -1) ++#define RUST_NO_RECURSION_LIMIT ((unsigned) -1) +
+uint64_tbound_lifetime_depth;
+ };
+--
+2.27.0
+
Quoted 1 line
Quoted 1 line
Did you mean CVE-2021-3530 here and in the patches below as well?
Should I have it in the commit message or in the patches?
Thanks,
Naveen
Quoted 237 lines · Anuj
Quoted 1 line · Pgowda
CVE: CVE-2015-3530
Did you mean CVE-2021-3530 here and in the patches below as well?
Thanks,
Anuj
Quoted 226 lines
Upstream-Status:
Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=25162c795b1a2becf936bb3581d86a307ea491eb ]
Upstream-Status:
Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=999566402e3
]Signed-off-by Pgowda <[email protected]>--- .../binutils/binutils-2.36.inc | 2 + .../binutils/0017-CVE-2021-3530.patch | 102 ++++++++++++++++++ .../binutils/0018-CVE-2021-3530.patch | 64 +++++++++++ 3 files changed, 168 insertions(+) create mode 100644 meta/recipes-devtools/binutils/binutils/0017-CVE- 2021-3530.patch create mode 100644 meta/recipes-devtools/binutils/binutils/0018-CVE-2021-3530.patch
meta/recipes-devtools/binutils/binutils-2.36.inc +2
-0@@ -44,5 +44,7 @@ SRC_URI = "\ file://0001-CVE-2021-20197.patch \ file://0002-CVE-2021-20197.patch \ file://0003-CVE-2021-20197.patch \ + file://0017-CVE-2021-3530.patch \ + file://0018-CVE-2021-3530.patch \ " S = "${WORKDIR}/git"(quoted diff) +0
-03530.patch b/meta/recipes-devtools/binutils/binutils/0017-CVE-2021- 3530.patch
new file mode 100644
index 0000000000..3eba99132bmeta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +0
-03530.patch
meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +1
-0@@ -0,0 +1,102 @@ +From 25162c795b1a2becf936bb3581d86a307ea491eb Mon Sep 17 00:00:002001
meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +3
-0+From: Nick Clifton <[email protected]> +Date: Thu, 15 Jul 2021 16:51:56 +0100 +Subject: [PATCH] Fix a stack exhaustion problem in the Rustdemangling code in
+ the libiberty library.meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +6
-0+ + PR 99935 + * rust-demangle.c: Add recursion limit. + +CVE: CVE-2015-3530 +Upstream-Status:Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=25162c795b1a2becf936bb3581d86a307ea491eb ]
meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +31
-0+Signed-off-by: Pgowda <[email protected]> + +--- + libiberty/ChangeLog | 5 +++++ + libiberty/rust-demangle.c | 31 +++++++++++++++++++++++++------ + 2 files changed, 30 insertions(+), 6 deletions(-) + +diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog +index bc1b35b97c4..8e39fd28eba 100644 +--- a/libiberty/ChangeLog ++++ b/libiberty/ChangeLog +@@ -1,3 +1,8 @@ ++2021-07-15 Nick Clifton <[email protected]> ++ ++ PR 99935 ++ * rust-demangle.c: Add recursion limit. ++ + 2021-01-04 Martin Liska <[email protected]> + + * strverscmp.c: Convert to utf8 from iso8859. +diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c +index 449941b56dc..df09b7b8fdd 100644 +--- a/libiberty/rust-demangle.c ++++ b/libiberty/rust-demangle.c +@@ -74,6 +74,12 @@ struct rust_demangler + /* Rust mangling version, with legacy mangling being -1. */ + int version; + ++ /* Recursion depth. */ ++ uint recursion; ++ /* Maximum number of times demangle_path may be calledrecursively. */
++#defineRUST_MAX_RECURSION_COUNT1024
++#defineRUST_NO_RECURSION_LIMIT((uint) -1)
++meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +54
-0+ uint64_t bound_lifetime_depth; + }; + +@@ -671,6 +677,15 @@ demangle_path (struct rust_demangler *rd + if (rdm->errored) + return; + ++ if (rdm->recursion != RUST_NO_RECURSION_LIMIT) ++ { ++ ++ rdm->recursion; ++ if (rdm->recursion > RUST_MAX_RECURSION_COUNT) ++ /* FIXME: There ought to be a way to report ++ that the recursion limit has been reached. */ ++ goto fail_return; ++ } ++ + switch (tag = next (rdm)) + { + case 'C': +@@ -688,10 +703,7 @@ demangle_path (struct rust_demangler *rd + case 'N': + ns = next (rdm); + if (!ISLOWER (ns) && !ISUPPER (ns)) +- { +- rdm->errored = 1; +- return; +- } ++ goto fail_return; + + demangle_path (rdm, in_value); + +@@ -776,9 +788,15 @@ demangle_path (struct rust_demangler *rd + } + break; + default: +- rdm->errored = 1; +- return; ++ goto fail_return; + } ++ goto pass_return; ++ ++ fail_return: ++ rdm->errored = 1; ++ pass_return: ++ if (rdm->recursion != RUST_NO_RECURSION_LIMIT) ++ -- rdm->recursion; + } + + static void +@@ -1317,6 +1335,7 @@ rust_demangle_callback (const char *mang + rdm.skipping_printing = 0; + rdm.verbose = (options & DMGL_VERBOSE) != 0; + rdm.version = 0; ++ rdm.recursion = (options & DMGL_NO_RECURSE_LIMIT) ?
RUST_NO_RECURSION_LIMIT: 0;meta/recipes-devtools/binutils/binutils/0017-CVE-2021- new file +3
-0+ rdm.bound_lifetime_depth = 0; + + /* Rust symbols always start with _R (v0) or _ZN (legacy). */(quoted diff) +0
-03530.patch b/meta/recipes-devtools/binutils/binutils/0018-CVE-2021- 3530.patch
new file mode 100644
index 0000000000..857ac5b3d0meta/recipes-devtools/binutils/binutils/0018-CVE-2021- new file +0
-03530.patch
meta/recipes-devtools/binutils/binutils/0018-CVE-2021- new file +1
-0@@ -0,0 +1,64 @@ +From 999566402e3d7c69032bbf47e28b44fc0926fe62 Mon Sep 17 00:00:002001
meta/recipes-devtools/binutils/binutils/0018-CVE-2021- new file +22
-0+From: Christopher Wellons <[email protected]> +Date: Sun, 18 Jul 2021 16:57:19 -0400 +Subject: [PATCH] Change "uint" to "unsigned" + +This fixes a defect introduced in 25162c795. The "uint" type has not +been explicitly defined here on mingw, causing compilation to fail. + +On linux we have this in /usr/include/sys/types.h + +/* Old compatibility names for C types. */ +typedef unsigned long int ulong; +typedef unsigned short int ushort; +typedef unsigned int uint; + +So it's easy to see how such bugs can creep in. + + * rust-demangle.c (struct rust_demangler): Change type of + "recursion" to unsigned. + (RUST_NO_RECURSION_LIMIT): Similarly in cast. + +CVE: CVE-2015-3530 +Upstream-Status:Backport[https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=999566402e3 ]
meta/recipes-devtools/binutils/binutils/0018-CVE-2021- new file +32
-0+Signed-off-by: Pgowda <[email protected]> + +--- + libiberty/ChangeLog | 6 ++++++ + libiberty/rust-demangle.c | 4 ++-- + 2 files changed, 8 insertions(+), 2 deletions(-) + +diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog +index 8e39fd28eba..3f749455f05 100644 +--- a/libiberty/ChangeLog ++++ b/libiberty/ChangeLog +@@ -1,3 +1,9 @@ ++2021-07-19 Christopher Wellons <[email protected]> ++ ++ * rust-demangle.c (struct rust_demangler): Change type of ++ "recursion" to unsigned. ++ (RUST_NO_RECURSION_LIMIT): Similarly in cast. ++ + 2021-07-15 Nick Clifton <[email protected]> + + PR 99935 +diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c +index df09b7b8fdd..ac1eb8eb02c 100644 +--- a/libiberty/rust-demangle.c ++++ b/libiberty/rust-demangle.c +@@ -75,10 +75,10 @@ struct rust_demangler + int version; + + /* Recursion depth. */ +- uint recursion; ++ unsigned recursion; + /* Maximum number of times demangle_path may be calledrecursively. */
+ #define RUST_MAX_RECURSION_COUNT 1024 +-#define RUST_NO_RECURSION_LIMIT ((uint) -1) ++#define RUST_NO_RECURSION_LIMIT ((unsigned) -1)meta/recipes-devtools/binutils/binutils/0018-CVE-2021- new file +6
-0+ + uint64_t bound_lifetime_depth; + }; +-- +2.27.0 +