mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RESEND v2 1/2] arch/x86: handle ARCH_SHSTK_ENABLE explicitly
@ 2026-11-02 18:17 Bill Roberts
  2026-11-02 18:17 ` [PATCH RESEND v2 2/2] selftest/x86: test ARCH_SHSTK_UNLOCK Bill Roberts
  2026-11-30 23:09 ` [PATCH RESEND v2 1/2] arch/x86: handle ARCH_SHSTK_ENABLE explicitly Dave Hansen
  0 siblings, 2 replies; 4+ messages in thread
From: Bill Roberts @ 2026-11-02 18:17 UTC (permalink / raw)
  To: H. Peter Anvin, Borislav Petkov, Dave Hansen, Ingo Molnar,
	rick.p.edgecombe, Shuah Khan, Thomas Gleixner, x86
  Cc: linux-kernel, linux-kselftest, Bill Roberts

On x86 user shadow stack is controlled via an arch_prctl() interface, in
order to allow ptrace to actuate some of the options, and allow normal
syscall execution of arch_prctl() to execute others. Only valid shadow stack
options, for both ptrace and normal userspace callers, are directed into the
shstk_prctl() handler via checking in do_arch_prctl_64(). Then in
shstk_prctl(), it differentiates ptrace callers by checking if task !=
current.

The trouble starts when the handling of the task == current (normal syscall)
case treats the enabling option, ARCH_SHSTK_ENABLE, like a default case. It
reasons that shstk_prctl() has handled all other possible shadow stack
options, so ARCH_SHSTK_ENABLE can be the only remaining. Or so it thinks.
Because the ARCH_SHSTK_UNLOCK option is only handled in the ptrace case.
Since it has no handler in the syscall case, ARCH_SHSTK_UNLOCK can get
misinterpreted as ARCH_SHSTK_ENABLE by the erroneous default case logic.

The impact is that doing an arch_prtcl(ARCH_SHSTK_UNLOCK) syscall actually
behaves like an arch_prtcl(ARCH_SHSTK_ENABLE) syscall. This is a surprising
behavior, but does not expose any control to userspace that it doesn't
already have.

So drop the buggy default assumptions by checking for ARCH_SHSTK_ENABLE
explicitly.

Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Bill Roberts <bill.roberts@arm.com>
---
 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 eb690ba90180..8deed118040c 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.55.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH RESEND v2 2/2] selftest/x86: test ARCH_SHSTK_UNLOCK
  2026-11-02 18:17 [PATCH RESEND v2 1/2] arch/x86: handle ARCH_SHSTK_ENABLE explicitly Bill Roberts
@ 2026-11-02 18:17 ` Bill Roberts
  2026-11-09 18:34   ` Bill Roberts
  2026-11-30 23:09 ` [PATCH RESEND v2 1/2] arch/x86: handle ARCH_SHSTK_ENABLE explicitly Dave Hansen
  1 sibling, 1 reply; 4+ messages in thread
From: Bill Roberts @ 2026-11-02 18:17 UTC (permalink / raw)
  To: H. Peter Anvin, Borislav Petkov, Dave Hansen, Ingo Molnar,
	rick.p.edgecombe, Shuah Khan, Thomas Gleixner, x86
  Cc: linux-kernel, linux-kselftest, Bill Roberts

Test that ARCH_SHSTK_UNLOCK can't be called from normal (non-ptrace)
context.

Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Bill Roberts <bill.roberts@arm.com>
---
 tools/testing/selftests/x86/test_shadow_stack.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/testing/selftests/x86/test_shadow_stack.c b/tools/testing/selftests/x86/test_shadow_stack.c
index 3d6ca33edba4..cbe7ca4ebd90 100644
--- a/tools/testing/selftests/x86/test_shadow_stack.c
+++ b/tools/testing/selftests/x86/test_shadow_stack.c
@@ -1059,6 +1059,14 @@ int main(int argc, char *argv[])
 {
 	int ret = 0;
 
+	/* Test that ARCH_SHSTK_UNLOCK can't be called from normal (non-ptrace) context. */
+	if (!ARCH_PRCTL(ARCH_SHSTK_UNLOCK, ARCH_SHSTK_SHSTK)) {
+		printf("[FAIL]\tARCH_SHSTK_UNLOCK should fail in a non-ptrace context\n");
+		goto out;
+	}
+
+	printf("[OK]\tCouldn't enable Shadow stack via UNLOCK\n");
+
 	if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_SHSTK)) {
 		printf("[SKIP]\tCould not enable Shadow stack\n");
 		return 1;
-- 
2.55.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH RESEND v2 2/2] selftest/x86: test ARCH_SHSTK_UNLOCK
  2026-11-02 18:17 ` [PATCH RESEND v2 2/2] selftest/x86: test ARCH_SHSTK_UNLOCK Bill Roberts
@ 2026-11-09 18:34   ` Bill Roberts
  0 siblings, 0 replies; 4+ messages in thread
From: Bill Roberts @ 2026-11-09 18:34 UTC (permalink / raw)
  To: bill.roberts, dave.hansen, rick.p.edgecombe
  Cc: bp, hpa, linux-kernel, linux-kselftest, mingo, shuah, tglx, x86

Hi,

Just following up on this series to see if there are any outstanding
concerns or if anything else is needed before it can be picked up.

Thanks,
Bill

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH RESEND v2 1/2] arch/x86: handle ARCH_SHSTK_ENABLE explicitly
  2026-11-02 18:17 [PATCH RESEND v2 1/2] arch/x86: handle ARCH_SHSTK_ENABLE explicitly Bill Roberts
  2026-11-02 18:17 ` [PATCH RESEND v2 2/2] selftest/x86: test ARCH_SHSTK_UNLOCK Bill Roberts
@ 2026-11-30 23:09 ` Dave Hansen
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Hansen @ 2026-11-30 23:09 UTC (permalink / raw)
  To: Bill Roberts, H. Peter Anvin, Borislav Petkov, Dave Hansen,
	Ingo Molnar, rick.p.edgecombe, Shuah Khan, Thomas Gleixner, x86
  Cc: linux-kernel, linux-kselftest

While I applaud the restraint in just having an LLM write the changelog,
I had a really hard time reading this. How does this (LLM-assisted)
version look? It feels more readable to me.

--

x86/shstk: Don't treat 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30 23:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 18:17 [PATCH RESEND v2 1/2] arch/x86: handle ARCH_SHSTK_ENABLE explicitly Bill Roberts
2026-11-02 18:17 ` [PATCH RESEND v2 2/2] selftest/x86: test ARCH_SHSTK_UNLOCK Bill Roberts
2026-11-09 18:34   ` Bill Roberts
2026-11-30 23:09 ` [PATCH RESEND v2 1/2] arch/x86: handle ARCH_SHSTK_ENABLE explicitly Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®