Skip to content

Commit 91a1b6c

Browse files
kristina-martsenkoctmarinas
authored andcommitted
arm64: rename ptrauth key structures to be user-specific
We currently enable ptrauth for userspace, but do not use it within the kernel. We're going to enable it for the kernel, and will need to manage a separate set of ptrauth keys for the kernel. We currently keep all 5 keys in struct ptrauth_keys. However, as the kernel will only need to use 1 key, it is a bit wasteful to allocate a whole ptrauth_keys struct for every thread. Therefore, a subsequent patch will define a separate struct, with only 1 key, for the kernel. In preparation for that, rename the existing struct (and associated macros and functions) to reflect that they are specific to userspace. Acked-by: Catalin Marinas <[email protected]> Reviewed-by: Vincenzo Frascino <[email protected]> Signed-off-by: Kristina Martsenko <[email protected]> [Amit: Re-positioned the patch to reduce the diff] Signed-off-by: Amit Daniel Kachhap <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent cfef06b commit 91a1b6c

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

arch/arm64/include/asm/pointer_auth.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ 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+
static inline void ptrauth_keys_init_user(struct ptrauth_keys_user *keys)
3434
{
3535
if (system_supports_address_auth()) {
3636
get_random_bytes(&keys->apia, sizeof(keys->apia));
@@ -50,7 +50,7 @@ do { \
5050
write_sysreg_s(__pki_v.hi, SYS_ ## k ## KEYHI_EL1); \
5151
} while (0)
5252

53-
static inline void ptrauth_keys_switch(struct ptrauth_keys *keys)
53+
static inline void ptrauth_keys_switch_user(struct ptrauth_keys_user *keys)
5454
{
5555
if (system_supports_address_auth()) {
5656
__ptrauth_key_install(APIA, keys->apia);
@@ -80,12 +80,12 @@ static inline unsigned long ptrauth_strip_insn_pac(unsigned long ptr)
8080
#define ptrauth_thread_init_user(tsk) \
8181
do { \
8282
struct task_struct *__ptiu_tsk = (tsk); \
83-
ptrauth_keys_init(&__ptiu_tsk->thread.keys_user); \
84-
ptrauth_keys_switch(&__ptiu_tsk->thread.keys_user); \
83+
ptrauth_keys_init_user(&__ptiu_tsk->thread.keys_user); \
84+
ptrauth_keys_switch_user(&__ptiu_tsk->thread.keys_user); \
8585
} while (0)
8686

8787
#define ptrauth_thread_switch(tsk) \
88-
ptrauth_keys_switch(&(tsk)->thread.keys_user)
88+
ptrauth_keys_switch_user(&(tsk)->thread.keys_user)
8989

9090
#else /* CONFIG_ARM64_PTR_AUTH */
9191
#define ptrauth_prctl_reset_keys(tsk, arg) (-EINVAL)

arch/arm64/include/asm/processor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct thread_struct {
146146
unsigned long fault_code; /* ESR_EL1 value */
147147
struct debug_info debug; /* debugging */
148148
#ifdef CONFIG_ARM64_PTR_AUTH
149-
struct ptrauth_keys keys_user;
149+
struct ptrauth_keys_user keys_user;
150150
#endif
151151
};
152152

arch/arm64/kernel/pointer_auth.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg)
1111
{
12-
struct ptrauth_keys *keys = &tsk->thread.keys_user;
12+
struct ptrauth_keys_user *keys = &tsk->thread.keys_user;
1313
unsigned long addr_key_mask = PR_PAC_APIAKEY | PR_PAC_APIBKEY |
1414
PR_PAC_APDAKEY | PR_PAC_APDBKEY;
1515
unsigned long key_mask = addr_key_mask | PR_PAC_APGAKEY;
@@ -18,8 +18,8 @@ int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg)
1818
return -EINVAL;
1919

2020
if (!arg) {
21-
ptrauth_keys_init(keys);
22-
ptrauth_keys_switch(keys);
21+
ptrauth_keys_init_user(keys);
22+
ptrauth_keys_switch_user(keys);
2323
return 0;
2424
}
2525

@@ -41,7 +41,7 @@ int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg)
4141
if (arg & PR_PAC_APGAKEY)
4242
get_random_bytes(&keys->apga, sizeof(keys->apga));
4343

44-
ptrauth_keys_switch(keys);
44+
ptrauth_keys_switch_user(keys);
4545

4646
return 0;
4747
}

arch/arm64/kernel/ptrace.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -999,15 +999,15 @@ static struct ptrauth_key pac_key_from_user(__uint128_t ukey)
999999
}
10001000

10011001
static void pac_address_keys_to_user(struct user_pac_address_keys *ukeys,
1002-
const struct ptrauth_keys *keys)
1002+
const struct ptrauth_keys_user *keys)
10031003
{
10041004
ukeys->apiakey = pac_key_to_user(&keys->apia);
10051005
ukeys->apibkey = pac_key_to_user(&keys->apib);
10061006
ukeys->apdakey = pac_key_to_user(&keys->apda);
10071007
ukeys->apdbkey = pac_key_to_user(&keys->apdb);
10081008
}
10091009

1010-
static void pac_address_keys_from_user(struct ptrauth_keys *keys,
1010+
static void pac_address_keys_from_user(struct ptrauth_keys_user *keys,
10111011
const struct user_pac_address_keys *ukeys)
10121012
{
10131013
keys->apia = pac_key_from_user(ukeys->apiakey);
@@ -1021,7 +1021,7 @@ static int pac_address_keys_get(struct task_struct *target,
10211021
unsigned int pos, unsigned int count,
10221022
void *kbuf, void __user *ubuf)
10231023
{
1024-
struct ptrauth_keys *keys = &target->thread.keys_user;
1024+
struct ptrauth_keys_user *keys = &target->thread.keys_user;
10251025
struct user_pac_address_keys user_keys;
10261026

10271027
if (!system_supports_address_auth())
@@ -1038,7 +1038,7 @@ static int pac_address_keys_set(struct task_struct *target,
10381038
unsigned int pos, unsigned int count,
10391039
const void *kbuf, const void __user *ubuf)
10401040
{
1041-
struct ptrauth_keys *keys = &target->thread.keys_user;
1041+
struct ptrauth_keys_user *keys = &target->thread.keys_user;
10421042
struct user_pac_address_keys user_keys;
10431043
int ret;
10441044

@@ -1056,12 +1056,12 @@ static int pac_address_keys_set(struct task_struct *target,
10561056
}
10571057

10581058
static void pac_generic_keys_to_user(struct user_pac_generic_keys *ukeys,
1059-
const struct ptrauth_keys *keys)
1059+
const struct ptrauth_keys_user *keys)
10601060
{
10611061
ukeys->apgakey = pac_key_to_user(&keys->apga);
10621062
}
10631063

1064-
static void pac_generic_keys_from_user(struct ptrauth_keys *keys,
1064+
static void pac_generic_keys_from_user(struct ptrauth_keys_user *keys,
10651065
const struct user_pac_generic_keys *ukeys)
10661066
{
10671067
keys->apga = pac_key_from_user(ukeys->apgakey);
@@ -1072,7 +1072,7 @@ static int pac_generic_keys_get(struct task_struct *target,
10721072
unsigned int pos, unsigned int count,
10731073
void *kbuf, void __user *ubuf)
10741074
{
1075-
struct ptrauth_keys *keys = &target->thread.keys_user;
1075+
struct ptrauth_keys_user *keys = &target->thread.keys_user;
10761076
struct user_pac_generic_keys user_keys;
10771077

10781078
if (!system_supports_generic_auth())
@@ -1089,7 +1089,7 @@ static int pac_generic_keys_set(struct task_struct *target,
10891089
unsigned int pos, unsigned int count,
10901090
const void *kbuf, const void __user *ubuf)
10911091
{
1092-
struct ptrauth_keys *keys = &target->thread.keys_user;
1092+
struct ptrauth_keys_user *keys = &target->thread.keys_user;
10931093
struct user_pac_generic_keys user_keys;
10941094
int ret;
10951095

0 commit comments

Comments
 (0)