[PATCH] D25462: [Object/ELF] - Check Header->e_shoff value earlier and do not crash.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 11 03:06:19 PDT 2016
grimar created this revision.
grimar added reviewers: rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
I had to revert https://reviews.llvm.org/D25368 (r283858, r283740) because it was the reason of UBSan failture:
(http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/17075)
-
Exit Code: 1
Command Output (stderr):
------------------------
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/test/Object/invalid.test:70:32: error: expected string not found in input
INVALID-SEC-ADDRESS-ALIGNMENT: Invalid address alignment of section headers
^
<stdin>:1:1: note: scanning from here
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Object/ELF.h:412:7: runtime error: upcast of misaligned address 0x000002d8b899 for type 'llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<llvm::support::endianness::little, true> >', which requires 2 byte alignment
^
<stdin>:1:125: note: possible intended match here
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Object/ELF.h:412:7: runtime error: upcast of misaligned address 0x000002d8b899 for type 'llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<llvm::support::endianness::little, true> >', which requires 2 byte alignment
Problem is seems to be that on the moment of following call, Section pointer is unaligned:
ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const
Patch moves the alignment check before such call to fix the issue.
https://reviews.llvm.org/D25462
Files:
include/llvm/Object/ELF.h
test/Object/Inputs/invalid-sections-address-alignment.x86-64
test/Object/invalid.test
Index: test/Object/invalid.test
===================================================================
--- test/Object/invalid.test
+++ test/Object/invalid.test
@@ -64,3 +64,7 @@
RUN: not llvm-readobj -r %p/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s
INVALID-RELOC-SH-OFFSET: Invalid data was encountered while parsing the file
+
+RUN: not llvm-readobj -t %p/Inputs/invalid-sections-address-alignment.x86-64 2>&1 | \
+RUN: FileCheck --check-prefix=INVALID-SEC-ADDRESS-ALIGNMENT %s
+INVALID-SEC-ADDRESS-ALIGNMENT: Invalid data was encountered while parsing the file
Index: include/llvm/Object/ELF.h
===================================================================
--- include/llvm/Object/ELF.h
+++ include/llvm/Object/ELF.h
@@ -330,6 +330,12 @@
return;
}
+ if (SectionTableOffset & (AlignOf<Elf_Shdr>::Alignment - 1)) {
+ // Invalid address alignment of section headers
+ EC = object_error::parse_failed;
+ return;
+ }
+
// The getNumSections() call below depends on SectionHeaderTable being set.
SectionHeaderTable =
reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25462.74205.patch
Type: text/x-patch
Size: 1213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161011/aa11892d/attachment.bin>
More information about the llvm-commits
mailing list