arm64: add KASAN support
authorAndrey Ryabinin <ryabinin.a.a@gmail.com>
Tue, 11 Aug 2015 02:18:18 +0000 (05:18 +0300)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 14 Dec 2016 04:49:38 +0000 (13:49 +0900)
commit1f2757b45f7a29b1363944bc53c7895d8843e882
tree769f62ff0b335971a9b265c87f3a29cfe98f5463
parentdedc7254abe8e9ee71aadf378927ea8522d82c9d
arm64: add KASAN support

This patch adds arch specific code for kernel address sanitizer
(see Documentation/kasan.txt).

1/8 of kernel addresses reserved for shadow memory. There was no
big enough hole for this, so virtual addresses for shadow were
stolen from vmalloc area.

At early boot stage the whole shadow region populated with just
one physical page (kasan_zero_page). Later, this page reused
as readonly zero shadow for some memory that KASan currently
don't track (vmalloc).
After mapping the physical memory, pages for shadow memory are
allocated and mapped.

Functions like memset/memmove/memcpy do a lot of memory accesses.
If bad pointer passed to one of these function it is important
to catch this. Compiler's instrumentation cannot do this since
these functions are written in assembly.
KASan replaces memory functions with manually instrumented variants.
Original functions declared as weak symbols so strong definitions
in mm/kasan/kasan.c could replace them. Original functions have aliases
with '__' prefix in name, so we could call non-instrumented variant
if needed.
Some files built without kasan instrumentation (e.g. mm/slub.c).
Original mem* function replaced (via #define) with prefixed variants
to disable memory access checks for such files.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
15 files changed:
arch/arm64/Kconfig
arch/arm64/Makefile
arch/arm64/include/asm/kasan.h [new file with mode: 0644]
arch/arm64/include/asm/pgtable.h
arch/arm64/include/asm/string.h
arch/arm64/kernel/arm64ksyms.c
arch/arm64/kernel/head.S
arch/arm64/kernel/module.c
arch/arm64/kernel/setup.c
arch/arm64/lib/memcpy.S
arch/arm64/lib/memmove.S
arch/arm64/lib/memset.S
arch/arm64/mm/Makefile
arch/arm64/mm/kasan_init.c [new file with mode: 0644]
scripts/Makefile.kasan