This is an archive of the discontinued LLVM Phabricator instance.

[Object/ELF] - Do not crash on invalid Header->e_shoff value.
ClosedPublic

Authored by grimar on Oct 7 2016, 6:56 AM.

Details

Summary

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.

Diff Detail

Event Timeline

grimar updated this revision to Diff 73927.Oct 7 2016, 6:56 AM
grimar retitled this revision from to [Object/ELF] - Do not crash on invalid Header->e_shoff value..
grimar updated this object.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
grimar abandoned this revision.Oct 7 2016, 7:13 AM

gnu archives seems does not like such innovations. I`ll reimplement this to do checks from lld side.

grimar reclaimed this revision.Oct 7 2016, 8:38 AM

Will update in a minute.

grimar updated this revision to Diff 73937.Oct 7 2016, 8:43 AM
  • As suggested by Rafael, check only alignment of Header->e_shoff.
rafael accepted this revision.Oct 7 2016, 10:49 AM
rafael edited edge metadata.

LGTM with a nit.

include/llvm/Object/ELF.h
370

Can you use Elf_Shdr instead of uint in AlignOf? After all that is what we return a pointer to.

This revision is now accepted and ready to land.Oct 7 2016, 10:49 AM
grimar closed this revision.Oct 10 2016, 4:01 AM

r283740