Skip to content

Commit fe30ddc

Browse files
xairyakpm00
authored andcommitted
kasan: clean-up kconfig options descriptions
Various readability clean-ups of KASAN Kconfig options. No functional changes. Link: https://lkml.kernel.org/r/c160840dd9e4b1ad5529ecfdb0bba35d9a14d826.1652203271.git.andreyknvl@google.com Link: https://lkml.kernel.org/r/47afaecec29221347bee49f58c258ac1ced3b429.1652123204.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <[email protected]> Reviewed-by: Marco Elver <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ca89f2a commit fe30ddc

File tree

1 file changed

+82
-86
lines changed

1 file changed

+82
-86
lines changed

lib/Kconfig.kasan

Lines changed: 82 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2+
23
# This config refers to the generic KASAN mode.
34
config HAVE_ARCH_KASAN
45
bool
@@ -15,9 +16,8 @@ config HAVE_ARCH_KASAN_VMALLOC
1516
config ARCH_DISABLE_KASAN_INLINE
1617
bool
1718
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.
2121

2222
config CC_HAS_KASAN_GENERIC
2323
def_bool $(cc-option, -fsanitize=kernel-address)
@@ -26,100 +26,99 @@ config CC_HAS_KASAN_SW_TAGS
2626
def_bool $(cc-option, -fsanitize=kernel-hwaddress)
2727

2828
# 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.
3030
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89124 for details.
3131
config CC_HAS_WORKING_NOSANITIZE_ADDRESS
3232
def_bool !CC_IS_GCC || GCC_VERSION >= 80300
3333

3434
menuconfig KASAN
35-
bool "KASAN: runtime memory debugger"
35+
bool "KASAN: dynamic memory safety error detector"
3636
depends on (((HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \
3737
(HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)) && \
3838
CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \
3939
HAVE_ARCH_KASAN_HW_TAGS
4040
depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB)
4141
select STACKDEPOT_ALWAYS_INIT
4242
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+
4546
See Documentation/dev-tools/kasan.rst for details.
4647

48+
For better error reports, also enable CONFIG_STACKTRACE.
49+
4750
if KASAN
4851

4952
choice
5053
prompt "KASAN mode"
5154
default KASAN_GENERIC
5255
help
5356
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).
6157

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).
6365

64-
For better error reports enable CONFIG_STACKTRACE.
66+
See Documentation/dev-tools/kasan.rst for details about each mode.
6567

6668
config KASAN_GENERIC
67-
bool "Generic mode"
69+
bool "Generic KASAN"
6870
depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC
6971
depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS
7072
select SLUB_DEBUG if SLUB
7173
select CONSTRUCTORS
7274
help
73-
Enables generic KASAN mode.
75+
Enables Generic KASAN.
7476

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.
7978

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.
8281
The performance slowdown is ~x3.
8382

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.)
8684

8785
config KASAN_SW_TAGS
88-
bool "Software tag-based mode"
86+
bool "Software Tag-Based KASAN"
8987
depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS
9088
depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS
9189
select SLUB_DEBUG if SLUB
9290
select CONSTRUCTORS
9391
help
94-
Enables software tag-based KASAN mode.
92+
Enables Software Tag-Based KASAN.
9593

96-
This mode require software memory tagging support in the form of
97-
HWASan-like compiler instrumentation.
94+
Requires GCC 11+ or Clang.
9895

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.
10197

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.
107100

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.)
110105

111106
config KASAN_HW_TAGS
112-
bool "Hardware tag-based mode"
107+
bool "Hardware Tag-Based KASAN"
113108
depends on HAVE_ARCH_KASAN_HW_TAGS
114109
depends on SLUB
115110
help
116-
Enables hardware tag-based KASAN mode.
111+
Enables Hardware Tag-Based KASAN.
112+
113+
Requires GCC 10+ or Clang 12+.
117114

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.
120117

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.
123122

124123
endchoice
125124

@@ -131,83 +130,80 @@ choice
131130
config KASAN_OUTLINE
132131
bool "Outline instrumentation"
133132
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.
139136

140137
config KASAN_INLINE
141138
bool "Inline instrumentation"
142139
depends on !ARCH_DISABLE_KASAN_INLINE
143140
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.
148144

149145
endchoice
150146

151147
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
153149
depends on KASAN_GENERIC || KASAN_SW_TAGS
154150
depends on !ARCH_DISABLE_KASAN_INLINE
155151
default y if CC_IS_GCC
156152
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.
171169

172170
config KASAN_TAGS_IDENTIFY
173-
bool "Enable memory corruption identification"
171+
bool "Memory corruption type identification"
174172
depends on KASAN_SW_TAGS || KASAN_HW_TAGS
175173
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.
179177

180178
config KASAN_VMALLOC
181179
bool "Check accesses to vmalloc allocations"
182180
depends on HAVE_ARCH_KASAN_VMALLOC
183181
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.
186183

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.
189186

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.
192189

193190
config KASAN_KUNIT_TEST
194191
tristate "KUnit-compatible tests of KASAN bug detection capabilities" if !KUNIT_ALL_TESTS
195192
depends on KASAN && KUNIT
196193
default KUNIT_ALL_TESTS
197194
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.
201198

202199
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/.
204201

205202
config KASAN_MODULE_TEST
206203
tristate "KUnit-incompatible tests of KASAN bug detection capabilities"
207204
depends on m && KASAN && !KASAN_HW_TAGS
208205
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.
212208

213209
endif # KASAN

0 commit comments

Comments
 (0)