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

            Bug ID: 35072
           Summary: elf_update() crashes (memcpy from NULL) when malformed
                    e_shoff/e_shnum leaves section headers unloaded
           Product: elfutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libelf
          Assignee: unassigned at sourceware dot org
          Reporter: dl at ieee dot org
                CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

Seen on git master commit 11d2e85059645688ca2942e2943dab3a02fce1df, checked out
2026-11-18.

elf_begin() accepts an ELF64 file when e_shoff and e_shnum point at bytes that
cannot be loaded as a section header table. The section-header pointers stay
NULL. elf_update(elf, ELF_C_WRITE) then copies from that NULL pointer.

Copy /bin/true to a temp file. Write e_shoff = 0x40 at file offset 0x28 and
e_shnum = 1 at offset 0x3c. Open it with ELF_C_RDWR and call elf_update(elf,
ELF_C_WRITE).

With native endianness, ASan reports a SEGV, a read at 0x0:

  #2 __elf64_updatefile  libelf/elf32_updatefile.c:849  (memcpy)
  #4 elf_update          libelf/elf_update.c:231

If those two fields are byte-swapped, the fault is in ElfNN_cvt_Shdr instead.
The shdr pointer is NULL in both cases.

Bug 33967, commit e91caaa8, loads section zero in elf32_updatenull.c for the
65280-section case. It does not change this copy. Bug 34468, commit 9a6307a5,
changes the gap fill.

elf_update() should return an error when the section headers were not loaded.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to