[compiler-rt] 515c435 - [asan] Fix stack pointers comparison in FakeStack

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 18 00:28:33 PDT 2023


Author: Vitaly Buka
Date: 2023-08-18T00:28:20-07:00
New Revision: 515c435e378b243b1be3da1587c9e206055f2c32

URL: https://github.com/llvm/llvm-project/commit/515c435e378b243b1be3da1587c9e206055f2c32
DIFF: https://github.com/llvm/llvm-project/commit/515c435e378b243b1be3da1587c9e206055f2c32.diff

LOG: [asan] Fix stack pointers comparison in FakeStack

Unlucky naming top/bottom for stack bounds, has nothing to do with real
stack top. So top > botton is here, and opposite of
9be8892908d49c19fd6c9fc930d0f41276c3e345 assumption.

This is minimal fix in case cherry-picks is needed. Naming fix and
testing (if possible) will be in followup patches.

Introduced in 9be8892908d49c19fd6c9fc930d0f41276c3e345.
Can't symply reverted 9be8892908d49c19fd6c9fc930d0f41276c3e345 as
it fixes ~10 year old bug, accidentally exposed by
a8bef8865e4a4226ee608df327fddd380870c620.

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_fake_stack.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_fake_stack.cpp b/compiler-rt/lib/asan/asan_fake_stack.cpp
index 8680bc6d6630e2..4273f178dc9f06 100644
--- a/compiler-rt/lib/asan/asan_fake_stack.cpp
+++ b/compiler-rt/lib/asan/asan_fake_stack.cpp
@@ -151,7 +151,7 @@ NOINLINE void FakeStack::GC(uptr real_stack) {
     return;  // Try again when we have a thread.
   auto top = curr_thread->stack_top();
   auto bottom = curr_thread->stack_bottom();
-  if (real_stack < top || real_stack > bottom)
+  if (real_stack < bottom || real_stack > top)
     return;  // Not the default stack.
 
   for (uptr class_id = 0; class_id < kNumberOfSizeClasses; class_id++) {
@@ -162,7 +162,7 @@ NOINLINE void FakeStack::GC(uptr real_stack) {
       FakeFrame *ff = reinterpret_cast<FakeFrame *>(
           GetFrame(stack_size_log(), class_id, i));
       // GC only on the default stack.
-      if (ff->real_stack < real_stack && ff->real_stack >= top) {
+      if (bottom < ff->real_stack && ff->real_stack < real_stack) {
         flags[i] = 0;
         // Poison the frame, so the any access will be reported as UAR.
         SetShadow(reinterpret_cast<uptr>(ff), BytesInSizeClass(class_id),


        


More information about the llvm-commits mailing list