diff options
author | Andrey Konovalov <andreyknvl@google.com> | 2018-12-28 03:29:53 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-12-28 15:11:43 -0500 |
commit | 2bd926b439b4cb6b9ed240a9781cd01958b53d85 (patch) | |
tree | bfdd9f2a3f0111b3a3510032aabdc6f90ce73ed4 | |
parent | b938fcf42739de8270e6ea41593722929c8a7dd0 (diff) |
kasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS
This commit splits the current CONFIG_KASAN config option into two:
1. CONFIG_KASAN_GENERIC, that enables the generic KASAN mode (the one
that exists now);
2. CONFIG_KASAN_SW_TAGS, that enables the software tag-based KASAN mode.
The name CONFIG_KASAN_SW_TAGS is chosen as in the future we will have
another hardware tag-based KASAN mode, that will rely on hardware memory
tagging support in arm64.
With CONFIG_KASAN_SW_TAGS enabled, compiler options are changed to
instrument kernel files with -fsantize=kernel-hwaddress (except the ones
for which KASAN_SANITIZE := n is set).
Both CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS support both
CONFIG_KASAN_INLINE and CONFIG_KASAN_OUTLINE instrumentation modes.
This commit also adds empty placeholder (for now) implementation of
tag-based KASAN specific hooks inserted by the compiler and adjusts
common hooks implementation.
While this commit adds the CONFIG_KASAN_SW_TAGS config option, this option
is not selectable, as it depends on HAVE_ARCH_KASAN_SW_TAGS, which we will
enable once all the infrastracture code has been added.
Link: http://lkml.kernel.org/r/b2550106eb8a68b10fefbabce820910b115aa853.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>
Cc: Christoph Lameter <cl@linux.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/compiler-clang.h | 6 | ||||
-rw-r--r-- | include/linux/compiler-gcc.h | 6 | ||||
-rw-r--r-- | include/linux/compiler_attributes.h | 13 | ||||
-rw-r--r-- | include/linux/kasan.h | 16 | ||||
-rw-r--r-- | lib/Kconfig.kasan | 98 | ||||
-rw-r--r-- | mm/kasan/Makefile | 6 | ||||
-rw-r--r-- | mm/kasan/generic.c | 2 | ||||
-rw-r--r-- | mm/kasan/kasan.h | 3 | ||||
-rw-r--r-- | mm/kasan/tags.c | 75 | ||||
-rw-r--r-- | mm/slub.c | 2 | ||||
-rw-r--r-- | scripts/Makefile.kasan | 53 |
11 files changed, 214 insertions, 66 deletions
diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index 3e7dafb3ea80..39f668d5066b 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h | |||
@@ -16,9 +16,13 @@ | |||
16 | /* all clang versions usable with the kernel support KASAN ABI version 5 */ | 16 | /* all clang versions usable with the kernel support KASAN ABI version 5 */ |
17 | #define KASAN_ABI_VERSION 5 | 17 | #define KASAN_ABI_VERSION 5 |
18 | 18 | ||
19 | #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer) | ||
19 | /* emulate gcc's __SANITIZE_ADDRESS__ flag */ | 20 | /* emulate gcc's __SANITIZE_ADDRESS__ flag */ |
20 | #if __has_feature(address_sanitizer) | ||
21 | #define __SANITIZE_ADDRESS__ | 21 | #define __SANITIZE_ADDRESS__ |
22 | #define __no_sanitize_address \ | ||
23 | __attribute__((no_sanitize("address", "hwaddress"))) | ||
24 | #else | ||
25 | #define __no_sanitize_address | ||
22 | #endif | 26 | #endif |
23 | 27 | ||
24 | /* | 28 | /* |
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 2010493e1040..5776da43da97 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h | |||
@@ -143,6 +143,12 @@ | |||
143 | #define KASAN_ABI_VERSION 3 | 143 | #define KASAN_ABI_VERSION 3 |
144 | #endif | 144 | #endif |
145 | 145 | ||
146 | #if __has_attribute(__no_sanitize_address__) | ||
147 | #define __no_sanitize_address __attribute__((no_sanitize_address)) | ||
148 | #else | ||
149 | #define __no_sanitize_address | ||
150 | #endif | ||
151 | |||
146 | #if GCC_VERSION >= 50100 | 152 | #if GCC_VERSION >= 50100 |
147 | #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 | 153 | #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 |
148 | #endif | 154 | #endif |
diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index fe07b680dd4a..19f32b0c29af 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h | |||
@@ -200,19 +200,6 @@ | |||
200 | #define __noreturn __attribute__((__noreturn__)) | 200 | #define __noreturn __attribute__((__noreturn__)) |
201 | 201 | ||
202 | /* | 202 | /* |
203 | * Optional: only supported since gcc >= 4.8 | ||
204 | * Optional: not supported by icc | ||
205 | * | ||
206 | * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fsanitize_005faddress-function-attribute | ||
207 | * clang: https://clang.llvm.org/docs/AttributeReference.html#no-sanitize-address-no-address-safety-analysis | ||
208 | */ | ||
209 | #if __has_attribute(__no_sanitize_address__) | ||
210 | # define __no_sanitize_address __attribute__((__no_sanitize_address__)) | ||
211 | #else | ||
212 | # define __no_sanitize_address | ||
213 | #endif | ||
214 | |||
215 | /* | ||
216 | * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute | 203 | * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute |
217 | * clang: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-packed-variable-attribute | 204 | * clang: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-packed-variable-attribute |
218 | */ | 205 | */ |
diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 52c86a568a4e..b66fdf5ea7ab 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h | |||
@@ -45,8 +45,6 @@ void kasan_free_pages(struct page *page, unsigned int order); | |||
45 | 45 | ||
46 | void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, | 46 | void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, |
47 | slab_flags_t *flags); | 47 | slab_flags_t *flags); |
48 | void kasan_cache_shrink(struct kmem_cache *cache); | ||
49 | void kasan_cache_shutdown(struct kmem_cache *cache); | ||
50 | 48 | ||
51 | void kasan_poison_slab(struct page *page); | 49 | void kasan_poison_slab(struct page *page); |
52 | void kasan_unpoison_object_data(struct kmem_cache *cache, void *object); | 50 | void kasan_unpoison_object_data(struct kmem_cache *cache, void *object); |
@@ -97,8 +95,6 @@ static inline void kasan_free_pages(struct page *page, unsigned int order) {} | |||
97 | static inline void kasan_cache_create(struct kmem_cache *cache, | 95 | static inline void kasan_cache_create(struct kmem_cache *cache, |
98 | unsigned int *size, | 96 | unsigned int *size, |
99 | slab_flags_t *flags) {} | 97 | slab_flags_t *flags) {} |
100 | static inline void kasan_cache_shrink(struct kmem_cache *cache) {} | ||
101 | static inline void kasan_cache_shutdown(struct kmem_cache *cache) {} | ||
102 | 98 | ||
103 | static inline void kasan_poison_slab(struct page *page) {} | 99 | static inline void kasan_poison_slab(struct page *page) {} |
104 | static inline void kasan_unpoison_object_data(struct kmem_cache *cache, | 100 | static inline void kasan_unpoison_object_data(struct kmem_cache *cache, |
@@ -155,4 +151,16 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } | |||
155 | 151 | ||
156 | #endif /* CONFIG_KASAN */ | 152 | #endif /* CONFIG_KASAN */ |
157 | 153 | ||
154 | #ifdef CONFIG_KASAN_GENERIC | ||
155 | |||
156 | void kasan_cache_shrink(struct kmem_cache *cache); | ||
157 | void kasan_cache_shutdown(struct kmem_cache *cache); | ||
158 | |||
159 | #else /* CONFIG_KASAN_GENERIC */ | ||
160 | |||
161 | static inline void kasan_cache_shrink(struct kmem_cache *cache) {} | ||
162 | static inline void kasan_cache_shutdown(struct kmem_cache *cache) {} | ||
163 | |||
164 | #endif /* CONFIG_KASAN_GENERIC */ | ||
165 | |||
158 | #endif /* LINUX_KASAN_H */ | 166 | #endif /* LINUX_KASAN_H */ |
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index d0bad1bd9a2b..d8c474b6691e 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan | |||
@@ -1,36 +1,92 @@ | |||
1 | # This config refers to the generic KASAN mode. | ||
1 | config HAVE_ARCH_KASAN | 2 | config HAVE_ARCH_KASAN |
2 | bool | 3 | bool |
3 | 4 | ||
4 | if HAVE_ARCH_KASAN | 5 | config HAVE_ARCH_KASAN_SW_TAGS |
6 | bool | ||
7 | |||
8 | config CC_HAS_KASAN_GENERIC | ||
9 | def_bool $(cc-option, -fsanitize=kernel-address) | ||
10 | |||
11 | config CC_HAS_KASAN_SW_TAGS | ||
12 | def_bool $(cc-option, -fsanitize=kernel-hwaddress) | ||
5 | 13 | ||
6 | config KASAN | 14 | config KASAN |
7 | bool "KASan: runtime memory debugger" | 15 | bool "KASAN: runtime memory debugger" |
16 | depends on (HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \ | ||
17 | (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS) | ||
18 | depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) | ||
19 | help | ||
20 | Enables KASAN (KernelAddressSANitizer) - runtime memory debugger, | ||
21 | designed to find out-of-bounds accesses and use-after-free bugs. | ||
22 | See Documentation/dev-tools/kasan.rst for details. | ||
23 | |||
24 | choice | ||
25 | prompt "KASAN mode" | ||
26 | depends on KASAN | ||
27 | default KASAN_GENERIC | ||
28 | help | ||
29 | KASAN has two modes: generic KASAN (similar to userspace ASan, | ||
30 | x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC) and | ||
31 | software tag-based KASAN (a version based on software memory | ||
32 | tagging, arm64 only, similar to userspace HWASan, enabled with | ||
33 | CONFIG_KASAN_SW_TAGS). | ||
34 | Both generic and tag-based KASAN are strictly debugging features. | ||
35 | |||
36 | config KASAN_GENERIC | ||
37 | bool "Generic mode" | ||
38 | depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC | ||
8 | depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) | 39 | depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) |
9 | select SLUB_DEBUG if SLUB | 40 | select SLUB_DEBUG if SLUB |
10 | select CONSTRUCTORS | 41 | select CONSTRUCTORS |
11 | select STACKDEPOT | 42 | select STACKDEPOT |
12 | help | 43 | help |
13 | Enables kernel address sanitizer - runtime memory debugger, | 44 | Enables generic KASAN mode. |
14 | designed to find out-of-bounds accesses and use-after-free bugs. | 45 | Supported in both GCC and Clang. With GCC it requires version 4.9.2 |
15 | This is strictly a debugging feature and it requires a gcc version | 46 | or later for basic support and version 5.0 or later for detection of |
16 | of 4.9.2 or later. Detection of out of bounds accesses to stack or | 47 | out-of-bounds accesses for stack and global variables and for inline |
17 | global variables requires gcc 5.0 or later. | 48 | instrumentation mode (CONFIG_KASAN_INLINE). With Clang it requires |
18 | This feature consumes about 1/8 of available memory and brings about | 49 | version 3.7.0 or later and it doesn't support detection of |
19 | ~x3 performance slowdown. | 50 | out-of-bounds accesses for global variables yet. |
51 | This mode consumes about 1/8th of available memory at kernel start | ||
52 | and introduces an overhead of ~x1.5 for the rest of the allocations. | ||
53 | The performance slowdown is ~x3. | ||
20 | For better error detection enable CONFIG_STACKTRACE. | 54 | For better error detection enable CONFIG_STACKTRACE. |
21 | Currently CONFIG_KASAN doesn't work with CONFIG_DEBUG_SLAB | 55 | Currently CONFIG_KASAN_GENERIC doesn't work with CONFIG_DEBUG_SLAB |
22 | (the resulting kernel does not boot). | 56 | (the resulting kernel does not boot). |
23 | 57 | ||
58 | config KASAN_SW_TAGS | ||
59 | bool "Software tag-based mode" | ||
60 | depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS | ||
61 | depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) | ||
62 | select SLUB_DEBUG if SLUB | ||
63 | select CONSTRUCTORS | ||
64 | select STACKDEPOT | ||
65 | help | ||
66 | Enables software tag-based KASAN mode. | ||
67 | This mode requires Top Byte Ignore support by the CPU and therefore | ||
68 | is only supported for arm64. | ||
69 | This mode requires Clang version 7.0.0 or later. | ||
70 | This mode consumes about 1/16th of available memory at kernel start | ||
71 | and introduces an overhead of ~20% for the rest of the allocations. | ||
72 | This mode may potentially introduce problems relating to pointer | ||
73 | casting and comparison, as it embeds tags into the top byte of each | ||
74 | pointer. | ||
75 | For better error detection enable CONFIG_STACKTRACE. | ||
76 | Currently CONFIG_KASAN_SW_TAGS doesn't work with CONFIG_DEBUG_SLAB | ||
77 | (the resulting kernel does not boot). | ||
78 | |||
79 | endchoice | ||
80 | |||
24 | config KASAN_EXTRA | 81 | config KASAN_EXTRA |
25 | bool "KAsan: extra checks" | 82 | bool "KASAN: extra checks" |
26 | depends on KASAN && DEBUG_KERNEL && !COMPILE_TEST | 83 | depends on KASAN_GENERIC && DEBUG_KERNEL && !COMPILE_TEST |
27 | help | 84 | help |
28 | This enables further checks in the kernel address sanitizer, for now | 85 | This enables further checks in generic KASAN, for now it only |
29 | it only includes the address-use-after-scope check that can lead | 86 | includes the address-use-after-scope check that can lead to |
30 | to excessive kernel stack usage, frame size warnings and longer | 87 | excessive kernel stack usage, frame size warnings and longer |
31 | compile time. | 88 | compile time. |
32 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 has more | 89 | See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 |
33 | |||
34 | 90 | ||
35 | choice | 91 | choice |
36 | prompt "Instrumentation type" | 92 | prompt "Instrumentation type" |
@@ -53,7 +109,7 @@ config KASAN_INLINE | |||
53 | memory accesses. This is faster than outline (in some workloads | 109 | memory accesses. This is faster than outline (in some workloads |
54 | it gives about x2 boost over outline instrumentation), but | 110 | it gives about x2 boost over outline instrumentation), but |
55 | make kernel's .text size much bigger. | 111 | make kernel's .text size much bigger. |
56 | This requires a gcc version of 5.0 or later. | 112 | For CONFIG_KASAN_GENERIC this requires GCC 5.0 or later. |
57 | 113 | ||
58 | endchoice | 114 | endchoice |
59 | 115 | ||
@@ -67,11 +123,9 @@ config KASAN_S390_4_LEVEL_PAGING | |||
67 | 4-level paging instead. | 123 | 4-level paging instead. |
68 | 124 | ||
69 | config TEST_KASAN | 125 | config TEST_KASAN |
70 | tristate "Module for testing kasan for bug detection" | 126 | tristate "Module for testing KASAN for bug detection" |
71 | depends on m && KASAN | 127 | depends on m && KASAN |
72 | help | 128 | help |
73 | This is a test module doing various nasty things like | 129 | This is a test module doing various nasty things like |
74 | out of bounds accesses, use after free. It is useful for testing | 130 | out of bounds accesses, use after free. It is useful for testing |
75 | kernel debugging features like kernel address sanitizer. | 131 | kernel debugging features like KASAN. |
76 | |||
77 | endif | ||
diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index d643530b24aa..68ba1822f003 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile | |||
@@ -2,6 +2,7 @@ | |||
2 | KASAN_SANITIZE := n | 2 | KASAN_SANITIZE := n |
3 | UBSAN_SANITIZE_common.o := n | 3 | UBSAN_SANITIZE_common.o := n |
4 | UBSAN_SANITIZE_generic.o := n | 4 | UBSAN_SANITIZE_generic.o := n |
5 | UBSAN_SANITIZE_tags.o := n | ||
5 | KCOV_INSTRUMENT := n | 6 | KCOV_INSTRUMENT := n |
6 | 7 | ||
7 | CFLAGS_REMOVE_generic.o = -pg | 8 | CFLAGS_REMOVE_generic.o = -pg |
@@ -10,5 +11,8 @@ CFLAGS_REMOVE_generic.o = -pg | |||
10 | 11 | ||
11 | CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) | 12 | CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) |
12 | CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) | 13 | CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) |
14 | CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) | ||
13 | 15 | ||
14 | obj-y := common.o generic.o report.o init.o quarantine.o | 16 | obj-$(CONFIG_KASAN) := common.o init.o report.o |
17 | obj-$(CONFIG_KASAN_GENERIC) += generic.o quarantine.o | ||
18 | obj-$(CONFIG_KASAN_SW_TAGS) += tags.o | ||
diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 44ec228de0a2..b8de6d33c55c 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * This file contains core KASAN code. | 2 | * This file contains core generic KASAN code. |
3 | * | 3 | * |
4 | * Copyright (c) 2014 Samsung Electronics Co., Ltd. | 4 | * Copyright (c) 2014 Samsung Electronics Co., Ltd. |
5 | * Author: Andrey Ryabinin <ryabinin.a.a@gmail.com> | 5 | * Author: Andrey Ryabinin <ryabinin.a.a@gmail.com> |
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 659463800f10..19b950eaccff 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h | |||
@@ -114,7 +114,8 @@ void kasan_report(unsigned long addr, size_t size, | |||
114 | bool is_write, unsigned long ip); | 114 | bool is_write, unsigned long ip); |
115 | void kasan_report_invalid_free(void *object, unsigned long ip); | 115 | void kasan_report_invalid_free(void *object, unsigned long ip); |
116 | 116 | ||
117 | #if defined(CONFIG_SLAB) || defined(CONFIG_SLUB) | 117 | #if defined(CONFIG_KASAN_GENERIC) && \ |
118 | (defined(CONFIG_SLAB) || defined(CONFIG_SLUB)) | ||
118 | void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache); | 119 | void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache); |
119 | void quarantine_reduce(void); | 120 | void quarantine_reduce(void); |
120 | void quarantine_remove_cache(struct kmem_cache *cache); | 121 | void quarantine_remove_cache(struct kmem_cache *cache); |
diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c new file mode 100644 index 000000000000..04194923c543 --- /dev/null +++ b/mm/kasan/tags.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | * This file contains core tag-based KASAN code. | ||
3 | * | ||
4 | * Copyright (c) 2018 Google, Inc. | ||
5 | * Author: Andrey Konovalov <andreyknvl@google.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
14 | #define DISABLE_BRANCH_PROFILING | ||
15 | |||
16 | #include <linux/export.h> | ||
17 | #include <linux/interrupt.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/kasan.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/kmemleak.h> | ||
22 | #include <linux/linkage.h> | ||
23 | #include <linux/memblock.h> | ||
24 | #include <linux/memory.h> | ||
25 | #include <linux/mm.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/printk.h> | ||
28 | #include <linux/random.h> | ||
29 | #include <linux/sched.h> | ||
30 | #include <linux/sched/task_stack.h> | ||
31 | #include <linux/slab.h> | ||
32 | #include <linux/stacktrace.h> | ||
33 | #include <linux/string.h> | ||
34 | #include <linux/types.h> | ||
35 | #include <linux/vmalloc.h> | ||
36 | #include <linux/bug.h> | ||
37 | |||
38 | #include "kasan.h" | ||
39 | #include "../slab.h" | ||
40 | |||
41 | void check_memory_region(unsigned long addr, size_t size, bool write, | ||
42 | unsigned long ret_ip) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | #define DEFINE_HWASAN_LOAD_STORE(size) \ | ||
47 | void __hwasan_load##size##_noabort(unsigned long addr) \ | ||
48 | { \ | ||
49 | } \ | ||
50 | EXPORT_SYMBOL(__hwasan_load##size##_noabort); \ | ||
51 | void __hwasan_store##size##_noabort(unsigned long addr) \ | ||
52 | { \ | ||
53 | } \ | ||
54 | EXPORT_SYMBOL(__hwasan_store##size##_noabort) | ||
55 | |||
56 | DEFINE_HWASAN_LOAD_STORE(1); | ||
57 | DEFINE_HWASAN_LOAD_STORE(2); | ||
58 | DEFINE_HWASAN_LOAD_STORE(4); | ||
59 | DEFINE_HWASAN_LOAD_STORE(8); | ||
60 | DEFINE_HWASAN_LOAD_STORE(16); | ||
61 | |||
62 | void __hwasan_loadN_noabort(unsigned long addr, unsigned long size) | ||
63 | { | ||
64 | } | ||
65 | EXPORT_SYMBOL(__hwasan_loadN_noabort); | ||
66 | |||
67 | void __hwasan_storeN_noabort(unsigned long addr, unsigned long size) | ||
68 | { | ||
69 | } | ||
70 | EXPORT_SYMBOL(__hwasan_storeN_noabort); | ||
71 | |||
72 | void __hwasan_tag_memory(unsigned long addr, u8 tag, unsigned long size) | ||
73 | { | ||
74 | } | ||
75 | EXPORT_SYMBOL(__hwasan_tag_memory); | ||
@@ -2992,7 +2992,7 @@ static __always_inline void slab_free(struct kmem_cache *s, struct page *page, | |||
2992 | do_slab_free(s, page, head, tail, cnt, addr); | 2992 | do_slab_free(s, page, head, tail, cnt, addr); |
2993 | } | 2993 | } |
2994 | 2994 | ||
2995 | #ifdef CONFIG_KASAN | 2995 | #ifdef CONFIG_KASAN_GENERIC |
2996 | void ___cache_free(struct kmem_cache *cache, void *x, unsigned long addr) | 2996 | void ___cache_free(struct kmem_cache *cache, void *x, unsigned long addr) |
2997 | { | 2997 | { |
2998 | do_slab_free(cache, virt_to_head_page(x), x, NULL, 1, addr); | 2998 | do_slab_free(cache, virt_to_head_page(x), x, NULL, 1, addr); |
diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index 69552a39951d..25c259df8ffa 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan | |||
@@ -1,5 +1,6 @@ | |||
1 | # SPDX-License-Identifier: GPL-2.0 | 1 | # SPDX-License-Identifier: GPL-2.0 |
2 | ifdef CONFIG_KASAN | 2 | ifdef CONFIG_KASAN_GENERIC |
3 | |||
3 | ifdef CONFIG_KASAN_INLINE | 4 | ifdef CONFIG_KASAN_INLINE |
4 | call_threshold := 10000 | 5 | call_threshold := 10000 |
5 | else | 6 | else |
@@ -12,36 +13,44 @@ CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address | |||
12 | 13 | ||
13 | cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) | 14 | cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) |
14 | 15 | ||
15 | ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) | 16 | # -fasan-shadow-offset fails without -fsanitize |
16 | ifneq ($(CONFIG_COMPILE_TEST),y) | 17 | CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \ |
17 | $(warning Cannot use CONFIG_KASAN: \ | ||
18 | -fsanitize=kernel-address is not supported by compiler) | ||
19 | endif | ||
20 | else | ||
21 | # -fasan-shadow-offset fails without -fsanitize | ||
22 | CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \ | ||
23 | -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \ | 18 | -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \ |
24 | $(call cc-option, -fsanitize=kernel-address \ | 19 | $(call cc-option, -fsanitize=kernel-address \ |
25 | -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET))) | 20 | -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET))) |
26 | 21 | ||
27 | ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),) | 22 | ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),) |
28 | CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) | 23 | CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) |
29 | else | 24 | else |
30 | # Now add all the compiler specific options that are valid standalone | 25 | # Now add all the compiler specific options that are valid standalone |
31 | CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ | 26 | CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ |
32 | $(call cc-param,asan-globals=1) \ | 27 | $(call cc-param,asan-globals=1) \ |
33 | $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ | 28 | $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ |
34 | $(call cc-param,asan-stack=1) \ | 29 | $(call cc-param,asan-stack=1) \ |
35 | $(call cc-param,asan-use-after-scope=1) \ | 30 | $(call cc-param,asan-use-after-scope=1) \ |
36 | $(call cc-param,asan-instrument-allocas=1) | 31 | $(call cc-param,asan-instrument-allocas=1) |
37 | endif | ||
38 | |||
39 | endif | 32 | endif |
40 | 33 | ||
41 | ifdef CONFIG_KASAN_EXTRA | 34 | ifdef CONFIG_KASAN_EXTRA |
42 | CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) | 35 | CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) |
43 | endif | 36 | endif |
44 | 37 | ||
45 | CFLAGS_KASAN_NOSANITIZE := -fno-builtin | 38 | endif # CONFIG_KASAN_GENERIC |
46 | 39 | ||
40 | ifdef CONFIG_KASAN_SW_TAGS | ||
41 | |||
42 | ifdef CONFIG_KASAN_INLINE | ||
43 | instrumentation_flags := -mllvm -hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET) | ||
44 | else | ||
45 | instrumentation_flags := -mllvm -hwasan-instrument-with-calls=1 | ||
46 | endif | ||
47 | |||
48 | CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ | ||
49 | -mllvm -hwasan-instrument-stack=0 \ | ||
50 | $(instrumentation_flags) | ||
51 | |||
52 | endif # CONFIG_KASAN_SW_TAGS | ||
53 | |||
54 | ifdef CONFIG_KASAN | ||
55 | CFLAGS_KASAN_NOSANITIZE := -fno-builtin | ||
47 | endif | 56 | endif |