-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".
Differential D98008
[AArch64][compiler-rt] Strip PAC from the link register. danielkiss on Mar 4 2021, 11:08 PM. Authored by
Details -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 Keep the PAC in the stack trace and only strip it when necessary like comparing traces, looking up symbols.
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.
|
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.