Skip to content

Commit 08e99ce

Browse files
authored
1 parent 78c1dd1 commit 08e99ce

File tree

4 files changed

+528
-1
lines changed

4 files changed

+528
-1
lines changed

SPECS/gdb/CVE-2023-39128.patch

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
From 033bc52bb6190393c8eed80925fa78cc35b40c6d Mon Sep 17 00:00:00 2001
2+
From: Tom Tromey <[email protected]>
3+
Date: Wed, 16 Aug 2023 11:29:19 -0600
4+
Subject: [PATCH] Avoid buffer overflow in ada_decode
5+
6+
A bug report pointed out a buffer overflow in ada_decode, which Keith
7+
helpfully analyzed. ada_decode had a logic error when the input was
8+
all digits. While this isn't valid -- and would probably only appear
9+
in fuzzer tests -- it still should be handled properly.
10+
11+
This patch adds a missing bounds check. Tested with the self-tests in
12+
an asan build.
13+
14+
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30639
15+
Reviewed-by: Keith Seitz <[email protected]>
16+
---
17+
gdb/ada-lang.c | 19 ++++++++++++++++++-
18+
1 file changed, 18 insertions(+), 1 deletion(-)
19+
20+
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
21+
index 70a2b44..f682302 100644
22+
--- a/gdb/ada-lang.c
23+
+++ b/gdb/ada-lang.c
24+
@@ -57,6 +57,7 @@
25+
#include "cli/cli-utils.h"
26+
#include "gdbsupport/function-view.h"
27+
#include "gdbsupport/byte-vector.h"
28+
+#include "gdbsupport/selftest.h"
29+
#include <algorithm>
30+
#include "ada-exp.h"
31+
32+
@@ -1057,7 +1058,7 @@ ada_decode (const char *encoded, bool wrap)
33+
i -= 1;
34+
if (i > 1 && encoded[i] == '_' && encoded[i - 1] == '_')
35+
len0 = i - 1;
36+
- else if (encoded[i] == '$')
37+
+ else if (i >= 0 && encoded[i] == '$')
38+
len0 = i;
39+
}
40+
41+
@@ -1225,6 +1226,18 @@ ada_decode (const char *encoded, bool wrap)
42+
return decoded;
43+
}
44+
45+
+#ifdef GDB_SELF_TEST
46+
+
47+
+static void
48+
+ada_decode_tests ()
49+
+{
50+
+ /* This isn't valid, but used to cause a crash. PR gdb/30639. The
51+
+ result does not really matter very much. */
52+
+ SELF_CHECK (ada_decode ("44") == "44");
53+
+}
54+
+
55+
+#endif
56+
+
57+
/* Table for keeping permanent unique copies of decoded names. Once
58+
allocated, names in this table are never released. While this is a
59+
storage leak, it should not be significant unless there are massive
60+
@@ -13497,4 +13510,8 @@ DWARF attribute."),
61+
gdb::observers::new_objfile.attach (ada_new_objfile_observer, "ada-lang");
62+
gdb::observers::free_objfile.attach (ada_free_objfile_observer, "ada-lang");
63+
gdb::observers::inferior_exit.attach (ada_inferior_exit, "ada-lang");
64+
+
65+
+#ifdef GDB_SELF_TEST
66+
+ selftests::register_test ("ada-decode", ada_decode_tests);
67+
+#endif
68+
}
69+
--
70+
2.34.1
71+

SPECS/gdb/CVE-2023-39129.patch

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
From 58abdf887821a5da09ba184c6e400a3bc5cccd5a Mon Sep 17 00:00:00 2001
2+
From: Keith Seitz <[email protected]>
3+
Date: Wed, 2 Aug 2023 08:35:11 -0700
4+
Subject: [PATCH] Verify COFF symbol stringtab offset
5+
6+
This patch addresses an issue with malformed/fuzzed debug information that
7+
was recently reported in gdb/30639. That bug specifically deals with
8+
an ASAN issue, but the reproducer provided by the reporter causes a
9+
another failure outside of ASAN:
10+
11+
$ ./gdb --data-directory data-directory -nx -q UAF_2
12+
Reading symbols from /home/keiths/UAF_2...
13+
14+
15+
Fatal signal: Segmentation fault
16+
----- Backtrace -----
17+
0x59a53a gdb_internal_backtrace_1
18+
../../src/gdb/bt-utils.c:122
19+
0x59a5dd _Z22gdb_internal_backtracev
20+
../../src/gdb/bt-utils.c:168
21+
0x786380 handle_fatal_signal
22+
../../src/gdb/event-top.c:889
23+
0x7864ec handle_sigsegv
24+
../../src/gdb/event-top.c:962
25+
0x7ff354c5fb6f ???
26+
0x611f9a process_coff_symbol
27+
../../src/gdb/coffread.c:1556
28+
0x611025 coff_symtab_read
29+
../../src/gdb/coffread.c:1172
30+
0x60f8ff coff_read_minsyms
31+
../../src/gdb/coffread.c:549
32+
0x60fe4b coff_symfile_read
33+
../../src/gdb/coffread.c:698
34+
0xbde0f6 read_symbols
35+
../../src/gdb/symfile.c:772
36+
0xbde7a3 syms_from_objfile_1
37+
../../src/gdb/symfile.c:966
38+
0xbde867 syms_from_objfile
39+
../../src/gdb/symfile.c:983
40+
0xbded42 symbol_file_add_with_addrs
41+
../../src/gdb/symfile.c:1086
42+
0xbdf083 _Z24symbol_file_add_from_bfdRKN3gdb7ref_ptrI3bfd18gdb_bfd_ref_policyEEPKc10enum_flagsI16symfile_add_flagEPSt6vectorI14other_sectionsSaISC_EES8_I12objfile_flagEP7objfile
43+
../../src/gdb/symfile.c:1166
44+
0xbdf0d2 _Z15symbol_file_addPKc10enum_flagsI16symfile_add_flagEPSt6vectorI14other_sectionsSaIS5_EES1_I12objfile_flagE
45+
../../src/gdb/symfile.c:1179
46+
0xbdf197 symbol_file_add_main_1
47+
../../src/gdb/symfile.c:1203
48+
0xbdf13e _Z20symbol_file_add_mainPKc10enum_flagsI16symfile_add_flagE
49+
../../src/gdb/symfile.c:1194
50+
0x90f97f symbol_file_add_main_adapter
51+
../../src/gdb/main.c:549
52+
0x90f895 catch_command_errors
53+
../../src/gdb/main.c:518
54+
0x9109b6 captured_main_1
55+
../../src/gdb/main.c:1203
56+
0x910fc8 captured_main
57+
../../src/gdb/main.c:1310
58+
0x911067 _Z8gdb_mainP18captured_main_args
59+
../../src/gdb/main.c:1339
60+
0x418c71 main
61+
../../src/gdb/gdb.c:39
62+
---------------------
63+
A fatal error internal to GDB has been detected, further
64+
debugging is not possible. GDB will now terminate.
65+
66+
This is a bug, please report it. For instructions, see:
67+
<https://www.gnu.org/software/gdb/bugs/>.
68+
69+
Segmentation fault (core dumped)
70+
71+
The issue here is that the COFF offset for the fuzzed symbol's
72+
name is outside the string table. That is, the offset is greater
73+
than the actual string table size.
74+
75+
coffread.c:getsymname actually contains a FIXME about this, and that's
76+
what I've chosen to address to fix this issue, following what is done
77+
in the DWARF reader:
78+
79+
$ ./gdb --data-directory data-directory -nx -q UAF_2
80+
Reading symbols from /home/keiths/UAF_2...
81+
COFF Error: string table offset (256) outside string table (length 0)
82+
(gdb)
83+
84+
Unfortunately, I haven't any idea how else to test this patch since
85+
COFF is not very common anymore. GCC removed support for it five
86+
years ago with GCC 8.
87+
---
88+
gdb/coffread.c | 7 +++++--
89+
1 file changed, 5 insertions(+), 2 deletions(-)
90+
91+
diff --git a/gdb/coffread.c b/gdb/coffread.c
92+
index f8e14d8ad93..ae7632d49cb 100644
93+
--- a/gdb/coffread.c
94+
+++ b/gdb/coffread.c
95+
@@ -159,6 +159,7 @@ static file_ptr linetab_offset;
96+
static file_ptr linetab_size;
97+
98+
static char *stringtab = NULL;
99+
+static long stringtab_length = 0;
100+
101+
extern void stabsread_clear_cache (void);
102+
103+
@@ -1303,6 +1304,7 @@ init_stringtab (bfd *abfd, file_ptr offset, gdb::unique_xmalloc_ptr<char> *stora
104+
/* This is in target format (probably not very useful, and not
105+
currently used), not host format. */
106+
memcpy (stringtab, lengthbuf, sizeof lengthbuf);
107+
+ stringtab_length = length;
108+
if (length == sizeof length) /* Empty table -- just the count. */
109+
return 0;
110+
111+
@@ -1322,8 +1324,9 @@ getsymname (struct internal_syment *symbol_entry)
112+
113+
if (symbol_entry->_n._n_n._n_zeroes == 0)
114+
{
115+
- /* FIXME: Probably should be detecting corrupt symbol files by
116+
- seeing whether offset points to within the stringtab. */
117+
+ if (symbol_entry->_n._n_n._n_offset > stringtab_length)
118+
+ error (_("COFF Error: string table offset (%ld) outside string table (length %ld)"),
119+
+ symbol_entry->_n._n_n._n_offset, stringtab_length);
120+
result = stringtab + symbol_entry->_n._n_n._n_offset;
121+
}
122+
else
123+
--
124+
2.43.5

0 commit comments

Comments
 (0)