Skip to content

Commit 67840ad

Browse files
rpedgecohansendc
authored andcommitted
x86/shstk: Add ARCH_SHSTK_STATUS
CRIU and GDB need to get the current shadow stack and WRSS enablement status. This information is already available via /proc/pid/status, but this is inconvenient for CRIU because it involves parsing the text output in an area of the code where this is difficult. Provide a status arch_prctl(), ARCH_SHSTK_STATUS for retrieving the status. Have arg2 be a userspace address, and make the new arch_prctl simply copy the features out to userspace. Suggested-by: Mike Rapoport <rppt@kernel.org> 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> Acked-by: Mike Rapoport (IBM) <rppt@kernel.org> 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-43-rick.p.edgecombe%40intel.com
1 parent 680ed2f commit 67840ad

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

Documentation/arch/x86/shstk.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ arch_prctl(ARCH_SHSTK_UNLOCK, unsigned long features)
7979
Unlock features. 'features' is a mask of all features to unlock. All
8080
bits set are processed, unset bits are ignored. Only works via ptrace.
8181

82+
arch_prctl(ARCH_SHSTK_STATUS, unsigned long addr)
83+
Copy the currently enabled features to the address passed in addr. The
84+
features are described using the bits passed into the others in
85+
'features'.
86+
8287
The return values are as follows. On success, return 0. On error, errno can
8388
be::
8489

8590
-EPERM if any of the passed feature are locked.
8691
-ENOTSUPP if the feature is not supported by the hardware or
8792
kernel.
8893
-EINVAL arguments (non existing feature, etc)
94+
-EFAULT if could not copy information back to userspace
8995

9096
The feature's bits supported are::
9197

arch/x86/include/asm/shstk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct thread_shstk {
1414
u64 size;
1515
};
1616

17-
long shstk_prctl(struct task_struct *task, int option, unsigned long features);
17+
long shstk_prctl(struct task_struct *task, int option, unsigned long arg2);
1818
void reset_thread_features(void);
1919
unsigned long shstk_alloc_thread_stack(struct task_struct *p, unsigned long clone_flags,
2020
unsigned long stack_size);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define ARCH_SHSTK_DISABLE 0x5002
3535
#define ARCH_SHSTK_LOCK 0x5003
3636
#define ARCH_SHSTK_UNLOCK 0x5004
37+
#define ARCH_SHSTK_STATUS 0x5005
3738

3839
/* ARCH_SHSTK_ features bits */
3940
#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
@@ -900,6 +900,7 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
900900
case ARCH_SHSTK_DISABLE:
901901
case ARCH_SHSTK_LOCK:
902902
case ARCH_SHSTK_UNLOCK:
903+
case ARCH_SHSTK_STATUS:
903904
return shstk_prctl(task, option, arg2);
904905
default:
905906
ret = -EINVAL;

arch/x86/kernel/shstk.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,14 @@ SYSCALL_DEFINE3(map_shadow_stack, unsigned long, addr, unsigned long, size, unsi
482482
return alloc_shstk(addr, aligned_size, size, set_tok);
483483
}
484484

485-
long shstk_prctl(struct task_struct *task, int option, unsigned long features)
485+
long shstk_prctl(struct task_struct *task, int option, unsigned long arg2)
486486
{
487+
unsigned long features = arg2;
488+
489+
if (option == ARCH_SHSTK_STATUS) {
490+
return put_user(task->thread.features, (unsigned long __user *)arg2);
491+
}
492+
487493
if (option == ARCH_SHSTK_LOCK) {
488494
task->thread.features_locked |= features;
489495
return 0;

0 commit comments

Comments
 (0)