[compiler-rt] Poison last word of FakeFrame (PR #133689)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 2 05:43:17 PDT 2025


https://github.com/brandb97 updated https://github.com/llvm/llvm-project/pull/133689

>From 03cd392eb1bb027cf70421e4e9f0eb6e5180637b Mon Sep 17 00:00:00 2001
From: lidongyan <502024330056 at smail.nju.edu.cn>
Date: Mon, 31 Mar 2025 15:14:45 +0800
Subject: [PATCH 1/2] Poison last word of FakeFrame

---
 compiler-rt/lib/asan/asan_fake_stack.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/lib/asan/asan_fake_stack.cpp b/compiler-rt/lib/asan/asan_fake_stack.cpp
index 7443ff166984d..f68dd31ab1610 100644
--- a/compiler-rt/lib/asan/asan_fake_stack.cpp
+++ b/compiler-rt/lib/asan/asan_fake_stack.cpp
@@ -107,7 +107,12 @@ FakeFrame *FakeStack::Allocate(uptr stack_size_log, uptr class_id,
     FakeFrame *res = reinterpret_cast<FakeFrame *>(
         GetFrame(stack_size_log, class_id, pos));
     res->real_stack = real_stack;
-    *SavedFlagPtr(reinterpret_cast<uptr>(res), class_id) = &flags[pos];
+    u8 **saved_flag_ptr = SavedFlagPtr(reinterpret_cast<uptr>(res), class_id);
+    *saved_flag_ptr = &flags[pos];
+
+    // Poison the last word of FakeFrame
+    u8 *shadow = reinterpret_cast<u8*>(MemToShadow(reinterpret_cast<uptr>(saved_flag_ptr)));
+    *shadow = kMagic1;
     return res;
   }
   return nullptr; // We are out of fake stack.

>From be3221b82d9c12bceaa16236be9df191e1a0f5f3 Mon Sep 17 00:00:00 2001
From: brandb97 <77328395+brandb97 at users.noreply.github.com>
Date: Wed, 2 Apr 2025 20:43:09 +0800
Subject: [PATCH 2/2] replace oxf5 with 0xf3

replace kAsanAfterReturnMagic with kAsanStackRightRedzoneMagic
---
 compiler-rt/lib/asan/asan_fake_stack.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/lib/asan/asan_fake_stack.cpp b/compiler-rt/lib/asan/asan_fake_stack.cpp
index f68dd31ab1610..590c759d76078 100644
--- a/compiler-rt/lib/asan/asan_fake_stack.cpp
+++ b/compiler-rt/lib/asan/asan_fake_stack.cpp
@@ -112,7 +112,7 @@ FakeFrame *FakeStack::Allocate(uptr stack_size_log, uptr class_id,
 
     // Poison the last word of FakeFrame
     u8 *shadow = reinterpret_cast<u8*>(MemToShadow(reinterpret_cast<uptr>(saved_flag_ptr)));
-    *shadow = kMagic1;
+    *shadow = kAsanStackRightRedzoneMagic;
     return res;
   }
   return nullptr; // We are out of fake stack.



More information about the llvm-commits mailing list