Skip to content

Commit 509ff51

Browse files
rpedgecohansendc
authored andcommitted
x86/shstk: Add warning for shadow stack double unmap
There are several ways a thread's shadow stacks can get unmapped. This can happen on exit or exec, as well as error handling in exec or clone. The task struct already keeps track of the thread's shadow stack. Use the size variable to keep track of if the shadow stack has already been freed. When an attempt to double unmap the thread shadow stack is caught, warn about it and abort the operation. Signed-off-by: Rick Edgecombe <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Tested-by: H.J. Lu <[email protected]> Link: https://lore.kernel.org/all/20230908203655.543765-4-rick.p.edgecombe%40intel.com
1 parent 748c90c commit 509ff51

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

arch/x86/kernel/shstk.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,18 @@ void shstk_free(struct task_struct *tsk)
426426
if (!shstk->base)
427427
return;
428428

429+
/*
430+
* shstk->base is NULL for CLONE_VFORK child tasks, and so is
431+
* normal. But size = 0 on a shstk->base is not normal and
432+
* indicated an attempt to free the thread shadow stack twice.
433+
* Warn about it.
434+
*/
435+
if (WARN_ON(!shstk->size))
436+
return;
437+
429438
unmap_shadow_stack(shstk->base, shstk->size);
439+
440+
shstk->size = 0;
430441
}
431442

432443
static int wrss_control(bool enable)

0 commit comments

Comments
 (0)