-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
llvm-objdump: printDynamicSection() out-of-bounds read #86612
Comments
@llvm/issue-subscribers-tools-llvm-objdump Author: Ed Maste (emaste)
Reported against FreeBSD at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277885, with attached ELF reproducer.
|
Possible duplicate of #85568? Could you check against HEAD, please? |
Think this should work: --- a/llvm/tools/llvm-objdump/ELFDump.cpp
+++ b/llvm/tools/llvm-objdump/ELFDump.cpp
@@ -233,7 +233,13 @@ template <class ELFT> void ELFDumper<ELFT>::printDynamicSection() {
Expected<StringRef> StrTabOrErr = getDynamicStrTab(Elf);
if (StrTabOrErr) {
const char *Data = StrTabOrErr.get().data();
- outs() << (Data + Dyn.d_un.d_val) << "\n";
+ const auto SecSize =
+ unwrapOrError(Elf.getSection(ELF::SHT_DYNAMIC), Obj.getFileName())
+ ->sh_size;
+ if (Dyn.d_un.d_val > SecSize)
+ reportWarning("string table offset out-of-bound", Obj.getFileName());
+ else
+ outs() << Data + Dyn.d_un.d_val << "\n";
continue;
}
reportWarning(toString(StrTabOrErr.takeError()), Obj.getFileName()); |
These were submitted as separate FreeBSD issues, and indeed it is still reproducible at bf4fc00
and no crash with @antoniofrighetto's patch:
|
When reading the dynamic string table, llvm-objdump used to crash if the ELF was malformed, due to an erroneous consumption of error status. Instead, propogate the error status to the caller, fixing the crash, and printing a warning. Fixes llvm#86612.
llvm/tools/llvm-objdump/ELFDump.cpp:70 @artagnon We need a minimal reproduce file. obj2yaml gives a start, but you need to scrub unneeded parts from the YAML file. A test filename like |
Reported against FreeBSD at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277885, with attached ELF reproducer.
The text was updated successfully, but these errors were encountered: