This is an archive of the discontinued LLVM Phabricator instance.

[lsan][fuchsia] Add extra check for allocator cache to avoid overflow
ClosedPublic

Authored by leonardchan on Sep 14 2023, 3:19 PM.

Details

Summary

Prior to this, we would check if the end of the allocator cache was located before the end of the chunk passed to the tls check. However, if the actual allocator cache comes after the end of the chunk, then the sub in the end - params->allocator_caches[i] bit overflows. Since the resulting type is an unsigned uptr, this is not UB, but if the signed result would be a negative value (ie. end < params->allocator_caches[i]) then this will actually result in a very large unsigned value much bigger than the compared sizeof(AllocatorCache) which will almost always be true. This can cause ScanRangeForPointers to accept incorrect values: a begin pointing to some address, and params->allocator_caches[i] pointing to some much larger address way past the end of the chunk which can result in a page fault/stack overflow.

Diff Detail

Event Timeline

leonardchan created this revision.Sep 14 2023, 3:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 14 2023, 3:19 PM
leonardchan requested review of this revision.Sep 14 2023, 3:19 PM
phosek accepted this revision.Sep 14 2023, 4:02 PM

LGTM

This revision is now accepted and ready to land.Sep 14 2023, 4:02 PM