This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Alternative fix to prevent possible crash on large output.
AbandonedPublic

Authored by grimar on Oct 11 2016, 4:30 AM.

Details

Summary

This is alternative solution for D25279.

Initial problem was that because of overflow in calculations wierd thinks could happen.
Most heavy is a crash in writeTo because of overflow in FileSize calculation.

This patch does not introduce new class and uses 2 check-methods.

Diff Detail

Event Timeline

grimar updated this revision to Diff 74233.Oct 11 2016, 4:30 AM
grimar retitled this revision from to [ELF] - Alternative fix to prevent possible crash on large output..
grimar updated this object.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
ruiu edited edge metadata.Oct 11 2016, 11:16 AM

The new functions seem too complicated. There are a lot of ways to crash the linker by giving incorrect input. We deliberately ignore some cases such as relocations having too large values. Why do you want to fix this specifically? This is not even the only place where overflow can happen. I think we should leave it as is.

ruiu added a comment.Oct 11 2016, 11:46 AM

Here's my proposal to detect offset overflow without checking integer overflow everywhere.

  • Use uint64_t for Off instead of uintX_t everywhere
  • If the final Off is greater than sizeof(uintX_t), reject it. This check should suffice for detecting any overflow on 32-bit targets.
  • Reject insanely large sections and alignments such as >2^40 when reading a file. This suffices to prevent any overflow on 64-bit targets.

That being said, I doubt this is a top priority thing to do.

In D25467#567497, @ruiu wrote:

The new functions seem too complicated. There are a lot of ways to crash the linker by giving incorrect input. We deliberately ignore some cases such as relocations having too large values. Why do you want to fix this specifically? This is not even the only place where overflow can happen. I think we should leave it as is.

I am not fixing this specifically, I am trying to fix every crash or hang I see during AFL runs. There is no high or low priority for me, each crash is a problem I think.

grimar abandoned this revision.Dec 2 2016, 11:47 PM

Depricated.