[compiler-rt] 00989f4 - [scudo] Fix isOwned on MTE devices. (#111060)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 7 14:13:20 PDT 2024
Author: Evgenii Stepanov
Date: 2024-10-07T14:13:17-07:00
New Revision: 00989f4ab14c4cf41bbac258f2bf197cbbdc2b41
URL: https://github.com/llvm/llvm-project/commit/00989f4ab14c4cf41bbac258f2bf197cbbdc2b41
DIFF: https://github.com/llvm/llvm-project/commit/00989f4ab14c4cf41bbac258f2bf197cbbdc2b41.diff
LOG: [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().
Added:
Modified:
compiler-rt/lib/scudo/standalone/combined.h
compiler-rt/lib/scudo/standalone/memtag.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index a5f1bc388e8824..323a8b9d76c994 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<AllocatorConfig>(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 1f6983e99404a2..83ebe676433ebd 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) {
More information about the llvm-commits
mailing list