]> xenbits.xensource.com Git - people/pauldu/linux.git/commitdiff
x86/shstk: Add warning for shadow stack double unmap
authorRick Edgecombe <rick.p.edgecombe@intel.com>
Fri, 8 Sep 2023 20:36:55 +0000 (13:36 -0700)
committerDave Hansen <dave.hansen@linux.intel.com>
Tue, 19 Sep 2023 16:18:34 +0000 (09:18 -0700)
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 <rick.p.edgecombe@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Tested-by: H.J. Lu <hjl.tools@gmail.com>
Link: https://lore.kernel.org/all/20230908203655.543765-4-rick.p.edgecombe%40intel.com
arch/x86/kernel/shstk.c

index ad63252ebebcd82a945be0cbb979756e581c0417..59e15dd8d0f86665ef0949b1c7072b9d25205c5e 100644 (file)
@@ -426,7 +426,18 @@ void shstk_free(struct task_struct *tsk)
        if (!shstk->base)
                return;
 
+       /*
+        * 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.
+        */
+       if (WARN_ON(!shstk->size))
+               return;
+
        unmap_shadow_stack(shstk->base, shstk->size);
+
+       shstk->size = 0;
 }
 
 static int wrss_control(bool enable)