This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] - Don't crash when relocation table goes past the EOF.
ClosedPublic

Authored by grimar on Nov 19 2020, 5:18 AM.

Details

Summary

It is possible to trigger reading past the EOF by breaking fields like
DT_PLTRELSZ, DT_RELSZ or DT_RELASZ

This patch adds a validation in DynRegionInfo helper class.

Diff Detail

Event Timeline

grimar created this revision.Nov 19 2020, 5:18 AM
Herald added a project: Restricted Project. · View Herald Transcript
grimar requested review of this revision.Nov 19 2020, 5:18 AM
grimar retitled this revision from [llvm-readobj] - Don't crash when relocation table size is past the EOF. to [llvm-readobj] - Don't crash when relocation table goes past the EOF..

Would adding --implicit-check-not=warning: to the test cases be useful?

llvm/tools/llvm-readobj/ELFDumper.cpp
128–131

Can't you change users of this overload in the same way, so that there's always an object?

165

I think this punctuation is slightly more correct English.

grimar updated this revision to Diff 306639.Nov 20 2020, 3:03 AM
grimar marked 2 inline comments as done.
  • Addressed review comments.

Would adding --implicit-check-not=warning: to the test cases be useful?

Perhaps we could can add it to each test where we print warnings jsut in case.
I've added it.

llvm/tools/llvm-readobj/ELFDumper.cpp
128–131

I was not sure how much it is useful (because this constructor is only used in createDRI, which do Offset/Size check before creating the DynRegionInfo). But I've tried and seems it allows to simplify the code a bit.

Done.

jhenderson accepted this revision.Nov 20 2020, 3:34 AM

LGTM, with or without the suggested changes.

llvm/tools/llvm-readobj/ELFDumper.cpp
141

Maybe make this a reference? It can't change after all, and is always valid.

160

Here and below, maybe reportUniqueWarning?

This revision is now accepted and ready to land.Nov 20 2020, 3:34 AM
grimar marked an inline comment as done.Nov 20 2020, 3:39 AM
grimar added inline comments.
llvm/tools/llvm-readobj/ELFDumper.cpp
141

Would be good, but I can't, because the code stops to compile.
Compiler removes copy assignment operator when a class has a reference member:

function was implicitly deleted because '`anonymous-namespace'::DynRegionInfo' has a data member '`anonymous-namespace'::DynRegionInfo::Owner' of reference type

It is needed in one place where DynRegionInfo os used as Optional<>.