mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/shstk: don't warn when the shadow stack is freed twice
@ 2026-11-24  8:46 Christian Brauner
  2026-11-24 15:14 ` Dave Hansen
  2026-11-24 16:26 ` [tip: x86/mm] x86/shstk: Don't " tip-bot2 for Christian Brauner
  0 siblings, 2 replies; 4+ messages in thread
From: Christian Brauner @ 2026-11-24  8:46 UTC (permalink / raw)
  To: Thomas Gleixner, Borislav Petkov
  Cc: Dave Hansen, x86, linux-kernel, stable, Christian Brauner (Amutable)

exec frees the shadow stack of the old image when it releases the old
mm in mm_exit_exec_release(). That happens right before it takes
exec_update_lock and before it switches to the new mm. If the exec fails
after that the task exits with the old mm and exit_mm() calls
mm_exit_exec_release() a second time. shstk_free() notices that the
shadow stack is gone already as shstk->size is zero and warns:

  WARNING: arch/x86/kernel/shstk.c:472 at shstk_free+0x7d/0x90, CPU#7: shstk-exec/120
  RIP: 0010:shstk_free+0x7d/0x90
  Call Trace:
   mm_exit_exec_release+0x21/0x110
   do_exit+0x1e8/0xc30
   do_group_exit+0x2e/0xd0
   get_signal+0xd11/0xd20
   arch_do_signal_or_restart+0x72/0x2b0
   exit_to_user_mode_loop+0xd8/0x560
   do_syscall_64+0x412/0x600
   entry_SYSCALL_64_after_hwframe+0x77/0x7f

All it takes is a SIGKILL while the task waits for exec_update_lock or
for the mmap lock of the old mm. Both are taken killable. And a task
that sleeps in a page fault while it holds the exec_update_lock of the
exec'ing task for reading, e.g., in readlink() of /proc/<pid>/ns/mnt,
makes that wait as long as it likes.

Nothing is unmapped twice as shstk_free() returns in that case. So just
don't warn about it.

Fixes: 509ff51ee652 ("x86/shstk: Add warning for shadow stack double unmap")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
This removes a warning that a task with a user shadow stack triggers
when its exec is killed while it waits for a lock. I have a reproducer.
---
Hey,

This also fell out of my exec massage. I was unsure whether it should go
to sec or on the list but it's just a WARN() that we need to drop. I
have a reproducer if that's needed.

Thanks!
Christian
---
 arch/x86/kernel/shstk.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c
index eb690ba90180c..df5576d8d7d2b 100644
--- a/arch/x86/kernel/shstk.c
+++ b/arch/x86/kernel/shstk.c
@@ -465,11 +465,12 @@ void shstk_free(struct task_struct *tsk)
 
 	/*
 	 * shstk->base is NULL for CLONE_VFORK child tasks, and so is
-	 * normal. But size = 0 on a shstk->base is not normal and
-	 * indicated an attempt to free the thread shadow stack twice.
-	 * Warn about it.
+	 * normal. size = 0 on a shstk->base means that the thread
+	 * shadow stack has been freed already. That happens when an
+	 * exec fails after it released the old mm as the task then
+	 * exits with the old mm and gets here a second time.
 	 */
-	if (WARN_ON(!shstk->size))
+	if (!shstk->size)
 		return;
 
 	unmap_shadow_stack(shstk->base, shstk->size);

---
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
change-id: 20261123-work-x86-shstk_free-392b68946094


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

* Re: [PATCH] x86/shstk: don't warn when the shadow stack is freed twice
  2026-11-24  8:46 [PATCH] x86/shstk: don't warn when the shadow stack is freed twice Christian Brauner
@ 2026-11-24 15:14 ` Dave Hansen
  2026-11-24 16:14   ` Christian Brauner
  2026-11-24 16:26 ` [tip: x86/mm] x86/shstk: Don't " tip-bot2 for Christian Brauner
  1 sibling, 1 reply; 4+ messages in thread
From: Dave Hansen @ 2026-11-24 15:14 UTC (permalink / raw)
  To: Christian Brauner, Thomas Gleixner, Borislav Petkov
  Cc: Dave Hansen, x86, linux-kernel, stable

On 11/24/26 00:46, Christian Brauner wrote:
> This also fell out of my exec massage. I was unsure whether it should go
> to sec or on the list but it's just a WARN() that we need to drop. I
> have a reproducer if that's needed.

I think it can just go to the lists like normal.

Thanks for the patch, btw!

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

* Re: [PATCH] x86/shstk: don't warn when the shadow stack is freed twice
  2026-11-24 15:14 ` Dave Hansen
@ 2026-11-24 16:14   ` Christian Brauner
  0 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2026-11-24 16:14 UTC (permalink / raw)
  To: Dave Hansen
  Cc: Thomas Gleixner, Borislav Petkov, Dave Hansen, x86, linux-kernel, stable

On Tue, Nov 24, 2026 at 07:14:52AM -0800, Dave Hansen wrote:
> On 11/24/26 00:46, Christian Brauner wrote:
> > This also fell out of my exec massage. I was unsure whether it should go
> > to sec or on the list but it's just a WARN() that we need to drop. I
> > have a reproducer if that's needed.
> 
> I think it can just go to the lists like normal.
> 
> Thanks for the patch, btw!

No problem. Fyi, It's on the list already.

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

* [tip: x86/mm] x86/shstk: Don't warn when the shadow stack is freed twice
  2026-11-24  8:46 [PATCH] x86/shstk: don't warn when the shadow stack is freed twice Christian Brauner
  2026-11-24 15:14 ` Dave Hansen
@ 2026-11-24 16:26 ` tip-bot2 for Christian Brauner
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Christian Brauner @ 2026-11-24 16:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Christian Brauner (Amutable), Dave Hansen, stable, x86, linux-kernel

The following commit has been merged into the x86/mm branch of tip:

Commit-ID:     b1e6233ef68ff994c924fad46a728e7191175bef
Gitweb:        https://git.kernel.org/tip/b1e6233ef68ff994c924fad46a728e7191175bef
Author:        Christian Brauner <brauner@kernel.org>
AuthorDate:    Tue, 24 Nov 2026 09:46:22 +01:00
Committer:     Dave Hansen <dave.hansen@linux.intel.com>
CommitterDate: Tue, 24 Nov 2026 08:24:44 -08:00

x86/shstk: Don't warn when the shadow stack is freed twice

exec frees the shadow stack of the old image when it releases the old
mm in mm_exit_exec_release(). That happens right before it takes
exec_update_lock and before it switches to the new mm. If the exec fails
after that the task exits with the old mm and exit_mm() calls
mm_exit_exec_release() a second time. shstk_free() notices that the
shadow stack is gone already as shstk->size is zero and warns:

  WARNING: arch/x86/kernel/shstk.c:472 at shstk_free+0x7d/0x90, CPU#7: shstk-exec/120
  RIP: 0010:shstk_free+0x7d/0x90
  Call Trace:
   mm_exit_exec_release+0x21/0x110
   do_exit+0x1e8/0xc30
   do_group_exit+0x2e/0xd0
   get_signal+0xd11/0xd20
   arch_do_signal_or_restart+0x72/0x2b0
   exit_to_user_mode_loop+0xd8/0x560
   do_syscall_64+0x412/0x600
   entry_SYSCALL_64_after_hwframe+0x77/0x7f

All it takes is a SIGKILL while the task waits for exec_update_lock or
for the mmap lock of the old mm. Both are taken killable. And a task
that sleeps in a page fault while it holds the exec_update_lock of the
exec'ing task for reading, e.g., in readlink() of /proc/<pid>/ns/mnt,
makes that wait as long as it likes.

Nothing is unmapped twice as shstk_free() returns in that case. So just
don't warn about it.

Fixes: 509ff51ee652 ("x86/shstk: Add warning for shadow stack double unmap")
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc:stable@vger.kernel.org
Link: https://patch.msgid.link/20261124-work-x86-shstk_free-v1-1-fc456c538e70@kernel.org
---
 arch/x86/kernel/shstk.c |  9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c
index eb690ba..df5576d 100644
--- a/arch/x86/kernel/shstk.c
+++ b/arch/x86/kernel/shstk.c
@@ -465,11 +465,12 @@ void shstk_free(struct task_struct *tsk)
 
 	/*
 	 * shstk->base is NULL for CLONE_VFORK child tasks, and so is
-	 * normal. But size = 0 on a shstk->base is not normal and
-	 * indicated an attempt to free the thread shadow stack twice.
-	 * Warn about it.
+	 * normal. size = 0 on a shstk->base means that the thread
+	 * shadow stack has been freed already. That happens when an
+	 * exec fails after it released the old mm as the task then
+	 * exits with the old mm and gets here a second time.
 	 */
-	if (WARN_ON(!shstk->size))
+	if (!shstk->size)
 		return;
 
 	unmap_shadow_stack(shstk->base, shstk->size);

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

end of thread, other threads:[~2026-11-24 16:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24  8:46 [PATCH] x86/shstk: don't warn when the shadow stack is freed twice Christian Brauner
2026-11-24 15:14 ` Dave Hansen
2026-11-24 16:14   ` Christian Brauner
2026-11-24 16:26 ` [tip: x86/mm] x86/shstk: Don't " tip-bot2 for Christian Brauner

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®