-mbranch-protection protects the LR on the stack with PAC.
When the frames are walked the LR need to be cleared.
This inline assembly later will be replaced with a new builtin.
Test: build with -DCMAKE_C_FLAGS="-mbranch-protection=standard".
Paths
| Differential D98008
[AArch64][compiler-rt] Strip PAC from the link register. ClosedPublic Authored by danielkiss on Mar 4 2021, 11:08 PM.
Details Summary -mbranch-protection protects the LR on the stack with PAC. Test: build with -DCMAKE_C_FLAGS="-mbranch-protection=standard".
Diff Detail Event TimelineComment Actions Could we reuse the macros/builtins from https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h instead? Something like this: // Let's assume that any pointer in the 0th page (i.e. <0x1000 on i386 and // x86_64) is invalid and stop unwinding here. If we're adding support for // a platform where this isn't true, we need to reconsider this check. if (pc1 < kPageSize) break; +#if __has_feature(ptrauth_returns) + pc1 = (uhwptr)ptrauth_strip((void *)pc1, ptrauth_key_return_address); +#endif ? Comment Actions
Yes, that is the plan "This inline assembly later will be replaced with a new builtin." I tried to refer to this builtin. Comment Actions Keep the PAC in the stack trace and only strip it when necessary like comparing traces, looking up symbols.
danielkiss marked an inline comment as done. Comment Actions
Interesting, I'm not saying it's necessarily a bad idea, but could you explain the motivation? The previous approach (stripping the stack trace PCs at the point of capturing stack trace) seemed simpler, easier to implement and presumably faster (less stripping operations overall).
Comment Actions
Storing the PAC protected return addresses sounds safer because the values in trace can't be used directly as jump addresses. Assuming some might use sanitisers in production.
Comment Actions The current think is that the unstripped value of the return addresses is not too problematic. danielkiss added inline comments.
danielkiss marked an inline comment as done. This revision is now accepted and ready to land.Mar 12 2021, 5:36 PM This revision was landed with ongoing or failed builds.Mar 15 2021, 2:26 AM Closed by commit rGad40453fc425: [AArch64][compiler-rt] Strip PAC from the link register. (authored by danielkiss). · Explain Why This revision was automatically updated to reflect the committed changes.
danielkiss added inline comments.
Revision Contents
Diff 329382 compiler-rt/lib/asan/asan_suppressions.cpp
compiler-rt/lib/lsan/lsan_common.cpp
compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h
compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp
compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
compiler-rt/lib/tsan/rtl/tsan_external.cpp
compiler-rt/lib/tsan/rtl/tsan_interface.cpp
compiler-rt/lib/tsan/rtl/tsan_interface_inl.h
compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
|
Also add && !__APPLE__ please. I think there's no good reason to change the behavior of PAC on Apple platforms, so we shouldn't do that.