]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Fix use-after-free when an objfile has no symbols to load
authorGuinevere Larsen <guinevere@redhat.com>
Thu, 5 Dec 2024 13:19:59 +0000 (10:19 -0300)
committerGuinevere Larsen <guinevere@redhat.com>
Fri, 6 Dec 2024 17:36:58 +0000 (14:36 -0300)
The recent commit <HASH> moved an initialization of an objfile_holder in
syms_from_objfile_1 much earlier in the function, to better deal with
when GDB is unable to read the objfile format.

However, there is an early exit from syms_from_objfile_1 when the
objfile can be understood, but has no symbols. That was not releasing
the objfile_holder, so the objfile was being unlinked from the program
space, but the process of reading the objfile was being continued,
leading to use-after-frees flagged by the Address Sanitizer.

This commit fixes that UAF by making the objfile_holder release the
objfile right before the early exit.

This commit also changes the test gdb.base/dump.exp since that was the
original test that flagged the UAF, but at the end of the test the
generated files were being deleted, meaning we couldn't redo the test
manually after the fact. That final deletion was removed

Reported-by: Simon Marchi <simark@simark.ca>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/symfile.c
gdb/testsuite/gdb.base/dump.exp

index 3fd6c8d73a2bc2050dbe5a40a71990c8255e15d1..28c0d46ab54cd851c7f9b62d189d185676288609 100644 (file)
@@ -901,6 +901,10 @@ syms_from_objfile_1 (struct objfile *objfile,
       int num_sections = gdb_bfd_count_sections (objfile->obfd.get ());
 
       objfile->section_offsets.assign (num_sections, 0);
+
+      /* Release the objfile unique pointer, since nothing went wrong
+        in reading it.  */
+      objfile_holder.release ();
       return;
     }
 
index 3c7bee5ff304fa2369cd762dad266b6749ce9a29..58fedb1d36b393c42fd4db07c58eaf5194a0da99 100644 (file)
@@ -564,7 +564,3 @@ if {![string compare $is64bitonly "no"]} {
       "reload struct as memory, tekhex" \
        $struct_val "\*$struct_ptr_type"
 }
-
-# clean up files
-
-remote_exec host "rm -f $filenames"