[compiler-rt] [scudo] Fix isOwned on MTE devices. (PR #111060)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 13:41:03 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: Evgenii Stepanov (eugenis)
<details>
<summary>Changes</summary>
If called on address that is actually not owned, the tags could not match. Disable tag checks in isOwned().
---
Full diff: https://github.com/llvm/llvm-project/pull/111060.diff
2 Files Affected:
- (modified) compiler-rt/lib/scudo/standalone/combined.h (+3)
- (modified) compiler-rt/lib/scudo/standalone/memtag.h (+7-2)
``````````diff
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..06a2ed275e9afb 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(bool cond UNUSED = true) {}
};
inline NORETURN uptr selectRandomTag(uptr Ptr, uptr ExcludeMask) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/111060
More information about the llvm-commits
mailing list