1 /* SPDX-License-Identifier: GPL-2.0 */
3 * arch/arm/include/asm/kasan_def.h
5 * Copyright (c) 2018 Huawei Technologies Co., Ltd.
7 * Author: Abbott Liu <liuwenliang@huawei.com>
10 #ifndef __ASM_KASAN_DEF_H
11 #define __ASM_KASAN_DEF_H
16 * Define KASAN_SHADOW_OFFSET,KASAN_SHADOW_START and KASAN_SHADOW_END for
17 * the Arm kernel address sanitizer. We are "stealing" lowmem (the 4GB
18 * addressable by a 32bit architecture) out of the virtual address
19 * space to use as shadow memory for KASan as follows:
23 * | | |-> Static kernel image (vmlinux) BSS and page table
27 * | | |-> Loadable kernel modules virtual address space area
29 * +----+ MODULES_VADDR = KASAN_SHADOW_END
31 * | | |-> The shadow area of kernel virtual address.
33 * +----+-> TASK_SIZE (start of kernel space) = KASAN_SHADOW_START the
34 * | |\ shadow address of MODULES_VADDR
37 * | | |-> The user space area in lowmem. The kernel address
38 * | | | sanitizer do not use this space, nor does it map it.
46 * 1) KASAN_SHADOW_START
47 * This value begins with the MODULE_VADDR's shadow address. It is the
48 * start of kernel virtual space. Since we have modules to load, we need
49 * to cover also that area with shadow memory so we can find memory
53 * This value is the 0x100000000's shadow address: the mapping that would
54 * be after the end of the kernel memory at 0xffffffff. It is the end of
55 * kernel address sanitizer shadow area. It is also the start of the
58 * 3) KASAN_SHADOW_OFFSET:
59 * This value is used to map an address to the corresponding shadow
60 * address by the following formula:
62 * shadow_addr = (address >> 3) + KASAN_SHADOW_OFFSET;
64 * As you would expect, >> 3 is equal to dividing by 8, meaning each
65 * byte in the shadow memory covers 8 bytes of kernel memory, so one
66 * bit shadow memory per byte of kernel memory is used.
68 * The KASAN_SHADOW_OFFSET is provided in a Kconfig option depending
69 * on the VMSPLIT layout of the system: the kernel and userspace can
70 * split up lowmem in different ways according to needs, so we calculate
71 * the shadow offset depending on this.
74 #define KASAN_SHADOW_SCALE_SHIFT 3
75 #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
76 #define KASAN_SHADOW_END ((UL(1) << (32 - KASAN_SHADOW_SCALE_SHIFT)) \
77 + KASAN_SHADOW_OFFSET)
78 #define KASAN_SHADOW_START ((KASAN_SHADOW_END >> 3) + KASAN_SHADOW_OFFSET)