This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Do not crash on absolute local symbol starting from ".L".
ClosedPublic

Authored by grimar on Oct 7 2016, 5:28 AM.

Details

Summary

I had a bunch of crashes during last AFL runs.

Problem is next. Object contains local symbol of type STT_NOTYPE
(it just should not be STT_FILE or STT_SECTION to crash).

Has section index greater than SHN_LORESERVE, so next code returns 0
template <class ELFT>

uint32_t ELFFileBase<ELFT>::getSectionIndex(const Elf_Sym &Sym) const {
...
  if (I >= ELF::SHN_LORESERVE)
    return 0;
  return I;
}

Then DefinedRegular is created:

  if (Sym->st_shndx == SHN_UNDEF)
    return new (this->Alloc)
        Undefined(Sym->st_name, Sym->st_other, Sym->getType(), this);
  return new (this->Alloc) DefinedRegular<ELFT>(*Sym, Sec);
}

And finally code is crashes in shouldKeepInSymtab() because Sec is null there.

As was noticed by Rafael, the same happens for absolute
local symbols with name staring from ".L".

Patch fixes that.

Diff Detail

Event Timeline

grimar updated this revision to Diff 73920.Oct 7 2016, 5:28 AM
grimar retitled this revision from to [ELF] - Do not crash on invalid local symbol..
grimar updated this object.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
grimar updated this revision to Diff 73933.Oct 7 2016, 8:12 AM
grimar retitled this revision from [ELF] - Do not crash on invalid local symbol. to [ELF] - Do not crash on absolute local symbol starting from ".L"..
grimar updated this object.
  • Updated.
rafael accepted this revision.Oct 7 2016, 10:38 AM
rafael edited edge metadata.

LGTM with a nit.

ELF/Writer.cpp
311

You don't need F.

This revision is now accepted and ready to land.Oct 7 2016, 10:38 AM
ruiu added inline comments.Oct 7 2016, 12:47 PM
ELF/Writer.cpp
339

Add () around &. This is probably better.

return !Sec || !(Sec->getSectionHdr()->sh_flags & SHF_MERGE);
grimar closed this revision.Oct 10 2016, 4:08 AM

Revision: 283731