This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt][lsan] Update CanBeAHeapPointer for AArch64
ClosedPublic

Authored by leonardchan on Apr 14 2022, 12:47 PM.

Details

Summary

While attempting to get the 64-bit lsan allocator working for Fuchsia, I noticed this function would incorrectly return false for pointers returned by the 64-bit allocator. On AArch64, this function attempts to get the VMA size dynamically by counting the number of leading zeros from the function frame address. This will fail if the frame address is significantly below an allocated pointer (that is, the frame address has more leading zeros than an allocated pointer). This is possible on Fuchsia and linux (when not called from the initial thread stack).

It seems the intended use of this function is to speed up pointer scanning by filtering out addresses that user code might not be able to access. Other platforms this check is done on seem to hardcode the VMA size/shift, so it seems appropriate to do this for aarch64 as well. This implies pointers on aarch64 where the VMA size is <64 will pass through, but bad pointers will still be caught by subsequent scan checks.

This patch also renames the function to something more fitting of what it's trying to do.

Diff Detail

Event Timeline

leonardchan created this revision.Apr 14 2022, 12:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2022, 12:47 PM
leonardchan requested review of this revision.Apr 14 2022, 12:47 PM
Herald added a subscriber: Restricted Project. · View Herald TranscriptApr 14 2022, 12:47 PM
vitalybuka accepted this revision.Apr 18 2022, 9:29 AM
This revision is now accepted and ready to land.Apr 18 2022, 9:29 AM
MaskRay added inline comments.
compiler-rt/lib/lsan/lsan_common.cpp
244

The s/Can/Could/ change seems unnecessary?

If you want to change it, in other places of LLVM, MayBe is more common.

pcc added a subscriber: pcc.Apr 18 2022, 2:44 PM
pcc added inline comments.
compiler-rt/lib/lsan/lsan_common.cpp
255

I think AArch64 can have up to 52 bit VAs.

leonardchan marked an inline comment as done.
leonardchan added inline comments.
compiler-rt/lib/lsan/lsan_common.cpp
244

Change was more intended on the Heap part since this code didn't really look like it was for checking if something is heap-allocated.

255

Yeah this value was more to fall in line with the other hardcoded values in this function. x86_64 could also be extended to 52bits depending on the page table format IIRC. I think what matters is if there are any lsan users that do use any higher order VMAs. Not sure if there are any that use 52bit, but I can increase to that value if there's suspicion of it.