Skip to content

Commit eafb149

Browse files
daxtenstorvalds
authored andcommitted
fork: support VMAP_STACK with KASAN_VMALLOC
Supporting VMAP_STACK with KASAN_VMALLOC is straightforward: - clear the shadow region of vmapped stacks when swapping them in - tweak Kconfig to allow VMAP_STACK to be turned on with KASAN Link: http://lkml.kernel.org/r/20191031093909.9228-4-dja@axtens.net Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Alexander Potapenko <glider@google.com> Cc: Christophe Leroy <christophe.leroy@c-s.fr> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0651391 commit eafb149

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎arch/Kconfig‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,16 +843,17 @@ config HAVE_ARCH_VMAP_STACK
843843
config VMAP_STACK
844844
default y
845845
bool "Use a virtually-mapped stack"
846-
depends on HAVE_ARCH_VMAP_STACK && !KASAN
846+
depends on HAVE_ARCH_VMAP_STACK
847+
depends on !KASAN || KASAN_VMALLOC
847848
---help---
848849
Enable this if you want the use virtually-mapped kernel stacks
849850
with guard pages. This causes kernel stack overflows to be
850851
caught immediately rather than causing difficult-to-diagnose
851852
corruption.
852853

853-
This is presently incompatible with KASAN because KASAN expects
854-
the stack to map directly to the KASAN shadow map using a formula
855-
that is incorrect if the stack is in vmalloc space.
854+
To use this with KASAN, the architecture must support backing
855+
virtual mappings with real shadow memory, and KASAN_VMALLOC must
856+
be enabled.
856857

857858
config ARCH_OPTIONAL_KERNEL_RWX
858859
def_bool n

‎kernel/fork.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
#include <linux/livepatch.h>
9494
#include <linux/thread_info.h>
9595
#include <linux/stackleak.h>
96+
#include <linux/kasan.h>
9697

9798
#include <asm/pgtable.h>
9899
#include <asm/pgalloc.h>
@@ -223,6 +224,9 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
223224
if (!s)
224225
continue;
225226

227+
/* Clear the KASAN shadow of the stack. */
228+
kasan_unpoison_shadow(s->addr, THREAD_SIZE);
229+
226230
/* Clear stale pointers from reused stack. */
227231
memset(s->addr, 0, THREAD_SIZE);
228232

0 commit comments

Comments
 (0)