[PATCH] D153072: [lsan] Be more conservative in SuspendedThreadsListMac::GetRegistersAndSP

Leonard Grey via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 13:52:31 PDT 2023


lgrey created this revision.
lgrey added a reviewer: kubamracek.
Herald added a subscriber: Enna1.
Herald added a project: All.
lgrey requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153072

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


Index: compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_mac.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_mac.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_mac.cpp
@@ -154,12 +154,10 @@
                          &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));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153072.531894.patch
Type: text/x-patch
Size: 1031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230615/5f77a4eb/attachment.bin>


More information about the llvm-commits mailing list