This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj/elf] - Fix a crash when dumping a dynamic relocation that refer to a symbol past the EOF.
ClosedPublic

Authored by grimar on Oct 27 2020, 2:25 AM.

Details

Summary

There is a possible scenario when we crash when dumping dynamic relocations.
For that we should have no section headers (to take the number of synamic symbols from)
and a dynamic relocation that refers to a symbol with an index that is too large to be in a file.

The patch fixes it.

Diff Detail

Event Timeline

grimar created this revision.Oct 27 2020, 2:25 AM
Herald added a project: Restricted Project. · View Herald Transcript
grimar requested review of this revision.Oct 27 2020, 2:25 AM
jhenderson added inline comments.Oct 27 2020, 3:26 AM
llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
384–385

These values are presumably tied to the size of data in other implicit sections, right? Could we arrange for those sections to appear before .dynsym, as well as the .rela.dyn section? That way, the .dynsym will actually appear at the end of the file, and it would be easier to see that the symbol indexes are what you say they are.

It's probably also worth expanding on what is meant by "valid" here, since the .dynsym appears to be essentially empty (and therefore any indexes into it could be viewed as invalid).

grimar updated this revision to Diff 300958.Oct 27 2020, 5:15 AM
grimar marked an inline comment as done.
  • Addressed review comments.
  • Now depends on D90224.
jhenderson added inline comments.Oct 27 2020, 9:13 AM
llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
380

I'm a little confused - why isn't this symbol something like 0x1 or 0x2? If the .dynsym is the very last thing in the output, then the at-EOF index should be the number of dynamic symbols.

grimar marked an inline comment as done.Oct 28 2020, 1:21 AM
grimar added inline comments.
llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
380

I've investigated it and found multiple reasons:

  1. There is a .dynstr section, which we also write after.
  2. Also we write the content of .strtab and .shstrtab implicit sections (both are empty and has size == 1). Here I think that the fact we still write the content of .shstrtab with NoHeaders: true is a bug. We don't add section names to it already, but we should just drop it from the output.
  3. We still: a) Align the start of the section header table, what affects the output size. (BUG) b) We still write it. (BUG)

I am going to fix it. Though it will be a separate independent set of changes.

384–385

Done.

jhenderson added inline comments.Oct 28 2020, 2:29 AM
llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
380

Sounds reasonable, thanks!

grimar updated this revision to Diff 301552.EditedOct 29 2020, 3:25 AM
grimar marked 2 inline comments as done.
  • Rebased after landing D90295.
  • Updated the test case.
llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
380

I've updated the test.

jhenderson accepted this revision.Oct 29 2020, 3:54 AM

Great, LGTM!

This revision is now accepted and ready to land.Oct 29 2020, 3:54 AM