diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h index a5f1bc388e882..323a8b9d76c99 100644 --- a/compiler-rt/lib/scudo/standalone/combined.h +++ b/compiler-rt/lib/scudo/standalone/combined.h @@ -785,6 +785,9 @@ class Allocator { // A corrupted chunk will not be reported as owned, which is WAI. bool isOwned(const void *Ptr) { initThreadMaybe(); + // If the allocation is not owned, the tags could be wrong. + ScopedDisableMemoryTagChecks x( + useMemoryTagging(Primary.Options.load())); #ifdef GWP_ASAN_HOOKS if (GuardedAlloc.pointerIsMine(Ptr)) return true; diff --git a/compiler-rt/lib/scudo/standalone/memtag.h b/compiler-rt/lib/scudo/standalone/memtag.h index 1f6983e99404a..83ebe676433eb 100644 --- a/compiler-rt/lib/scudo/standalone/memtag.h +++ b/compiler-rt/lib/scudo/standalone/memtag.h @@ -122,9 +122,12 @@ inline NORETURN void enableSystemMemoryTaggingTestOnly() { class ScopedDisableMemoryTagChecks { uptr PrevTCO; + bool active; public: - ScopedDisableMemoryTagChecks() { + ScopedDisableMemoryTagChecks(bool cond = true) : active(cond) { + if (!active) + return; __asm__ __volatile__( R"( .arch_extension memtag @@ -135,6 +138,8 @@ class ScopedDisableMemoryTagChecks { } ~ScopedDisableMemoryTagChecks() { + if (!active) + return; __asm__ __volatile__( R"( .arch_extension memtag @@ -269,7 +274,7 @@ inline NORETURN void enableSystemMemoryTaggingTestOnly() { } struct ScopedDisableMemoryTagChecks { - ScopedDisableMemoryTagChecks() {} + ScopedDisableMemoryTagChecks(UNUSED bool cond = true) {} }; inline NORETURN uptr selectRandomTag(uptr Ptr, uptr ExcludeMask) {