[compiler-rt] 5e4740c - [Darwin] Improve ASan diagnostics on arm64e with pointer auth

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 18:33:50 PDT 2020


Author: Julian Lettner
Date: 2020-05-06T18:32:31-07:00
New Revision: 5e4740c21284054a3e2905bfdcaadff1a9bd4bb0

URL: https://github.com/llvm/llvm-project/commit/5e4740c21284054a3e2905bfdcaadff1a9bd4bb0
DIFF: https://github.com/llvm/llvm-project/commit/5e4740c21284054a3e2905bfdcaadff1a9bd4bb0.diff

LOG: [Darwin] Improve ASan diagnostics on arm64e with pointer auth

When reporting diagnostics from ASan's (and other sanitizer's) signal
handlers we should strip the "invalid signature" bit before printing
addresses.  This makes the report less confusing and let's the user
focus on the real issue.

rdar://62615826

Reviewed By: kubamracek, delcypher

Differential Revision: https://reviews.llvm.org/D79132

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index a3a827cdb6ab..eff970d178ed 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -765,9 +765,16 @@ bool SignalContext::IsTrueFaultingAddress() const {
   return si->si_signo == SIGSEGV && si->si_code != 0;
 }
 
+#if __has_feature(ptrauth_calls)
+# include <ptrauth.h>
+#else
+# define ptrauth_strip(value, key) (value)
+#endif
+
 #if defined(__aarch64__) && defined(arm_thread_state64_get_sp)
   #define AARCH64_GET_REG(r) \
-    arm_thread_state64_get_##r(ucontext->uc_mcontext->__ss)
+    (uptr)ptrauth_strip(     \
+        (void *)arm_thread_state64_get_##r(ucontext->uc_mcontext->__ss), 0)
 #else
   #define AARCH64_GET_REG(r) ucontext->uc_mcontext->__ss.__##r
 #endif
@@ -799,7 +806,10 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
 # endif
 }
 
-void SignalContext::InitPcSpBp() { GetPcSpBp(context, &pc, &sp, &bp); }
+void SignalContext::InitPcSpBp() {
+  addr = (uptr)ptrauth_strip((void *)addr, 0);
+  GetPcSpBp(context, &pc, &sp, &bp);
+}
 
 void InitializePlatformEarly() {
   // Only use xnu_fast_mmap when on x86_64 and the OS supports it.
@@ -1136,7 +1146,7 @@ void SignalContext::DumpAllRegisters(void *context) {
 # define DUMPREG64(r) \
     Printf("%s = 0x%016llx  ", #r, ucontext->uc_mcontext->__ss.__ ## r);
 # define DUMPREGA64(r) \
-    Printf("%s = 0x%016llx  ", #r, AARCH64_GET_REG(r));
+    Printf("   %s = 0x%016llx  ", #r, AARCH64_GET_REG(r));
 # define DUMPREG32(r) \
     Printf("%s = 0x%08x  ", #r, ucontext->uc_mcontext->__ss.__ ## r);
 # define DUMPREG_(r)   Printf(" "); DUMPREG(r);


        


More information about the llvm-commits mailing list