-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x86: Introduce userspace API for shadow stack
Add three new arch_prctl() handles: - ARCH_SHSTK_ENABLE/DISABLE enables or disables the specified feature. Returns 0 on success or a negative value on error. - ARCH_SHSTK_LOCK prevents future disabling or enabling of the specified feature. Returns 0 on success or a negative value on error. The features are handled per-thread and inherited over fork(2)/clone(2), but reset on exec(). Co-developed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.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> 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-27-rick.p.edgecombe%40intel.com
- Loading branch information
Rick Edgecombe
authored and
Dave Hansen
committed
Aug 2, 2023
1 parent
6ee8366
commit 98cfa46
Showing
6 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef _ASM_X86_SHSTK_H | ||
#define _ASM_X86_SHSTK_H | ||
|
||
#ifndef __ASSEMBLY__ | ||
#include <linux/types.h> | ||
|
||
struct task_struct; | ||
|
||
#ifdef CONFIG_X86_USER_SHADOW_STACK | ||
long shstk_prctl(struct task_struct *task, int option, unsigned long features); | ||
void reset_thread_features(void); | ||
#else | ||
static inline long shstk_prctl(struct task_struct *task, int option, | ||
unsigned long arg2) { return -EINVAL; } | ||
static inline void reset_thread_features(void) {} | ||
#endif /* CONFIG_X86_USER_SHADOW_STACK */ | ||
|
||
#endif /* __ASSEMBLY__ */ | ||
|
||
#endif /* _ASM_X86_SHSTK_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* shstk.c - Intel shadow stack support | ||
* | ||
* Copyright (c) 2021, Intel Corporation. | ||
* Yu-cheng Yu <yu-cheng.yu@intel.com> | ||
*/ | ||
|
||
#include <linux/sched.h> | ||
#include <linux/bitops.h> | ||
#include <asm/prctl.h> | ||
|
||
void reset_thread_features(void) | ||
{ | ||
current->thread.features = 0; | ||
current->thread.features_locked = 0; | ||
} | ||
|
||
long shstk_prctl(struct task_struct *task, int option, unsigned long features) | ||
{ | ||
if (option == ARCH_SHSTK_LOCK) { | ||
task->thread.features_locked |= features; | ||
return 0; | ||
} | ||
|
||
/* Don't allow via ptrace */ | ||
if (task != current) | ||
return -EINVAL; | ||
|
||
/* Do not allow to change locked features */ | ||
if (features & task->thread.features_locked) | ||
return -EPERM; | ||
|
||
/* Only support enabling/disabling one feature at a time. */ | ||
if (hweight_long(features) > 1) | ||
return -EINVAL; | ||
|
||
if (option == ARCH_SHSTK_DISABLE) { | ||
return -EINVAL; | ||
} | ||
|
||
/* Handle ARCH_SHSTK_ENABLE */ | ||
return -EINVAL; | ||
} |