Skip to content

Commit 511b8b0

Browse files
asltru
authored andcommitted
Normalize ptrauth handling in sanitizer runtime (#100483)
1. Include `ptrauth.h` if `ptrauth_intrinsics` language feature is specified (per ptrauth spec, this is what enables `ptrauh.h` usage and functions like `ptrauth_strip`) 2. For PAC-RET fallback implement two changes: 1. Switch to macro, so we can ignore key argument 2. Ensure the unsigned value is erased from LR, so the possibility of gadget reuse is reduced. Fixes #100467 (cherry picked from commit cc4f989)
1 parent ec17a7a commit 511b8b0

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_ptrauth.h

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,33 @@
99
#ifndef SANITIZER_PTRAUTH_H
1010
#define SANITIZER_PTRAUTH_H
1111

12-
#if __has_feature(ptrauth_calls)
13-
#include <ptrauth.h>
12+
#if __has_feature(ptrauth_intrinsics)
13+
# include <ptrauth.h>
1414
#elif defined(__ARM_FEATURE_PAC_DEFAULT) && !defined(__APPLE__)
15-
inline unsigned long ptrauth_strip(void* __value, unsigned int __key) {
16-
// On the stack the link register is protected with Pointer
17-
// Authentication Code when compiled with -mbranch-protection.
18-
// Let's stripping the PAC unconditionally because xpaclri is in
19-
// the NOP space so will do nothing when it is not enabled or not available.
20-
unsigned long ret;
21-
asm volatile(
22-
"mov x30, %1\n\t"
23-
"hint #7\n\t" // xpaclri
24-
"mov %0, x30\n\t"
25-
: "=r"(ret)
26-
: "r"(__value)
27-
: "x30");
28-
return ret;
29-
}
30-
#define ptrauth_auth_data(__value, __old_key, __old_data) __value
31-
#define ptrauth_string_discriminator(__string) ((int)0)
15+
// On the stack the link register is protected with Pointer
16+
// Authentication Code when compiled with -mbranch-protection.
17+
// Let's stripping the PAC unconditionally because xpaclri is in
18+
// the NOP space so will do nothing when it is not enabled or not available.
19+
# define ptrauth_strip(__value, __key) \
20+
({ \
21+
unsigned long ret; \
22+
asm volatile( \
23+
"mov x30, %1\n\t" \
24+
"hint #7\n\t" \
25+
"mov %0, x30\n\t" \
26+
"mov x30, xzr\n\t" \
27+
: "=r"(ret) \
28+
: "r"(__value) \
29+
: "x30"); \
30+
ret; \
31+
})
32+
# define ptrauth_auth_data(__value, __old_key, __old_data) __value
33+
# define ptrauth_string_discriminator(__string) ((int)0)
3234
#else
3335
// Copied from <ptrauth.h>
34-
#define ptrauth_strip(__value, __key) __value
35-
#define ptrauth_auth_data(__value, __old_key, __old_data) __value
36-
#define ptrauth_string_discriminator(__string) ((int)0)
36+
# define ptrauth_strip(__value, __key) __value
37+
# define ptrauth_auth_data(__value, __old_key, __old_data) __value
38+
# define ptrauth_string_discriminator(__string) ((int)0)
3739
#endif
3840

3941
#define STRIP_PAC_PC(pc) ((uptr)ptrauth_strip(pc, 0))

0 commit comments

Comments
 (0)