diff --git a/compiler-rt/lib/asan/asan_mapping.h b/compiler-rt/lib/asan/asan_mapping.h index bddae9a074056..338324686a31d 100644 --- a/compiler-rt/lib/asan/asan_mapping.h +++ b/compiler-rt/lib/asan/asan_mapping.h @@ -285,7 +285,7 @@ extern uptr kHighMemEnd, kMidMemBeg, kMidMemEnd; // Initialized in __asan_init. # include "asan_mapping_sparc64.h" # else # define MEM_TO_SHADOW(mem) \ - (((mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET)) + ((STRIP_MTE_TAG(mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET)) # define SHADOW_TO_MEM(mem) \ (((mem) - (ASAN_SHADOW_OFFSET)) << (ASAN_SHADOW_SCALE)) @@ -377,6 +377,7 @@ static inline uptr MemToShadowSize(uptr size) { static inline bool AddrIsInMem(uptr a) { PROFILE_ASAN_MAPPING(); + a = STRIP_MTE_TAG(a); return AddrIsInLowMem(a) || AddrIsInMidMem(a) || AddrIsInHighMem(a) || (flags()->protect_shadow_gap == 0 && AddrIsInShadowGap(a)); } @@ -389,6 +390,7 @@ static inline uptr MemToShadow(uptr p) { static inline bool AddrIsInShadow(uptr a) { PROFILE_ASAN_MAPPING(); + a = STRIP_MTE_TAG(a); return AddrIsInLowShadow(a) || AddrIsInMidShadow(a) || AddrIsInHighShadow(a); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h index 13099fe84b0aa..1b47f3e24d12d 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h @@ -497,4 +497,11 @@ # endif #endif +#if SANITIZER_APPLE && SANITIZER_WORDSIZE == 64 +// MTE uses the lower half of the top byte. +# define STRIP_MTE_TAG(addr) ((addr) & ~((uptr)0x0f << 56)) +#else +# define STRIP_MTE_TAG(addr) (addr) +#endif + #endif // SANITIZER_PLATFORM_H diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform.h b/compiler-rt/lib/tsan/rtl/tsan_platform.h index 00b493bf2d931..7089be4d5d7f7 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_platform.h +++ b/compiler-rt/lib/tsan/rtl/tsan_platform.h @@ -958,7 +958,9 @@ struct IsAppMemImpl { }; ALWAYS_INLINE -bool IsAppMem(uptr mem) { return SelectMapping(mem); } +bool IsAppMem(uptr mem) { + return SelectMapping(STRIP_MTE_TAG(mem)); +} struct IsShadowMemImpl { template @@ -997,7 +999,8 @@ struct MemToShadowImpl { ALWAYS_INLINE RawShadow *MemToShadow(uptr x) { - return reinterpret_cast(SelectMapping(x)); + return reinterpret_cast( + SelectMapping(STRIP_MTE_TAG(x))); } struct MemToMetaImpl { @@ -1011,7 +1014,9 @@ struct MemToMetaImpl { }; ALWAYS_INLINE -u32 *MemToMeta(uptr x) { return SelectMapping(x); } +u32* MemToMeta(uptr x) { + return SelectMapping(STRIP_MTE_TAG(x)); +} struct ShadowToMemImpl { template