This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf] - Do not read past the end of file when dumping SHT_GNU_HASH.
ClosedPublic

Authored by grimar on Jun 3 2020, 8:26 AM.

Details

Summary

We have unobvious issue in the condition that is used to check
that we do not read past the EOF.

The problem is that the result of "GnuHashTable->nbuckets * 4" expression is uint32.
Because of that it was still possible to overflow it and pass the check.

There was no such problem with the "GnuHashTable->maskwords * sizeof(typename ELFT::Off)"
condition, because of sizeof on the right (which gives 64-bits value on x64),
but I've added an explicit conversion to 64-bit value for GnuHashTable->maskwords too.

Diff Detail

Event Timeline

grimar created this revision.Jun 3 2020, 8:26 AM
Herald added a project: Restricted Project. · View Herald Transcript
MaskRay accepted this revision.Jun 3 2020, 12:31 PM

Do not try to read past the end of the file when dumping the the SHT_GNU_HASH.

Do not read past the end of file when dumping SHT_GNU_HASH?

This revision is now accepted and ready to land.Jun 3 2020, 12:31 PM
grimar retitled this revision from [llvm-readelf] - Do not try to read past the end of the file when dumping the the SHT_GNU_HASH. to [llvm-readelf] - Do not read past the end of file when dumping SHT_GNU_HASH..Jun 4 2020, 1:26 AM

Do not try to read past the end of the file when dumping the the SHT_GNU_HASH.

Do not read past the end of file when dumping SHT_GNU_HASH?

Thanks!

jhenderson accepted this revision.Jun 4 2020, 1:41 AM

LGTM too.

This revision was automatically updated to reflect the committed changes.