From 0a3a5ea5a61b8887aa3b78ca7bc2908a0dc8abc1 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Mar 31 2021 21:49:14 +0000 Subject: Backport "Save/restore file offset while reading notes in core file" (Keith Seitz, RHBZ 1931344) Resolves: RHBZ 1931344 --- diff --git a/_gdb.spec.Patch.include b/_gdb.spec.Patch.include index f0b8ff4..30023ab 100644 --- a/_gdb.spec.Patch.include +++ b/_gdb.spec.Patch.include @@ -424,3 +424,7 @@ Patch104: testing-custom-inputrc.patch # (Tom de Vries) Patch105: process_psymtab_comp_unit-type-unit.patch +# Backport "Save/restore file offset while reading notes in core file" +# (Keith Seitz, RHBZ 1931344) +Patch106: gdb-rhbz1931344-bfd_seek-elf_read_notes.patch + diff --git a/_gdb.spec.patch.include b/_gdb.spec.patch.include index df14ff4..1b966ef 100644 --- a/_gdb.spec.patch.include +++ b/_gdb.spec.patch.include @@ -103,3 +103,4 @@ %patch103 -p1 %patch104 -p1 %patch105 -p1 +%patch106 -p1 diff --git a/_patch_order b/_patch_order index b4d313e..85a4a81 100644 --- a/_patch_order +++ b/_patch_order @@ -103,3 +103,4 @@ gdb-rhbz1909902-frame_id_p-assert-2.patch gdb-rhbz1941080-fix-gdbserver-hang.patch testing-custom-inputrc.patch process_psymtab_comp_unit-type-unit.patch +gdb-rhbz1931344-bfd_seek-elf_read_notes.patch diff --git a/gdb-rhbz1931344-bfd_seek-elf_read_notes.patch b/gdb-rhbz1931344-bfd_seek-elf_read_notes.patch new file mode 100644 index 0000000..e212dc6 --- /dev/null +++ b/gdb-rhbz1931344-bfd_seek-elf_read_notes.patch @@ -0,0 +1,87 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: Keith Seitz +Date: Thu, 25 Mar 2021 10:31:48 -0700 +Subject: gdb-rhbz1931344-bfd_seek-elf_read_notes.patch + +;; Backport "Save/restore file offset while reading notes in core file" +;; (Keith Seitz, RHBZ 1931344) + +A recent bug (RH BZ 1931344) has exposed a bug in the core file +build-ID support that I introduced a while ago. It is pretty +easy to demonstate the problem following a simplified procedure +outlined in that bug: + +[shell1] +shell1$ /usr/libexec/qemu-kvm + +[shell2] +shell2$ pkill -SEGV -x qemu-kvm + +[shell1] +Segmentation fault (core dumped) + +Load this core file into GDB without specifying an executable +(an unfortunate Fedora/RHEL-ism), and GDB will inform the user +to install debuginfo for the "missing" executable: + +$ gdb -nx -q core.12345 +... +Missing separate debuginfo for the main executable file +Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/e2/e9c66d3117fb2bbb5b2be122f04f2664e5df54 +Core was generated by `/usr/libexec/qemu-kvm'. +Program terminated with signal SIGSEGV, Segmentation fault. +... + +The suggested build-ID is actaully for gmp not qemu-kvm. The problem +lies in _bfd_elf_core_find_build_id, where we loop over program headers +looking for note segments: + + /* Read in program headers and parse notes. */ + for (i = 0; i < i_ehdr.e_phnum; ++i, ++i_phdr) + { + Elf_External_Phdr x_phdr; + + if (bfd_bread (&x_phdr, sizeof (x_phdr), abfd) != sizeof (x_phdr)) + goto fail; + elf_swap_phdr_in (abfd, &x_phdr, i_phdr); + + if (i_phdr->p_type == PT_NOTE && i_phdr->p_filesz > 0) + { + elf_read_notes (abfd, offset + i_phdr->p_offset, + i_phdr->p_filesz, i_phdr->p_align); + + if (abfd->build_id != NULL) + return TRUE; + } + +elf_read_notes uses bfd_seek to forward the stream to the location of +the note segment. When control returns to _bfd_elf_core_fild_build_id, +the stream is no longer in the location looking at program headers, and +all subsequent reads will read from the wrong file offset. + +To fix this, this patch marks the stream location and ensures +that it is restored after elf_read_notes is called. + +bfd/ChangeLog +2021-03-26 Keith Seitz + + * elfcore.h (_bfd_elf_core_find_build_id): Seek file + offset of program headers after calling elf_read_notes. + +diff --git a/bfd/elfcore.h b/bfd/elfcore.h +--- a/bfd/elfcore.h ++++ b/bfd/elfcore.h +@@ -410,6 +410,13 @@ NAME(_bfd_elf, core_find_build_id) + { + elf_read_notes (abfd, offset + i_phdr->p_offset, + i_phdr->p_filesz, i_phdr->p_align); ++ ++ /* Make sure ABFD returns to processing the program headers. */ ++ if (bfd_seek (abfd, (file_ptr) (offset + i_ehdr.e_phoff ++ + (i + 1) * sizeof (x_phdr)), ++ SEEK_SET) != 0) ++ goto fail; ++ + if (abfd->build_id != NULL) + return TRUE; + } diff --git a/gdb.spec b/gdb.spec index 37e5670..088f650 100644 --- a/gdb.spec +++ b/gdb.spec @@ -37,7 +37,7 @@ Version: 10.1 # The release always contains a leading reserved number, start it at 1. # `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing. -Release: 17%{?dist} +Release: 18%{?dist} License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and LGPLv3+ and BSD and Public Domain and GFDL # Do not provide URL for snapshots as the file lasts there only for 2 days. @@ -1190,7 +1190,11 @@ fi %endif %changelog -* Wed Mar 31 2021 Jonathan Wakely +* Wed Mar 31 2021 Keith Seitz - 10.1-18 +- Backport "Save/restore file offset while reading notes in core file" + (Keith Seitz, RHBZ 1931344) + +* Wed Mar 31 2021 Jonathan Wakely - 10.1-17 - Rebuilt for removed libstdc++ symbols (#1937698) * Tue Mar 23 2021 Kevin Buettner