You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When ELF has a malformed .dynamic section, running ./src/patchelf --shrink-rpath --allowed-rpath-prefixes /usr/lib:/foo/lib malformed_elf will cause patchelf crash.
$ ./src/patchelf --shrink-rpath --allowed-rpath-prefixes /usr/lib:/foo/lib malformed_elf
AddressSanitizer:DEADLYSIGNAL
=================================================================
==9147==ERROR: AddressSanitizer: SEGV on unknown address 0x624044334509 (pc 0x7fecfad6c26d bp 0x7ffd36d52300 sp 0x7ffd36d51aa8 T0)
==9147==The signal is caused by a READ memory access.
#0 0x7fecfad6c26d in __strlen_avx2 (/lib64/libc.so.6+0x16c26d) (BuildId: bbeee08e5f56966e641c4f3ba4ea1da9d730d0ab)#1 0x7fecfb46935c (/lib64/libasan.so.8+0x6935c) (BuildId: 3e1694ad218c99a8b1b69231666a27df63cf19d0)#2 0x410946 in std::char_traits<char>::length(char const*) /usr/include/c++/13/bits/char_traits.h:409#3 0x4143db in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<std::allocator<char> >(char const*, std::allocator<char> const&) /usr/include/c++/13/bits/basic_string.h:638#4 0x41f746 in ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, unsigned int, unsigned int, Elf32_Dyn, Elf32_Sym, unsigned short, Elf32_Verdef, Elf32_Verdaux, Elf32_Verneed, Elf32_Vernaux, Elf32_Rel, Elf32_Rela, 32u>::modifyRPath(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, unsigned int, unsigned int, Elf32_Dyn, Elf32_Sym, unsigned short, Elf32_Verdef, Elf32_Verdaux, Elf32_Verneed, Elf32_Vernaux, Elf32_Rel, Elf32_Rela, 32u>::RPathOp, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) /home/chenx/devp/repo/patchelf/src/patchelf.cc:1586#5 0x40d27f in patchElf2<ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, unsigned int, unsigned int, Elf32_Dyn, Elf32_Sym, short unsigned int, Elf32_Verdef, Elf32_Verdaux, Elf32_Verneed, Elf32_Vernaux, Elf32_Rel, Elf32_Rela, 32> > /home/chenx/devp/repo/patchelf/src/patchelf.cc:2420#6 0x4087d7 in patchElf /home/repo/patchelf/src/patchelf.cc:2463#7 0x40b96e in mainWrapped /home/repo/patchelf/src/patchelf.cc:2685#8 0x40c523 in main /home/repo/patchelf/src/patchelf.cc:2693#9 0x7fecfac281af in __libc_start_call_main (/lib64/libc.so.6+0x281af) (BuildId: bbeee08e5f56966e641c4f3ba4ea1da9d730d0ab)#10 0x7fecfac28278 in __libc_start_main@@GLIBC_2.34 (/lib64/libc.so.6+0x28278) (BuildId: bbeee08e5f56966e641c4f3ba4ea1da9d730d0ab)#11 0x4059c4 in _start ../sysdeps/x86_64/start.S:115
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib64/libc.so.6+0x16c26d) (BuildId: bbeee08e5f56966e641c4f3ba4ea1da9d730d0ab) in __strlen_avx2
==9147==ABORTING
When the tag of the element in .dynamic section is 0x1 and has a huge value (in the following example, 0x44332211), patchelf will read string from strTab + rdi(dyn->d_un.d_val), which will cause a OOB read.
Describe the bug
When ELF has a malformed .dynamic section, running
./src/patchelf --shrink-rpath --allowed-rpath-prefixes /usr/lib:/foo/lib malformed_elf
will cause patchelf crash.Steps To Reproduce
Expected behavior
patchelf not crash
patchelf --version
outputpatchelf 0.18.0
Additional context
ELF file: malformed_elf.zip
ASAN output:
When the tag of the element in .dynamic section is 0x1 and has a huge value (in the following example, 0x44332211), patchelf will read string from
strTab + rdi(dyn->d_un.d_val)
, which will cause a OOB read.I think add a check for
strTab + rdi(dyn->d_un.d_val)
before read string from memory will solve the problem.The text was updated successfully, but these errors were encountered: