]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Don't trust e_shentsize in dwfl_segment_report_module
authorMark Wielaard <mark@klomp.org>
Wed, 8 Dec 2021 21:20:17 +0000 (22:20 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 9 Dec 2021 18:34:19 +0000 (19:34 +0100)
When calulating the possible section header table end us the actual size
of the section headers (sizeof (Elf32_Shdr) or sizeof (Elf64_Shdr)),
not the ELF header e_shentsize value, which can be corrupted. This
prevents a posssible overflow, but we check the shdrs_end is sane
later anyway.

https://sourceware.org/bugzilla/show_bug.cgi?id=28659

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/dwfl_segment_report_module.c

index d875eabd21e01ef7980e3e081883899ddc5b6e40..76e0899e9985a2d15885c92033c255b4a30d365d 100644 (file)
@@ -1,3 +1,8 @@
+2021-12-08  Mark Wielaard  <mark@klomp.org>
+
+       * dwfl_segment_report_module.c (dwfl_segment_report_module): Don't
+       trust e_shentsize.
+
 2021-12-08  Mark Wielaard  <mark@klomp.org>
 
        * link_map.c (dwfl_link_map_report): Make sure phent != 0.
index f6a1799ef91f5d4d67dd76e90ed379be6328c9fe..be0aff76a92e445ef0920aedd063b68f3eb38592 100644 (file)
@@ -383,7 +383,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
         zero sh_size field. We ignore this here because getting shdrs
         is just a nice bonus (see below in the type == PT_LOAD case
         where we trim the last segment).  */
-      shdrs_end = ehdr.e32.e_shoff + ehdr.e32.e_shnum * ehdr.e32.e_shentsize;
+      shdrs_end = ehdr.e32.e_shoff + ehdr.e32.e_shnum * sizeof (Elf32_Shdr);
       break;
 
     case ELFCLASS64:
@@ -397,7 +397,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
       if (phentsize != sizeof (Elf64_Phdr))
        goto out;
       /* See the NOTE above for shdrs_end and ehdr.e32.e_shnum.  */
-      shdrs_end = ehdr.e64.e_shoff + ehdr.e64.e_shnum * ehdr.e64.e_shentsize;
+      shdrs_end = ehdr.e64.e_shoff + ehdr.e64.e_shnum * sizeof (Elf64_Shdr);
       break;
 
     default: