1
1
# SPDX-License-Identifier: GPL-2.0-only
2
+
2
3
# This config refers to the generic KASAN mode.
3
4
config HAVE_ARCH_KASAN
4
5
bool
@@ -15,9 +16,8 @@ config HAVE_ARCH_KASAN_VMALLOC
15
16
config ARCH_DISABLE_KASAN_INLINE
16
17
bool
17
18
help
18
- An architecture might not support inline instrumentation.
19
- When this option is selected, inline and stack instrumentation are
20
- disabled.
19
+ Disables both inline and stack instrumentation. Selected by
20
+ architectures that do not support these instrumentation types.
21
21
22
22
config CC_HAS_KASAN_GENERIC
23
23
def_bool $(cc-option, -fsanitize=kernel-address)
@@ -26,100 +26,99 @@ config CC_HAS_KASAN_SW_TAGS
26
26
def_bool $(cc-option, -fsanitize=kernel-hwaddress)
27
27
28
28
# This option is only required for software KASAN modes.
29
- # Old GCC versions don't have proper support for no_sanitize_address.
29
+ # Old GCC versions do not have proper support for no_sanitize_address.
30
30
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89124 for details.
31
31
config CC_HAS_WORKING_NOSANITIZE_ADDRESS
32
32
def_bool !CC_IS_GCC || GCC_VERSION >= 80300
33
33
34
34
menuconfig KASAN
35
- bool "KASAN: runtime memory debugger "
35
+ bool "KASAN: dynamic memory safety error detector "
36
36
depends on (((HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \
37
37
(HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)) && \
38
38
CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \
39
39
HAVE_ARCH_KASAN_HW_TAGS
40
40
depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB)
41
41
select STACKDEPOT_ALWAYS_INIT
42
42
help
43
- Enables KASAN (KernelAddressSANitizer) - runtime memory debugger,
44
- designed to find out-of-bounds accesses and use-after-free bugs.
43
+ Enables KASAN (Kernel Address Sanitizer) - a dynamic memory safety
44
+ error detector designed to find out-of-bounds and use-after-free bugs.
45
+
45
46
See Documentation/dev-tools/kasan.rst for details.
46
47
48
+ For better error reports, also enable CONFIG_STACKTRACE.
49
+
47
50
if KASAN
48
51
49
52
choice
50
53
prompt "KASAN mode"
51
54
default KASAN_GENERIC
52
55
help
53
56
KASAN has three modes:
54
- 1. generic KASAN (similar to userspace ASan,
55
- x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC),
56
- 2. software tag-based KASAN (arm64 only, based on software
57
- memory tagging (similar to userspace HWASan), enabled with
58
- CONFIG_KASAN_SW_TAGS), and
59
- 3. hardware tag-based KASAN (arm64 only, based on hardware
60
- memory tagging, enabled with CONFIG_KASAN_HW_TAGS).
61
57
62
- All KASAN modes are strictly debugging features.
58
+ 1. Generic KASAN (supported by many architectures, enabled with
59
+ CONFIG_KASAN_GENERIC, similar to userspace ASan),
60
+ 2. Software Tag-Based KASAN (arm64 only, based on software memory
61
+ tagging, enabled with CONFIG_KASAN_SW_TAGS, similar to userspace
62
+ HWASan), and
63
+ 3. Hardware Tag-Based KASAN (arm64 only, based on hardware memory
64
+ tagging, enabled with CONFIG_KASAN_HW_TAGS).
63
65
64
- For better error reports enable CONFIG_STACKTRACE .
66
+ See Documentation/dev-tools/kasan.rst for details about each mode .
65
67
66
68
config KASAN_GENERIC
67
- bool "Generic mode "
69
+ bool "Generic KASAN "
68
70
depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC
69
71
depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS
70
72
select SLUB_DEBUG if SLUB
71
73
select CONSTRUCTORS
72
74
help
73
- Enables generic KASAN mode .
75
+ Enables Generic KASAN.
74
76
75
- This mode is supported in both GCC and Clang. With GCC it requires
76
- version 8.3.0 or later. Any supported Clang version is compatible,
77
- but detection of out-of-bounds accesses for global variables is
78
- supported only since Clang 11.
77
+ Requires GCC 8.3.0+ or Clang.
79
78
80
- This mode consumes about 1/8th of available memory at kernel start
81
- and introduces an overhead of ~x1.5 for the rest of the allocations.
79
+ Consumes about 1/8th of available memory at kernel start and adds an
80
+ overhead of ~50% for dynamic allocations.
82
81
The performance slowdown is ~x3.
83
82
84
- Currently CONFIG_KASAN_GENERIC doesn't work with CONFIG_DEBUG_SLAB
85
- (the resulting kernel does not boot).
83
+ (Incompatible with CONFIG_DEBUG_SLAB: the kernel does not boot.)
86
84
87
85
config KASAN_SW_TAGS
88
- bool "Software tag-based mode "
86
+ bool "Software Tag-Based KASAN "
89
87
depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS
90
88
depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS
91
89
select SLUB_DEBUG if SLUB
92
90
select CONSTRUCTORS
93
91
help
94
- Enables software tag-based KASAN mode .
92
+ Enables Software Tag-Based KASAN.
95
93
96
- This mode require software memory tagging support in the form of
97
- HWASan-like compiler instrumentation.
94
+ Requires GCC 11+ or Clang.
98
95
99
- Currently this mode is only implemented for arm64 CPUs and relies on
100
- Top Byte Ignore. This mode requires Clang.
96
+ Supported only on arm64 CPUs and relies on Top Byte Ignore.
101
97
102
- This mode consumes about 1/16th of available memory at kernel start
103
- and introduces an overhead of ~20% for the rest of the allocations.
104
- This mode may potentially introduce problems relating to pointer
105
- casting and comparison, as it embeds tags into the top byte of each
106
- pointer.
98
+ Consumes about 1/16th of available memory at kernel start and
99
+ add an overhead of ~20% for dynamic allocations.
107
100
108
- Currently CONFIG_KASAN_SW_TAGS doesn't work with CONFIG_DEBUG_SLAB
109
- (the resulting kernel does not boot).
101
+ May potentially introduce problems related to pointer casting and
102
+ comparison, as it embeds a tag into the top byte of each pointer.
103
+
104
+ (Incompatible with CONFIG_DEBUG_SLAB: the kernel does not boot.)
110
105
111
106
config KASAN_HW_TAGS
112
- bool "Hardware tag-based mode "
107
+ bool "Hardware Tag-Based KASAN "
113
108
depends on HAVE_ARCH_KASAN_HW_TAGS
114
109
depends on SLUB
115
110
help
116
- Enables hardware tag-based KASAN mode.
111
+ Enables Hardware Tag-Based KASAN.
112
+
113
+ Requires GCC 10+ or Clang 12+.
117
114
118
- This mode requires hardware memory tagging support, and can be used
119
- by any architecture that provides it .
115
+ Supported only on arm64 CPUs starting from ARMv8.5 and relies on
116
+ Memory Tagging Extension and Top Byte Ignore .
120
117
121
- Currently this mode is only implemented for arm64 CPUs starting from
122
- ARMv8.5 and relies on Memory Tagging Extension and Top Byte Ignore.
118
+ Consumes about 1/32nd of available memory.
119
+
120
+ May potentially introduce problems related to pointer casting and
121
+ comparison, as it embeds a tag into the top byte of each pointer.
123
122
124
123
endchoice
125
124
@@ -131,83 +130,80 @@ choice
131
130
config KASAN_OUTLINE
132
131
bool "Outline instrumentation"
133
132
help
134
- Before every memory access compiler insert function call
135
- __asan_load*/__asan_store*. These functions performs check
136
- of shadow memory. This is slower than inline instrumentation,
137
- however it doesn't bloat size of kernel's .text section so
138
- much as inline does.
133
+ Makes the compiler insert function calls that check whether the memory
134
+ is accessible before each memory access. Slower than KASAN_INLINE, but
135
+ does not bloat the size of the kernel's .text section so much.
139
136
140
137
config KASAN_INLINE
141
138
bool "Inline instrumentation"
142
139
depends on !ARCH_DISABLE_KASAN_INLINE
143
140
help
144
- Compiler directly inserts code checking shadow memory before
145
- memory accesses. This is faster than outline (in some workloads
146
- it gives about x2 boost over outline instrumentation), but
147
- make kernel's .text size much bigger.
141
+ Makes the compiler directly insert memory accessibility checks before
142
+ each memory access. Faster than KASAN_OUTLINE (gives ~x2 boost for
143
+ some workloads), but makes the kernel's .text size much bigger.
148
144
149
145
endchoice
150
146
151
147
config KASAN_STACK
152
- bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST
148
+ bool "Stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST
153
149
depends on KASAN_GENERIC || KASAN_SW_TAGS
154
150
depends on !ARCH_DISABLE_KASAN_INLINE
155
151
default y if CC_IS_GCC
156
152
help
157
- The LLVM stack address sanitizer has a know problem that
158
- causes excessive stack usage in a lot of functions, see
159
- https://bugs.llvm.org/show_bug.cgi?id=38809
160
- Disabling asan-stack makes it safe to run kernels build
161
- with clang-8 with KASAN enabled, though it loses some of
162
- the functionality.
163
- This feature is always disabled when compile-testing with clang
164
- to avoid cluttering the output in stack overflow warnings,
165
- but clang users can still enable it for builds without
166
- CONFIG_COMPILE_TEST. On gcc it is assumed to always be safe
167
- to use and enabled by default.
168
- If the architecture disables inline instrumentation, stack
169
- instrumentation is also disabled as it adds inline-style
170
- instrumentation that is run unconditionally.
153
+ Disables stack instrumentation and thus KASAN's ability to detect
154
+ out-of-bounds bugs in stack variables.
155
+
156
+ With Clang, stack instrumentation has a problem that causes excessive
157
+ stack usage, see https://bugs.llvm.org/show_bug.cgi?id=38809. Thus,
158
+ with Clang, this option is deemed unsafe.
159
+
160
+ This option is always disabled when compile-testing with Clang to
161
+ avoid cluttering the log with stack overflow warnings.
162
+
163
+ With GCC, enabling stack instrumentation is assumed to be safe.
164
+
165
+ If the architecture disables inline instrumentation via
166
+ ARCH_DISABLE_KASAN_INLINE, stack instrumentation gets disabled
167
+ as well, as it adds inline-style instrumentation that is run
168
+ unconditionally.
171
169
172
170
config KASAN_TAGS_IDENTIFY
173
- bool "Enable memory corruption identification"
171
+ bool "Memory corruption type identification"
174
172
depends on KASAN_SW_TAGS || KASAN_HW_TAGS
175
173
help
176
- This option enables best-effort identification of bug type
177
- (use-after-free or out-of-bounds) at the cost of increased
178
- memory consumption .
174
+ Enables best-effort identification of the bug types (use-after-free
175
+ or out-of-bounds) at the cost of increased memory consumption.
176
+ Only applicable for the tag-based KASAN modes .
179
177
180
178
config KASAN_VMALLOC
181
179
bool "Check accesses to vmalloc allocations"
182
180
depends on HAVE_ARCH_KASAN_VMALLOC
183
181
help
184
- This mode makes KASAN check accesses to vmalloc allocations for
185
- validity.
182
+ Makes KASAN check the validity of accesses to vmalloc allocations.
186
183
187
- With software KASAN modes, checking is done for all types of vmalloc
188
- allocations . Enabling this option leads to higher memory usage.
184
+ With software KASAN modes, all types vmalloc allocations are
185
+ checked . Enabling this option leads to higher memory usage.
189
186
190
- With hardware tag-based KASAN, only VM_ALLOC mappings are checked.
191
- There is no additional memory usage.
187
+ With Hardware Tag-Based KASAN, only non-executable VM_ALLOC mappings
188
+ are checked. There is no additional memory usage.
192
189
193
190
config KASAN_KUNIT_TEST
194
191
tristate "KUnit-compatible tests of KASAN bug detection capabilities" if !KUNIT_ALL_TESTS
195
192
depends on KASAN && KUNIT
196
193
default KUNIT_ALL_TESTS
197
194
help
198
- This is a KUnit test suite doing various nasty things like
199
- out of bounds and use after free accesses. It is useful for testing
200
- kernel debugging features like KASAN .
195
+ A KUnit-based KASAN test suite. Triggers different kinds of
196
+ out-of- bounds and use- after- free accesses. Useful for testing whether
197
+ KASAN can detect certain bug types .
201
198
202
199
For more information on KUnit and unit tests in general, please refer
203
- to the KUnit documentation in Documentation/dev-tools/kunit.
200
+ to the KUnit documentation in Documentation/dev-tools/kunit/ .
204
201
205
202
config KASAN_MODULE_TEST
206
203
tristate "KUnit-incompatible tests of KASAN bug detection capabilities"
207
204
depends on m && KASAN && !KASAN_HW_TAGS
208
205
help
209
- This is a part of the KASAN test suite that is incompatible with
210
- KUnit. Currently includes tests that do bad copy_from/to_user
211
- accesses.
206
+ A part of the KASAN test suite that is not integrated with KUnit.
207
+ Incompatible with Hardware Tag-Based KASAN.
212
208
213
209
endif # KASAN
0 commit comments