[PATCH] x86/shstk: don't warn when the shadow stack is freed twice
From: Christian Brauner
Date: Tue Nov 24 2026 - 03:46:41 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
---
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