arm64: Introduce prctl(PR_PAC_{SET,GET}_ENABLED_KEYS)
[linux-2.6-microblaze.git] / arch / arm64 / kernel / ptrace.c
index 170f42f..eb2f739 100644 (file)
@@ -909,6 +909,38 @@ static int pac_mask_get(struct task_struct *target,
        return membuf_write(&to, &uregs, sizeof(uregs));
 }
 
+static int pac_enabled_keys_get(struct task_struct *target,
+                               const struct user_regset *regset,
+                               struct membuf to)
+{
+       long enabled_keys = ptrauth_get_enabled_keys(target);
+
+       if (IS_ERR_VALUE(enabled_keys))
+               return enabled_keys;
+
+       return membuf_write(&to, &enabled_keys, sizeof(enabled_keys));
+}
+
+static int pac_enabled_keys_set(struct task_struct *target,
+                               const struct user_regset *regset,
+                               unsigned int pos, unsigned int count,
+                               const void *kbuf, const void __user *ubuf)
+{
+       int ret;
+       long enabled_keys = ptrauth_get_enabled_keys(target);
+
+       if (IS_ERR_VALUE(enabled_keys))
+               return enabled_keys;
+
+       ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &enabled_keys, 0,
+                                sizeof(long));
+       if (ret)
+               return ret;
+
+       return ptrauth_set_enabled_keys(target, PR_PAC_ENABLED_KEYS_MASK,
+                                       enabled_keys);
+}
+
 #ifdef CONFIG_CHECKPOINT_RESTORE
 static __uint128_t pac_key_to_user(const struct ptrauth_key *key)
 {
@@ -1074,6 +1106,7 @@ enum aarch64_regset {
 #endif
 #ifdef CONFIG_ARM64_PTR_AUTH
        REGSET_PAC_MASK,
+       REGSET_PAC_ENABLED_KEYS,
 #ifdef CONFIG_CHECKPOINT_RESTORE
        REGSET_PACA_KEYS,
        REGSET_PACG_KEYS,
@@ -1160,6 +1193,14 @@ static const struct user_regset aarch64_regsets[] = {
                .regset_get = pac_mask_get,
                /* this cannot be set dynamically */
        },
+       [REGSET_PAC_ENABLED_KEYS] = {
+               .core_note_type = NT_ARM_PAC_ENABLED_KEYS,
+               .n = 1,
+               .size = sizeof(long),
+               .align = sizeof(long),
+               .regset_get = pac_enabled_keys_get,
+               .set = pac_enabled_keys_set,
+       },
 #ifdef CONFIG_CHECKPOINT_RESTORE
        [REGSET_PACA_KEYS] = {
                .core_note_type = NT_ARM_PACA_KEYS,