@@ -31,17 +31,36 @@ struct ptrauth_keys_user {
3131 struct ptrauth_key apga ;
3232};
3333
34- struct ptrauth_keys_kernel {
35- struct ptrauth_key apia ;
36- };
37-
3834#define __ptrauth_key_install_nosync (k , v ) \
3935do { \
4036 struct ptrauth_key __pki_v = (v); \
4137 write_sysreg_s(__pki_v.lo, SYS_ ## k ## KEYLO_EL1); \
4238 write_sysreg_s(__pki_v.hi, SYS_ ## k ## KEYHI_EL1); \
4339} while (0)
4440
41+ #ifdef CONFIG_ARM64_PTR_AUTH_KERNEL
42+
43+ struct ptrauth_keys_kernel {
44+ struct ptrauth_key apia ;
45+ };
46+
47+ static __always_inline void ptrauth_keys_init_kernel (struct ptrauth_keys_kernel * keys )
48+ {
49+ if (system_supports_address_auth ())
50+ get_random_bytes (& keys -> apia , sizeof (keys -> apia ));
51+ }
52+
53+ static __always_inline void ptrauth_keys_switch_kernel (struct ptrauth_keys_kernel * keys )
54+ {
55+ if (!system_supports_address_auth ())
56+ return ;
57+
58+ __ptrauth_key_install_nosync (APIA , keys -> apia );
59+ isb ();
60+ }
61+
62+ #endif /* CONFIG_ARM64_PTR_AUTH_KERNEL */
63+
4564static inline void ptrauth_keys_install_user (struct ptrauth_keys_user * keys )
4665{
4766 if (system_supports_address_auth ()) {
@@ -69,21 +88,6 @@ static inline void ptrauth_keys_init_user(struct ptrauth_keys_user *keys)
6988 ptrauth_keys_install_user (keys );
7089}
7190
72- static __always_inline void ptrauth_keys_init_kernel (struct ptrauth_keys_kernel * keys )
73- {
74- if (system_supports_address_auth ())
75- get_random_bytes (& keys -> apia , sizeof (keys -> apia ));
76- }
77-
78- static __always_inline void ptrauth_keys_switch_kernel (struct ptrauth_keys_kernel * keys )
79- {
80- if (!system_supports_address_auth ())
81- return ;
82-
83- __ptrauth_key_install_nosync (APIA , keys -> apia );
84- isb ();
85- }
86-
8791extern int ptrauth_prctl_reset_keys (struct task_struct * tsk , unsigned long arg );
8892
8993extern int ptrauth_set_enabled_keys (struct task_struct * tsk , unsigned long keys ,
@@ -121,11 +125,6 @@ static __always_inline void ptrauth_enable(void)
121125#define ptrauth_thread_switch_user (tsk ) \
122126 ptrauth_keys_install_user(&(tsk)->thread.keys_user)
123127
124- #define ptrauth_thread_init_kernel (tsk ) \
125- ptrauth_keys_init_kernel(&(tsk)->thread.keys_kernel)
126- #define ptrauth_thread_switch_kernel (tsk ) \
127- ptrauth_keys_switch_kernel(&(tsk)->thread.keys_kernel)
128-
129128#else /* CONFIG_ARM64_PTR_AUTH */
130129#define ptrauth_enable ()
131130#define ptrauth_prctl_reset_keys (tsk , arg ) (-EINVAL)
@@ -134,11 +133,19 @@ static __always_inline void ptrauth_enable(void)
134133#define ptrauth_strip_insn_pac (lr ) (lr)
135134#define ptrauth_suspend_exit ()
136135#define ptrauth_thread_init_user ()
137- #define ptrauth_thread_init_kernel (tsk )
138136#define ptrauth_thread_switch_user (tsk )
139- #define ptrauth_thread_switch_kernel (tsk )
140137#endif /* CONFIG_ARM64_PTR_AUTH */
141138
139+ #ifdef CONFIG_ARM64_PTR_AUTH_KERNEL
140+ #define ptrauth_thread_init_kernel (tsk ) \
141+ ptrauth_keys_init_kernel(&(tsk)->thread.keys_kernel)
142+ #define ptrauth_thread_switch_kernel (tsk ) \
143+ ptrauth_keys_switch_kernel(&(tsk)->thread.keys_kernel)
144+ #else
145+ #define ptrauth_thread_init_kernel (tsk )
146+ #define ptrauth_thread_switch_kernel (tsk )
147+ #endif /* CONFIG_ARM64_PTR_AUTH_KERNEL */
148+
142149#define PR_PAC_ENABLED_KEYS_MASK \
143150 (PR_PAC_APIAKEY | PR_PAC_APIBKEY | PR_PAC_APDAKEY | PR_PAC_APDBKEY)
144151
0 commit comments