[tip: x86/mm] x86/shstk: Avoid accidentally treating ARCH_SHSTK_UNLOCK as ARCH_SHSTK_ENABLE
From: tip-bot2 for Bill Roberts
Date: Tue Dec 01 2026 - 18:41:15 EST
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 4ce4f49da646a7775fc6359ce5abb396725b77ad
Gitweb: https://git.kernel.org/tip/4ce4f49da646a7775fc6359ce5abb396725b77ad
Author: Bill Roberts <bill.roberts@xxxxxxx>
AuthorDate: Mon, 02 Nov 2026 12:17:07 -06:00
Committer: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
CommitterDate: Tue, 01 Dec 2026 15:32:19 -08:00
x86/shstk: Avoid accidentally treating ARCH_SHSTK_UNLOCK as ARCH_SHSTK_ENABLE
On x86, normal arch_prctl() syscalls and ptrace() callers share
shstk_prctl() to control user shadow stack. It identifies ptrace()
callers by 'task != current'.
ARCH_SHSTK_UNLOCK is only meant for ptrace() callers. Normal syscall
callers should never use it. If they do, they accidentally get
ARCH_SHSTK_ENABLE behavior.
This happens because ARCH_SHSTK_UNLOCK is handled only in the ptrace
case. In the 'task == current' case, shstk_prctl() handles the other
options and assumes that any remaining one is ARCH_SHSTK_ENABLE, so
ARCH_SHSTK_UNLOCK falls through to the enable path.
This is surprising behavior, but does not give userspace any control
that it doesn't already have.
Check for ARCH_SHSTK_ENABLE explicitly and return -EINVAL for any
unhandled option.
[ dhansen+llm: rewrite changelog ]
Signed-off-by: Bill Roberts <bill.roberts@xxxxxxx>
Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
Link: https://patch.msgid.link/20261102181708.29178-1-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 df5576d..36ee353 100644
--- a/arch/x86/kernel/shstk.c
+++ b/arch/x86/kernel/shstk.c
@@ -608,11 +608,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;
}