This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho][nfc]Add bounds check before attempting to dereferencing iterators.
ClosedPublic

Authored by oontvoo on Aug 3 2023, 1:15 PM.

Details

Summary

Runnign some tests with asan built of LLD would throw errors similar to the following:

AddressSanitizer:DEADLYSIGNAL

#0 0x55d8e6da5df7 in operator() /mnt/ssd/repo/lld/llvm-project/lld/MachO/Arch/ARM64.cpp:612
#1 0x55d8e6daa514 in operator() /mnt/ssd/repo/lld/llvm-project/lld/MachO/Arch/ARM64.cpp:650

Diff Detail

Event Timeline

oontvoo created this revision.Aug 3 2023, 1:15 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 3 2023, 1:15 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
oontvoo requested review of this revision.Aug 3 2023, 1:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 1:15 PM
MaskRay added inline comments.Aug 4 2023, 8:57 PM
lld/MachO/Arch/ARM64.cpp
608

secIt >= obj.sections.end() should be impossible.

It's better to check whether the upper_bound result is out-of-bounds before invoking std::prev.

oontvoo updated this revision to Diff 548665.Aug 9 2023, 10:16 AM
oontvoo marked an inline comment as done.

updated diff

lld/MachO/Arch/ARM64.cpp
608

turnt out we can simply check whether sections or subsections are empty to avoid getting an out-of-bound iter.

@MaskRay Hi, friendly ping? Thanks!

MaskRay accepted this revision.Aug 10 2023, 1:00 PM

Runnign some tests with asan built of LLD would throw errors similar to the following:

Running. Can you name the exact test names?

This revision is now accepted and ready to land.Aug 10 2023, 1:00 PM
oontvoo added a comment.EditedAug 10 2023, 1:03 PM

Runnign some tests with asan built of LLD would throw errors similar to the following:

Running. Can you name the exact test names?

It's an internal test case - dropped you a link to it in chat.

P.S: can try making a smaller repro to attach to this.