Skip to content

Commit 00989f4

Browse files
authored
[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().
1 parent 3bace7e commit 00989f4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler-rt/lib/scudo/standalone/combined.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,9 @@ class Allocator {
785785
// A corrupted chunk will not be reported as owned, which is WAI.
786786
bool isOwned(const void *Ptr) {
787787
initThreadMaybe();
788+
// If the allocation is not owned, the tags could be wrong.
789+
ScopedDisableMemoryTagChecks x(
790+
useMemoryTagging<AllocatorConfig>(Primary.Options.load()));
788791
#ifdef GWP_ASAN_HOOKS
789792
if (GuardedAlloc.pointerIsMine(Ptr))
790793
return true;

compiler-rt/lib/scudo/standalone/memtag.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ inline NORETURN void enableSystemMemoryTaggingTestOnly() {
122122

123123
class ScopedDisableMemoryTagChecks {
124124
uptr PrevTCO;
125+
bool active;
125126

126127
public:
127-
ScopedDisableMemoryTagChecks() {
128+
ScopedDisableMemoryTagChecks(bool cond = true) : active(cond) {
129+
if (!active)
130+
return;
128131
__asm__ __volatile__(
129132
R"(
130133
.arch_extension memtag
@@ -135,6 +138,8 @@ class ScopedDisableMemoryTagChecks {
135138
}
136139

137140
~ScopedDisableMemoryTagChecks() {
141+
if (!active)
142+
return;
138143
__asm__ __volatile__(
139144
R"(
140145
.arch_extension memtag
@@ -269,7 +274,7 @@ inline NORETURN void enableSystemMemoryTaggingTestOnly() {
269274
}
270275

271276
struct ScopedDisableMemoryTagChecks {
272-
ScopedDisableMemoryTagChecks() {}
277+
ScopedDisableMemoryTagChecks(UNUSED bool cond = true) {}
273278
};
274279

275280
inline NORETURN uptr selectRandomTag(uptr Ptr, uptr ExcludeMask) {

0 commit comments

Comments
 (0)