public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* MIPS patch for crash during elf load
@ 2021-11-23  4:50 Lightning
  2021-11-23  4:52 ` Lightning
  2021-11-23 15:12 ` Andrew Burgess
  0 siblings, 2 replies; 8+ messages in thread
From: Lightning @ 2021-11-23  4:50 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 996 bytes --]

GDB has a bug with MIPS binaries where loading ones with a large number of
global objects in the debug sections results in using uninitialized memory
resulting in a crash. This was seen during a debug build of the following
project: https://github.com/pmret/papermario

I downloaded GDB 11.1 and compiled it with the following options:
./configure --target=mips-linux-gnu --program-prefix=mips-linux-gnu-

My local gcc compiler is gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

I traced the issue down to the initialization of the fdt_to_pst buffer. It
is initialized in gdb/mdebugread.c on line 2369 via a gdb::def_vector
however the internal values are never cleared.  On line 2403 a struct
variable in this buffer is incremented for the number of globals. With
enough globals and sections this can result in having invalid data in the
global field causing a crash. In the above case it was stale pointer data.
The fix is the attached patch, a simple memset after the buffer is
initialized.

Jewell

[-- Attachment #2: gdb-11.1.mips.patch --]
[-- Type: application/octet-stream, Size: 486 bytes --]

--- gdb-11.1.old/gdb/mdebugread.c	2021-07-03 10:41:09.000000000 -0700
+++ gdb-11.1/gdb/mdebugread.c	2021-11-19 20:57:23.662003100 -0800
@@ -2367,6 +2367,7 @@
      to FDR -1.  We`ll go along with that.  */
   gdb::def_vector<struct pst_map> fdr_to_pst_holder (hdr->ifdMax + 1);
   fdr_to_pst = fdr_to_pst_holder.data ();
+  memset(fdr_to_pst, 0, sizeof(struct pst_map) * (hdr->ifdMax+1));
   fdr_to_pst++;
   {
     legacy_psymtab *new_pst = new_psymtab ("", partial_symtabs, objfile);

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-01 17:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23  4:50 MIPS patch for crash during elf load Lightning
2021-11-23  4:52 ` Lightning
2021-11-23 15:12 ` Andrew Burgess
2021-11-23 17:01   ` Lightning
2021-11-24 10:47     ` Andrew Burgess
2021-11-30 21:29       ` Tom Tromey
2021-12-01 10:51         ` Andrew Burgess
2021-12-01 16:08           ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).