@@ -22,15 +22,19 @@ struct ptrauth_key {
2222 * We give each process its own keys, which are shared by all threads. The keys
2323 * are inherited upon fork(), and reinitialised upon exec*().
2424 */
25- struct ptrauth_keys {
25+ struct ptrauth_keys_user {
2626 struct ptrauth_key apia ;
2727 struct ptrauth_key apib ;
2828 struct ptrauth_key apda ;
2929 struct ptrauth_key apdb ;
3030 struct ptrauth_key apga ;
3131};
3232
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 )
3438{
3539 if (system_supports_address_auth ()) {
3640 get_random_bytes (& keys -> apia , sizeof (keys -> apia ));
@@ -50,48 +54,38 @@ do { \
5054 write_sysreg_s(__pki_v.hi, SYS_ ## k ## KEYHI_EL1); \
5155} while (0)
5256
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 )
5458{
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+ }
6162
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 );
6467}
6568
6669extern int ptrauth_prctl_reset_keys (struct task_struct * tsk , unsigned long arg );
6770
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 */
7571static inline unsigned long ptrauth_strip_insn_pac (unsigned long ptr )
7672{
77- return ptr & ~ ptrauth_user_pac_mask ( );
73+ return ptrauth_clear_pac ( ptr );
7874}
7975
8076#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)
8982
9083#else /* CONFIG_ARM64_PTR_AUTH */
9184#define ptrauth_prctl_reset_keys (tsk , arg ) (-EINVAL)
9285#define ptrauth_strip_insn_pac (lr ) (lr)
9386#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 )
9589#endif /* CONFIG_ARM64_PTR_AUTH */
9690
9791#endif /* __ASM_POINTER_AUTH_H */
0 commit comments