powerpc/32: prepare shadow area for KASAN
authorChristophe Leroy <christophe.leroy@c-s.fr>
Fri, 26 Apr 2019 16:23:32 +0000 (16:23 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 2 May 2019 15:20:26 +0000 (01:20 +1000)
This patch prepares a shadow area for KASAN.

The shadow area will be at the top of the kernel virtual
memory space above the fixmap area and will occupy one
eighth of the total kernel virtual memory space.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/Kconfig.debug
arch/powerpc/include/asm/fixmap.h
arch/powerpc/include/asm/kasan.h
arch/powerpc/mm/mem.c
arch/powerpc/mm/ptdump/ptdump.c

index 4e00cb0a54646706f7485900847fdbacf9a5dec5..61febbbdd02b357b9358d9afe3bdb8c669b76025 100644 (file)
@@ -366,3 +366,8 @@ config PPC_FAST_ENDIAN_SWITCH
         depends on DEBUG_KERNEL && PPC_BOOK3S_64
         help
          If you're unsure what this is, say N.
+
+config KASAN_SHADOW_OFFSET
+       hex
+       depends on KASAN
+       default 0xe0000000
index b9fbed84ddca40da0844933d6baaf04b2b5c52c7..0cfc365d814bae127093407aa28c612f5a4745b6 100644 (file)
 #include <asm/kmap_types.h>
 #endif
 
+#ifdef CONFIG_KASAN
+#include <asm/kasan.h>
+#define FIXADDR_TOP    (KASAN_SHADOW_START - PAGE_SIZE)
+#else
 #define FIXADDR_TOP    ((unsigned long)(-PAGE_SIZE))
+#endif
 
 /*
  * Here we define all the compile-time 'special' virtual
index 2c179a39d4ba55064a1f94ec11724cac48f79f33..05274dea310910c333c86771ca9fee4b077f6c6e 100644 (file)
 #define EXPORT_SYMBOL_KASAN(fn)
 #endif
 
+#ifndef __ASSEMBLY__
+
+#include <asm/page.h>
+
+#define KASAN_SHADOW_SCALE_SHIFT       3
+
+#define KASAN_SHADOW_START     (KASAN_SHADOW_OFFSET + \
+                                (PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT))
+
+#define KASAN_SHADOW_OFFSET    ASM_CONST(CONFIG_KASAN_SHADOW_OFFSET)
+
+#define KASAN_SHADOW_END       0UL
+
+#define KASAN_SHADOW_SIZE      (KASAN_SHADOW_END - KASAN_SHADOW_START)
+
+#endif /* __ASSEMBLY */
 #endif
index 105c58f8900aa4707950ee3c459272c914cce5c3..cd525d709072abf95c60c96bde6bd9cbc2deec48 100644 (file)
@@ -310,6 +310,10 @@ void __init mem_init(void)
        mem_init_print_info(NULL);
 #ifdef CONFIG_PPC32
        pr_info("Kernel virtual memory layout:\n");
+#ifdef CONFIG_KASAN
+       pr_info("  * 0x%08lx..0x%08lx  : kasan shadow mem\n",
+               KASAN_SHADOW_START, KASAN_SHADOW_END);
+#endif
        pr_info("  * 0x%08lx..0x%08lx  : fixmap\n", FIXADDR_START, FIXADDR_TOP);
 #ifdef CONFIG_HIGHMEM
        pr_info("  * 0x%08lx..0x%08lx  : highmem PTEs\n",
index 63fc56feea15b120b9ee53946c6bb58ba0adc271..48135ba6fa74dbc01167a7c5fab7507b5495e759 100644 (file)
@@ -100,6 +100,10 @@ static struct addr_marker address_markers[] = {
 #endif
        { 0,    "Fixmap start" },
        { 0,    "Fixmap end" },
+#endif
+#ifdef CONFIG_KASAN
+       { 0,    "kasan shadow mem start" },
+       { 0,    "kasan shadow mem end" },
 #endif
        { -1,   NULL },
 };
@@ -323,6 +327,10 @@ static void populate_markers(void)
 #endif
        address_markers[i++].start_address = FIXADDR_START;
        address_markers[i++].start_address = FIXADDR_TOP;
+#ifdef CONFIG_KASAN
+       address_markers[i++].start_address = KASAN_SHADOW_START;
+       address_markers[i++].start_address = KASAN_SHADOW_END;
+#endif
 #endif /* CONFIG_PPC64 */
 }