[PATCH v2 1/2] arch/x86: handle ARCH_SHSTK_ENABLE explicitly
From: Bill Roberts
Date: Tue Jul 07 2026 - 15:12:30 EST
The arch_prctl() handling for shadow stack operations checks that the
operation being specified is a specific value, except for the
ARCH_SHSTK_ENABLE condition, which is treated like a default case in a
switch.
However, the special handling for ARCH_SHSTK_UNLOCK is only performed when
task != current. As a result, an ARCH_SHSTK_UNLOCK request for the current
task bypasses the unlock check and falls through to the ARCH_SHSTK_ENABLE
path, causing the request to be interpreted as an enable operation
instead.
To fix this, handle ARCH_SHSTK_ENABLE explicitly rather than relying on it
as the default case. This fixes the incorrect dispatch and makes the
operation handling more robust by requiring each operation to be matched
explicitly.
Signed-off-by: Bill Roberts <bill.roberts@xxxxxxx>
---
arch/x86/kernel/shstk.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c
index 0ca64900192f..65c896d02379 100644
--- a/arch/x86/kernel/shstk.c
+++ b/arch/x86/kernel/shstk.c
@@ -607,11 +607,13 @@ long shstk_prctl(struct task_struct *task, int option, unsigned long arg2)
return -EINVAL;
}
- /* Handle ARCH_SHSTK_ENABLE */
- if (features & ARCH_SHSTK_SHSTK)
- return shstk_setup();
- if (features & ARCH_SHSTK_WRSS)
- return wrss_control(true);
+ if (option == ARCH_SHSTK_ENABLE) {
+ if (features & ARCH_SHSTK_SHSTK)
+ return shstk_setup();
+ if (features & ARCH_SHSTK_WRSS)
+ return wrss_control(true);
+ }
+
return -EINVAL;
}
--
2.54.0