@@ -22,15 +22,19 @@ struct ptrauth_key {
22
22
* We give each process its own keys, which are shared by all threads. The keys
23
23
* are inherited upon fork(), and reinitialised upon exec*().
24
24
*/
25
- struct ptrauth_keys {
25
+ struct ptrauth_keys_user {
26
26
struct ptrauth_key apia ;
27
27
struct ptrauth_key apib ;
28
28
struct ptrauth_key apda ;
29
29
struct ptrauth_key apdb ;
30
30
struct ptrauth_key apga ;
31
31
};
32
32
33
- static inline void ptrauth_keys_init (struct ptrauth_keys * keys )
33
+ struct ptrauth_keys_kernel {
34
+ struct ptrauth_key apia ;
35
+ };
36
+
37
+ static inline void ptrauth_keys_init_user (struct ptrauth_keys_user * keys )
34
38
{
35
39
if (system_supports_address_auth ()) {
36
40
get_random_bytes (& keys -> apia , sizeof (keys -> apia ));
@@ -50,48 +54,38 @@ do { \
50
54
write_sysreg_s(__pki_v.hi, SYS_ ## k ## KEYHI_EL1); \
51
55
} while (0)
52
56
53
- static inline void ptrauth_keys_switch (struct ptrauth_keys * keys )
57
+ static __always_inline void ptrauth_keys_init_kernel (struct ptrauth_keys_kernel * keys )
54
58
{
55
- if (system_supports_address_auth ()) {
56
- __ptrauth_key_install (APIA , keys -> apia );
57
- __ptrauth_key_install (APIB , keys -> apib );
58
- __ptrauth_key_install (APDA , keys -> apda );
59
- __ptrauth_key_install (APDB , keys -> apdb );
60
- }
59
+ if (system_supports_address_auth ())
60
+ get_random_bytes (& keys -> apia , sizeof (keys -> apia ));
61
+ }
61
62
62
- if (system_supports_generic_auth ())
63
- __ptrauth_key_install (APGA , keys -> apga );
63
+ static __always_inline void ptrauth_keys_switch_kernel (struct ptrauth_keys_kernel * keys )
64
+ {
65
+ if (system_supports_address_auth ())
66
+ __ptrauth_key_install (APIA , keys -> apia );
64
67
}
65
68
66
69
extern int ptrauth_prctl_reset_keys (struct task_struct * tsk , unsigned long arg );
67
70
68
- /*
69
- * The EL0 pointer bits used by a pointer authentication code.
70
- * This is dependent on TBI0 being enabled, or bits 63:56 would also apply.
71
- */
72
- #define ptrauth_user_pac_mask () GENMASK(54, vabits_actual)
73
-
74
- /* Only valid for EL0 TTBR0 instruction pointers */
75
71
static inline unsigned long ptrauth_strip_insn_pac (unsigned long ptr )
76
72
{
77
- return ptr & ~ ptrauth_user_pac_mask ( );
73
+ return ptrauth_clear_pac ( ptr );
78
74
}
79
75
80
76
#define ptrauth_thread_init_user (tsk ) \
81
- do { \
82
- struct task_struct *__ptiu_tsk = (tsk); \
83
- ptrauth_keys_init(&__ptiu_tsk->thread.keys_user); \
84
- ptrauth_keys_switch(&__ptiu_tsk->thread.keys_user); \
85
- } while (0)
86
-
87
- #define ptrauth_thread_switch (tsk ) \
88
- ptrauth_keys_switch(&(tsk)->thread.keys_user)
77
+ ptrauth_keys_init_user(&(tsk)->thread.keys_user)
78
+ #define ptrauth_thread_init_kernel (tsk ) \
79
+ ptrauth_keys_init_kernel(&(tsk)->thread.keys_kernel)
80
+ #define ptrauth_thread_switch_kernel (tsk ) \
81
+ ptrauth_keys_switch_kernel(&(tsk)->thread.keys_kernel)
89
82
90
83
#else /* CONFIG_ARM64_PTR_AUTH */
91
84
#define ptrauth_prctl_reset_keys (tsk , arg ) (-EINVAL)
92
85
#define ptrauth_strip_insn_pac (lr ) (lr)
93
86
#define ptrauth_thread_init_user (tsk )
94
- #define ptrauth_thread_switch (tsk )
87
+ #define ptrauth_thread_init_kernel (tsk )
88
+ #define ptrauth_thread_switch_kernel (tsk )
95
89
#endif /* CONFIG_ARM64_PTR_AUTH */
96
90
97
91
#endif /* __ASM_POINTER_AUTH_H */
0 commit comments