[LSAN] Mask out tags from pointers on ARM in MaybeUserPointer heuristic

This caused false positives because the existing logic was not taking into account that pointers could have a tag in them.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D144305
This commit is contained in:
Kirill Stoimenov 2023-02-18 00:02:06 +00:00
parent 890146b192
commit b4b5006be5

View File

@ -270,13 +270,17 @@ static inline bool MaybeUserPointer(uptr p) {
if (p < kMinAddress) if (p < kMinAddress)
return false; return false;
# if defined(__x86_64__) # if defined(__x86_64__)
// TODO: add logic similar to ARM when Intel LAM is available.
// Accept only canonical form user-space addresses. // Accept only canonical form user-space addresses.
return ((p >> 47) == 0); return ((p >> 47) == 0);
# elif defined(__mips64) # elif defined(__mips64)
return ((p >> 40) == 0); return ((p >> 40) == 0);
# elif defined(__aarch64__) # elif defined(__aarch64__)
// TBI (Top Byte Ignore) feature of AArch64: bits [63:56] are ignored in
// address translation and can be used to store a tag.
constexpr uptr kPointerMask = 255ULL << 48;
// Accept up to 48 bit VMA. // Accept up to 48 bit VMA.
return ((p >> 48) == 0); return ((p & kPointerMask) == 0);
# elif defined(__loongarch_lp64) # elif defined(__loongarch_lp64)
// Allow 47-bit user-space VMA at current. // Allow 47-bit user-space VMA at current.
return ((p >> 47) == 0); return ((p >> 47) == 0);