Page MenuHomePhabricator

[COFF] Don't reject executables with data directories pointing outside of provided data
ClosedPublic

Authored by mstorsjo on Jun 8 2022, 2:01 PM.

Details

Summary

Before bb94611d6545c2c5271f5bb01de1aa4228a37250, we didn't check
that the sections in the COFF executable actually contained enough
raw data, when looking up what section contains tables pointed to
by the data directories.

That commit added checking, to avoid setting a pointer that points
out of bounds - by rejecting such executables.

It turns out that some binaries (e.g.g a "helper.exe" provided by
NSIS) contains a base relocation table data directory that points
into the wrong section. It points inside the virtual address space
allocated for that section, but the section contains much less raw
data, and the table points outside of the provided raw data.

No longer reject such binaries (to let tools operate on them and
inspect them), but don't set the table pointers (so that when
printing e.g. base relocations, we don't print anything).

This should fix the regression pointed out in
https://reviews.llvm.org/D126898#3565834.

Diff Detail

Event Timeline

mstorsjo created this revision.Jun 8 2022, 2:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2022, 2:01 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
mstorsjo requested review of this revision.Jun 8 2022, 2:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2022, 2:01 PM

I agree with this change like I said in the linked review thread.

@rnk - What do you think about this? See the later discussion in D126898.

The executable that triggered this was deemed to be misbuilt, but we still have the case that our tools now refuse to print/dump binaries that it tolerated before.

rnk accepted this revision.Jun 13 2022, 2:30 PM

lgtm

This revision is now accepted and ready to land.Jun 13 2022, 2:30 PM
This revision was landed with ongoing or failed builds.Jun 15 2022, 6:52 AM
This revision was automatically updated to reflect the committed changes.