This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Check eh_frame_hdr overflow with PC offsets instead of PC absolute addresses
ClosedPublic

Authored by MaskRay on Jul 20 2018, 10:09 AM.

Event Timeline

MaskRay created this revision.Jul 20 2018, 10:09 AM
ruiu added inline comments.Jul 20 2018, 10:25 AM
ELF/SyntheticSections.cpp
510–513

I don't think this is a good place to check for this error. I'd move this to EhFrameHeader::writeTo(), so that getFdeData can just return FDE data without doing any extra work, as the name of that function implies.

513

Can't FdeVA overflow?

MaskRay added inline comments.Jul 20 2018, 10:51 AM
ELF/SyntheticSections.cpp
510–513

Then we would not know which object file causes .eh_frame_hdr pcrel overflow. But if you think this information is minor, I can move the check to EhFrameHeader::writeTo()

FdeVA is the address of the .eh_frame FDE entry. I think it is very unlikely to overflow

ruiu added a comment.Jul 20 2018, 10:59 AM

As to FdeVA, I wanted to ask if it could theoretically overflow. Since the new FdeData struct takes 16 bytes anyway, there's no point to keep FdeVA uint32_t instead of uint64_t.

ruiu added a comment.Jul 20 2018, 11:02 AM

Can you investigate how many FdeData are instantiated for common exception-heavy large programs? If it is not that many (so that we don't have to optimize), we could just include Fde->Sec to all FdeData.

ruiu added a comment.Jul 20 2018, 11:22 AM

I read the code again, and I believe the easiest way to fix this without hurting the readability of the code is to move more code from EhFrameHeader::writeTo to EhFrame::getFdeData, so that getFdeData returns a ready-made .eh_frame_hdr table entries, instead of something that needs to be sorted and then be subtracted by some value. You can do that in getFdeData, not after getFdeData.

MaskRay updated this revision to Diff 156567.Jul 20 2018, 12:32 PM

Move sorting logic from EhFrameHeader to EhFrame

ruiu added inline comments.Jul 20 2018, 12:33 PM
ELF/SyntheticSections.h
83–84

Now you can use uint32_t, no?

MaskRay marked 2 inline comments as done.Jul 20 2018, 12:33 PM
MaskRay added inline comments.
ELF/SyntheticSections.cpp
513
uint32_t Pc -> uint64_t PcRel
uint32_t FdeVA -> uint64_t FdeVARel
MaskRay marked 2 inline comments as done.Jul 20 2018, 12:34 PM
MaskRay updated this revision to Diff 156569.Jul 20 2018, 12:40 PM

Use uint32_t for PcRel and FdeVARel

ruiu added inline comments.Jul 20 2018, 12:44 PM
ELF/SyntheticSections.cpp
515

I think you can use isInt<32>(Pc - VA).

521–527

Why did you inline only one and not the two? Maybe you should keep the original code.

MaskRay updated this revision to Diff 156572.Jul 20 2018, 12:51 PM

Use isInt<32> and Less

MaskRay marked 2 inline comments as done.Jul 20 2018, 12:51 PM
ruiu accepted this revision.Jul 20 2018, 12:53 PM

LGTM

Thanks!

This revision is now accepted and ready to land.Jul 20 2018, 12:53 PM
This revision was automatically updated to reflect the committed changes.
test/ELF/Inputs/eh-frame-pcrel-overflow.s