Bug 277861 - corrupt ELF file can crash llvm-objdump in printSymbolVersionDefinition()
Summary: corrupt ELF file can crash llvm-objdump in printSymbolVersionDefinition()
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-21 10:13 UTC by Robert Morris
Modified: 2024-03-26 18:01 UTC (History)
1 user (show)

See Also:


Attachments
broken ELF file that crashes llvm-objdump in printSymbolVersionDefinition() (5.16 KB, application/x-msdownload)
2024-03-21 10:13 UTC, Robert Morris
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Morris 2024-03-21 10:13:04 UTC
Created attachment 249368 [details]
broken ELF file that crashes llvm-objdump in printSymbolVersionDefinition()

This line in printSymbolVersionDefinition() in
llvm-project/llvm/tools/llvm-objdump/ELFDump.cpp forms a pointer using
a value pulled from the ELF file (vd_aux) without a sanity check:

    const uint8_t *BufAux = Buf + Verdef->vd_aux;

It may be that the subsequent uses of vda_next and vd_next have a
similar problem.

I've attached an ELF file that crashes objdump due to a huge vd_aux:

# freebsd-version
15.0-CURRENT
# objdump --version
LLVM (http://llvm.org/):
  LLVM version 17.0.6
  Optimized build with assertions.
...
# objdump -p objdump2a.exe

objdump2a.exe:  file format elf32-lanai

Program Header:
objdump: warning: 'objdump2a.exe': section [index 7] has invalid sh_entsize: expected 8, but got 5

Version definitions:
1 0x00 0x7650bc00 PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace.
Stack dump:
0.      Program arguments: objdump -p objdump2a.exe
 #0 0x0000000001230c41 PrintStackTrace /usr/src/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:602:13
 #1 0x000000000122f0b5 RunSignalHandlers /usr/src/contrib/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 #2 0x0000000001231365 SignalHandler /usr/src/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:0:3
 #3 0x00000008255ae5ff handle_signal /usr/src/lib/libthr/thread/thr_sig.c:0:3
 #4 0x00000008255adbbb thr_sighandler /usr/src/lib/libthr/thread/thr_sig.c:244:1
 #5 0x00000008223cd2d3 ([vdso]+0x2d3)
 #6 0x0000000000de60d7 read<unsigned int, 1UL> /usr/src/contrib/llvm-project/llvm/include/llvm/Support/Endian.h:66:3
 #7 0x0000000000de60d7 read<unsigned int, (llvm::support::endianness)1, 1UL> /usr/src/contrib/llvm-project/llvm/include/llvm/Support/Endian.h:77:10
 #8 0x0000000000de60d7 operator unsigned int /usr/src/contrib/llvm-project/llvm/include/llvm/Support/Endian.h:216:12
 #9 0x0000000000de60d7 printSymbolVersionDefinition<llvm::object::ELFType<(llvm::support::endianness)1, false> > /usr/src/contrib/llvm-project/llvm/tools/llvm-objdump/ELFDump.cpp:398:45
#10 0x0000000000de60d7 printSymbolVersion /usr/src/contrib/llvm-project/llvm/tools/llvm-objdump/ELFDump.cpp:425:7
#11 0x0000000000de60d7 printPrivateHeaders /usr/src/contrib/llvm-project/llvm/tools/llvm-objdump/ELFDump.cpp:432:3
#12 0x0000000000e6a13c dumpObject /usr/src/contrib/llvm-project/llvm/tools/llvm-objdump/llvm-objdump.cpp:2815:7
#13 0x0000000000e654b0 dumpInput /usr/src/contrib/llvm-project/llvm/tools/llvm-objdump/llvm-objdump.cpp:0:5
#14 0x0000000000e654b0 for_each<std::__1::__wrap_iter<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > *>, void (*)(llvm::StringRef)> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/c++/v1/__algorithm/for_each.h:26:5
#15 0x0000000000e654b0 for_each<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > &, void (*)(llvm::StringRef)> /usr/src/contrib/llvm-project/llvm/include/llvm/ADT/STLExtras.h:1731:10
#16 0x0000000000e654b0 main /usr/src/contrib/llvm-project/llvm/tools/llvm-objdump/llvm-objdump.cpp:3248:3
#17 0x0000000828d4d0aa __libc_start1 /usr/src/lib/libc/csu/libc_start1.c:157:2
Segmentation fault (core dumped)
Comment 1 Ed Maste freebsd_committer freebsd_triage 2024-03-26 00:54:29 UTC
reported upstream at https://github.com/llvm/llvm-project/issues/86611
Comment 2 Ed Maste freebsd_committer freebsd_triage 2024-03-26 18:01:06 UTC
patch has been proposed in the upstream report