This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Do not crash on invalid symbol index.
ClosedPublic

Authored by grimar on Sep 28 2016, 8:10 AM.

Details

Summary

Relative to PR30540.

If .symtab has invalid type in elf, no bodies are created and any relocation
that tries to access them will fail.
The same can happen if symbol index is just incorrect.

This was revealed by "id_000005,sig_11,src_000000,op_flip2,pos_420"

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 72828.Sep 28 2016, 8:10 AM
grimar retitled this revision from to [ELF, WIP] - Do not crash on invalid symbol index..
grimar updated this object.
grimar added reviewers: ruiu, rafael, davide.
grimar updated this object.
grimar added subscribers: llvm-commits, grimar, evgeny777.
grimar updated this revision to Diff 73008.Sep 30 2016, 2:04 AM
grimar retitled this revision from [ELF, WIP] - Do not crash on invalid symbol index. to [ELF] - Do not crash on invalid symbol index..
grimar updated this object.
  • Rebased.
  • Run afl-min on testcases (had no any changes in size).
ruiu added inline comments.Sep 30 2016, 8:25 AM
ELF/InputFiles.h
154–155 ↗(On Diff #73008)

In the previous patch, you checked a value in a constructor of a symbol class. Here, you are checking it in InputFile. That seems inconsistent. Probably we should do all error checking in InputFile.cpp?

grimar added inline comments.Sep 30 2016, 8:51 AM
ELF/InputFiles.h
154–155 ↗(On Diff #73008)

In a construnctor of DefinedCommon, right. Because st_value contains alignment if symbol is SHT_COMMON and I tried to isolate check.

We know that symbol is common somewhere in ObjectFile<ELFT>::createSymbolBody() first time I think. Do you think it is better to have check there:

case SHN_COMMON:
  // Here ?
  return elf::Symtab<ELFT>::X
      ->addCommon(Name, Sym->st_size, Sym->st_value, Binding, Sym->st_other,
                  Sym->getType(), this)
      ->body();

I think constructor or SymbolTable::addCommon are more isolated and convenient places for checks.
Do you think we should change D25085 ?

grimar updated this revision to Diff 73257.Oct 3 2016, 3:36 AM
grimar updated this object.
  • Removed excessive test.
rafael accepted this revision.Oct 3 2016, 9:43 AM
rafael edited edge metadata.

LGTM

This revision is now accepted and ready to land.Oct 3 2016, 9:43 AM
ruiu accepted this revision.Oct 3 2016, 9:50 AM
ruiu edited edge metadata.

LGTM

ELF/InputFiles.h
155 ↗(On Diff #73257)

Please include the filename.

This revision was automatically updated to reflect the committed changes.