[scudo] Fix isOwned on MTE devices. (#111060)

If called on address that is actually not owned, the tags could not
match. Disable tag checks in isOwned().

GitOrigin-RevId: 00989f4ab14c4cf41bbac258f2bf197cbbdc2b41
diff --git a/combined.h b/combined.h
index a5f1bc3..323a8b9 100644
--- a/combined.h
+++ b/combined.h
@@ -785,6 +785,9 @@
   // 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<AllocatorConfig>(Primary.Options.load()));
 #ifdef GWP_ASAN_HOOKS
     if (GuardedAlloc.pointerIsMine(Ptr))
       return true;
diff --git a/memtag.h b/memtag.h
index 1f6983e..83ebe67 100644
--- a/memtag.h
+++ b/memtag.h
@@ -122,9 +122,12 @@
 
 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 @@
   }
 
   ~ScopedDisableMemoryTagChecks() {
+    if (!active)
+      return;
     __asm__ __volatile__(
         R"(
         .arch_extension memtag
@@ -269,7 +274,7 @@
 }
 
 struct ScopedDisableMemoryTagChecks {
-  ScopedDisableMemoryTagChecks() {}
+  ScopedDisableMemoryTagChecks(UNUSED bool cond = true) {}
 };
 
 inline NORETURN uptr selectRandomTag(uptr Ptr, uptr ExcludeMask) {