[compiler-rt] 4fd517d - [lsan] Be more conservative in SuspendedThreadsListMac::GetRegistersAndSP

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 01:40:27 PDT 2023


Author: Leonard Grey
Date: 2023-06-28T10:40:07+02:00
New Revision: 4fd517d6133e8ad2a35da60f5e0cd76d61868157

URL: https://github.com/llvm/llvm-project/commit/4fd517d6133e8ad2a35da60f5e0cd76d61868157
DIFF: https://github.com/llvm/llvm-project/commit/4fd517d6133e8ad2a35da60f5e0cd76d61868157.diff

LOG: [lsan] Be more conservative in SuspendedThreadsListMac::GetRegistersAndSP

Currently, we only return REGISTERS_UNAVAILABLE_FATAL if we receive
KERN_INVALID_ARGUMENT from thread_status. In reality, there are other
possible return values (MACH_SEND_INVALID_DEST for example) that make it
dangerous to read memory. This can be demonstrated by running
create_thread_leak.cpp in standalone mode where it will appear to hang
due to a EXC_BAD_ACCESS while scanning the stack.

This change reverses the current logic to treat MIG_ARRAY_TOO_LARGE as
non-fatal, and all other errors as fatal.

Differential revision: https://reviews.llvm.org/D153072

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_mac.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_mac.cpp
index 3ebeac52280a3..813616467656b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_mac.cpp
@@ -154,12 +154,10 @@ PtraceRegistersStatus SuspendedThreadsListMac::GetRegistersAndSP(
                          &reg_count);
   if (err != KERN_SUCCESS) {
     VReport(1, "Error - unable to get registers for a thread\n");
-    // KERN_INVALID_ARGUMENT indicates that either the flavor is invalid,
-    // or the thread does not exist. The other possible error case,
     // MIG_ARRAY_TOO_LARGE, means that the state is too large, but it's
     // still safe to proceed.
-    return err == KERN_INVALID_ARGUMENT ? REGISTERS_UNAVAILABLE_FATAL
-                                        : REGISTERS_UNAVAILABLE;
+    return err == MIG_ARRAY_TOO_LARGE ? REGISTERS_UNAVAILABLE
+                                      : REGISTERS_UNAVAILABLE_FATAL;
   }
 
   buffer->resize(RoundUpTo(sizeof(regs), sizeof(uptr)) / sizeof(uptr));


        


More information about the llvm-commits mailing list