[PATCH] D25368: [Object/ELF] - Do not crash on invalid Header->e_shoff value.
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 7 07:05:32 PDT 2016
I don't think we can be that strict with alignment, and the reason is
gnu archives. They can put a member in a position that is only 2 bytes
aligned.
Since that changes the alignment of base(), maybe what you can do is
check the alignment of Header->e_shoff directly?
Cheers,
Rafael
On 7 October 2016 at 09:56, George Rimar <grimar at accesssoftek.com> wrote:
> grimar created this revision.
> grimar added reviewers: ruiu, rafael, davide.
> grimar added subscribers: llvm-commits, grimar, evgeny777.
>
> sections_begin() may return unalignment pointer when Header->e_shoff isinvalid.
> That may result in a crash in clients, for example we have one in LLD:
>
> assert((PtrWord & ~PointerBitMask) == 0 &&
> "Pointer is not sufficiently aligned");
>
> fails when trying to push_back Elf_Shdr* (unaligned) into TinyPtrVector.
>
> Patch forces address to be aligned.
>
>
> https://reviews.llvm.org/D25368
>
> 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 address alignment of section headers
> Index: include/llvm/Object/ELF.h
> ===================================================================
> --- include/llvm/Object/ELF.h
> +++ include/llvm/Object/ELF.h
> @@ -367,7 +367,10 @@
> if (Header->e_shentsize != sizeof(Elf_Shdr))
> report_fatal_error(
> "Invalid section header entry size (e_shentsize) in ELF header");
> - return reinterpret_cast<const Elf_Shdr *>(base() + Header->e_shoff);
> + const uint8_t *Addr = base() + Header->e_shoff;
> + if ((uintptr_t)(Addr) & (AlignOf<typename ELFT::uint>::Alignment - 1))
> + report_fatal_error("Invalid address alignment of section headers");
> + return reinterpret_cast<const Elf_Shdr *>(Addr);
> }
>
> template <class ELFT>
>
>
More information about the llvm-commits
mailing list