Skip to content

Commit b2f557e

Browse files
xairytorvalds
authored andcommitted
kasan, arm64: adjust shadow size for tag-based mode
Tag-based KASAN uses 1 shadow byte for 16 bytes of kernel memory, so it requires 1/16th of the kernel virtual address space for the shadow memory. This commit sets KASAN_SHADOW_SCALE_SHIFT to 4 when the tag-based KASAN mode is enabled. Link: http://lkml.kernel.org/r/308b6bd49f756bb5e533be93c6f085ba99b30339.1544099024.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Acked-by: Will Deacon <will.deacon@arm.com> Cc: Christoph Lameter <cl@linux.com> Cc: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2bd926b commit b2f557e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

arch/arm64/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,19 @@ else
101101
TEXT_OFFSET := 0x00080000
102102
endif
103103

104+
ifeq ($(CONFIG_KASAN_SW_TAGS), y)
105+
KASAN_SHADOW_SCALE_SHIFT := 4
106+
else
107+
KASAN_SHADOW_SCALE_SHIFT := 3
108+
endif
109+
110+
KBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
111+
KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
112+
KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
113+
104114
# KASAN_SHADOW_OFFSET = VA_START + (1 << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT))
105115
# - (1 << (64 - KASAN_SHADOW_SCALE_SHIFT))
106116
# in 32-bit arithmetic
107-
KASAN_SHADOW_SCALE_SHIFT := 3
108117
KASAN_SHADOW_OFFSET := $(shell printf "0x%08x00000000\n" $$(( \
109118
(0xffffffff & (-1 << ($(CONFIG_ARM64_VA_BITS) - 32))) \
110119
+ (1 << ($(CONFIG_ARM64_VA_BITS) - 32 - $(KASAN_SHADOW_SCALE_SHIFT))) \

arch/arm64/include/asm/memory.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,11 @@
7474
#endif
7575

7676
/*
77-
* KASAN requires 1/8th of the kernel virtual address space for the shadow
78-
* region. KASAN can bloat the stack significantly, so double the (minimum)
79-
* stack size when KASAN is in use, and then double it again if KASAN_EXTRA is
80-
* on.
77+
* Generic and tag-based KASAN require 1/8th and 1/16th of the kernel virtual
78+
* address space for the shadow region respectively. They can bloat the stack
79+
* significantly, so double the (minimum) stack size when they are in use.
8180
*/
8281
#ifdef CONFIG_KASAN
83-
#define KASAN_SHADOW_SCALE_SHIFT 3
8482
#define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT))
8583
#ifdef CONFIG_KASAN_EXTRA
8684
#define KASAN_THREAD_SHIFT 2

0 commit comments

Comments
 (0)