Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c633544a authored by Max Filippov's avatar Max Filippov
Browse files

xtensa: add support for KASAN



Cover kernel addresses above 0x90000000 by the shadow map. Enable
HAVE_ARCH_KASAN when MMU is enabled. Provide kasan_early_init that fills
shadow map with writable copies of kasan_zero_page. Call
kasan_early_init right after mmu initialization in the setup_arch.
Provide kasan_init that allocates proper shadow map pages from the
memblock and puts these pages into the shadow map for addresses from
VMALLOC area to the end of KSEG. Call kasan_init right after memblock
initialization. Don't use KASAN for the boot code, MMU and KASAN
initialization and page fault handler. Make kernel stack size 4 times
larger when KASAN is enabled to avoid stack overflows.
GCC 7.3, 8 or newer is required to build the xtensa kernel with KASAN.

Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
parent 1af1e8a3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -35,5 +35,5 @@
    |          um: | TODO |
    |   unicore32: | TODO |
    |         x86: |  ok  |
    |      xtensa: | TODO |
    |      xtensa: |  ok  |
    -----------------------
+6 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ Default MMUv2-compatible layout.
+------------------+
| Page table       |  XCHAL_PAGE_TABLE_VADDR   0x80000000  XCHAL_PAGE_TABLE_SIZE
+------------------+
| KASAN shadow map |  KASAN_SHADOW_START       0x80400000  KASAN_SHADOW_SIZE
+------------------+                           0x8e400000
+------------------+
| VMALLOC area     |  VMALLOC_START            0xc0000000  128MB - 64KB
+------------------+  VMALLOC_END
@@ -111,6 +113,8 @@ Default MMUv2-compatible layout.
+------------------+
| Page table       |  XCHAL_PAGE_TABLE_VADDR   0x80000000  XCHAL_PAGE_TABLE_SIZE
+------------------+
| KASAN shadow map |  KASAN_SHADOW_START       0x80400000  KASAN_SHADOW_SIZE
+------------------+                           0x8e400000
+------------------+
| VMALLOC area     |  VMALLOC_START            0xa0000000  128MB - 64KB
+------------------+  VMALLOC_END
@@ -152,6 +156,8 @@ Default MMUv2-compatible layout.
+------------------+
| Page table       |  XCHAL_PAGE_TABLE_VADDR   0x80000000  XCHAL_PAGE_TABLE_SIZE
+------------------+
| KASAN shadow map |  KASAN_SHADOW_START       0x80400000  KASAN_SHADOW_SIZE
+------------------+                           0x8e400000
+------------------+
| VMALLOC area     |  VMALLOC_START            0x90000000  128MB - 64KB
+------------------+  VMALLOC_END
+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ config XTENSA
	select GENERIC_IRQ_SHOW
	select GENERIC_PCI_IOMAP
	select GENERIC_SCHED_CLOCK
	select HAVE_ARCH_KASAN if MMU
	select HAVE_CC_STACKPROTECTOR
	select HAVE_DEBUG_KMEMLEAK
	select HAVE_DMA_API_DEBUG
@@ -80,6 +81,10 @@ config VARIANT_IRQ_SWITCH
config HAVE_XTENSA_GPIO32
	def_bool n

config KASAN_SHADOW_OFFSET
	hex
	default 0x6e400000

menu "Processor type and features"

choice
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ CFLAGS_REMOVE_inftrees.o = -pg
CFLAGS_REMOVE_inffast.o = -pg
endif

KASAN_SANITIZE := n

CFLAGS_REMOVE_inflate.o += -fstack-protector -fstack-protector-strong
CFLAGS_REMOVE_zmem.o += -fstack-protector -fstack-protector-strong
CFLAGS_REMOVE_inftrees.o += -fstack-protector -fstack-protector-strong
+37 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __ASM_KASAN_H
#define __ASM_KASAN_H

#ifndef __ASSEMBLY__

#ifdef CONFIG_KASAN

#include <linux/kernel.h>
#include <linux/sizes.h>
#include <asm/kmem_layout.h>

/* Start of area covered by KASAN */
#define KASAN_START_VADDR __XTENSA_UL_CONST(0x90000000)
/* Start of the shadow map */
#define KASAN_SHADOW_START (XCHAL_PAGE_TABLE_VADDR + XCHAL_PAGE_TABLE_SIZE)
/* Size of the shadow map */
#define KASAN_SHADOW_SIZE (-KASAN_START_VADDR >> KASAN_SHADOW_SCALE_SHIFT)
/* Offset for mem to shadow address transformation */
#define KASAN_SHADOW_OFFSET __XTENSA_UL_CONST(CONFIG_KASAN_SHADOW_OFFSET)

void __init kasan_early_init(void);
void __init kasan_init(void);

#else

static inline void kasan_early_init(void)
{
}

static inline void kasan_init(void)
{
}

#endif
#endif
#endif
Loading