Skip to content

Commit

Permalink
[scudo] Fix isOwned on MTE devices. (llvm#111060)
Browse files Browse the repository at this point in the history
If called on address that is actually not owned, the tags could not
match. Disable tag checks in isOwned().
  • Loading branch information
eugenis authored Oct 7, 2024
1 parent 3bace7e commit 00989f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions compiler-rt/lib/scudo/standalone/combined.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<AllocatorConfig>(Primary.Options.load()));
#ifdef GWP_ASAN_HOOKS
if (GuardedAlloc.pointerIsMine(Ptr))
return true;
Expand Down
9 changes: 7 additions & 2 deletions compiler-rt/lib/scudo/standalone/memtag.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -135,6 +138,8 @@ class ScopedDisableMemoryTagChecks {
}

~ScopedDisableMemoryTagChecks() {
if (!active)
return;
__asm__ __volatile__(
R"(
.arch_extension memtag
Expand Down Expand Up @@ -269,7 +274,7 @@ inline NORETURN void enableSystemMemoryTaggingTestOnly() {
}

struct ScopedDisableMemoryTagChecks {
ScopedDisableMemoryTagChecks() {}
ScopedDisableMemoryTagChecks(UNUSED bool cond = true) {}
};

inline NORETURN uptr selectRandomTag(uptr Ptr, uptr ExcludeMask) {
Expand Down

0 comments on commit 00989f4

Please sign in to comment.