Skip to content

Commit 680ed2f

Browse files
rppthansendc
authored andcommitted
x86/shstk: Add ARCH_SHSTK_UNLOCK
Userspace loaders may lock features before a CRIU restore operation has the chance to set them to whatever state is required by the process being restored. Allow a way for CRIU to unlock features. Add it as an arch_prctl() like the other shadow stack operations, but restrict it being called by the ptrace arch_pctl() interface. [Merged into recent API changes, added commit log and docs] Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: David Hildenbrand <david@redhat.com> Tested-by: Pengfei Xu <pengfei.xu@intel.com> Tested-by: John Allen <john.allen@amd.com> Tested-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/all/20230613001108.3040476-42-rick.p.edgecombe%40intel.com
1 parent 2fab02b commit 680ed2f

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

Documentation/arch/x86/shstk.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ arch_prctl(ARCH_SHSTK_LOCK, unsigned long features)
7575
are ignored. The mask is ORed with the existing value. So any feature bits
7676
set here cannot be enabled or disabled afterwards.
7777

78+
arch_prctl(ARCH_SHSTK_UNLOCK, unsigned long features)
79+
Unlock features. 'features' is a mask of all features to unlock. All
80+
bits set are processed, unset bits are ignored. Only works via ptrace.
81+
7882
The return values are as follows. On success, return 0. On error, errno can
7983
be::
8084

arch/x86/include/uapi/asm/prctl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define ARCH_SHSTK_ENABLE 0x5001
3434
#define ARCH_SHSTK_DISABLE 0x5002
3535
#define ARCH_SHSTK_LOCK 0x5003
36+
#define ARCH_SHSTK_UNLOCK 0x5004
3637

3738
/* ARCH_SHSTK_ features bits */
3839
#define ARCH_SHSTK_SHSTK (1ULL << 0)

arch/x86/kernel/process_64.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
899899
case ARCH_SHSTK_ENABLE:
900900
case ARCH_SHSTK_DISABLE:
901901
case ARCH_SHSTK_LOCK:
902+
case ARCH_SHSTK_UNLOCK:
902903
return shstk_prctl(task, option, arg2);
903904
default:
904905
ret = -EINVAL;

arch/x86/kernel/shstk.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,14 @@ long shstk_prctl(struct task_struct *task, int option, unsigned long features)
489489
return 0;
490490
}
491491

492-
/* Don't allow via ptrace */
493-
if (task != current)
492+
/* Only allow via ptrace */
493+
if (task != current) {
494+
if (option == ARCH_SHSTK_UNLOCK && IS_ENABLED(CONFIG_CHECKPOINT_RESTORE)) {
495+
task->thread.features_locked &= ~features;
496+
return 0;
497+
}
494498
return -EINVAL;
499+
}
495500

496501
/* Do not allow to change locked features */
497502
if (features & task->thread.features_locked)

0 commit comments

Comments
 (0)