CONFIG_HAVE_ARCH_KASAN
CONFIG_HAVE_ARCH_KASAN_SW_TAGS
CONFIG_HAVE_ARCH_KASAN_HW_TAGS
CONFIG_HAVE_ARCH_KASAN_VMALLOC
CONFIG_ARCH_DISABLE_KASAN_INLINE
Disables both inline and stack instrumentation. Selected by architectures that do not support these instrumentation types.
CONFIG_ARCH_NEEDS_DEFER_KASAN
CONFIG_ARCH_DEFER_KASAN
Architectures should select this if they need to defer KASAN initialization until shadow memory is properly set up. This enables runtime control via static keys. Otherwise, KASAN uses compile-time constants for better performance.
- Depends on
KASAN && ARCH_NEEDS_DEFER_KASAN
CONFIG_CC_HAS_KASAN_GENERIC
CONFIG_CC_HAS_KASAN_SW_TAGS
CONFIG_CC_HAS_WORKING_NOSANITIZE_ADDRESS
CONFIG_KASAN KASAN: dynamic memory safety error detector
Enables KASAN (Kernel Address Sanitizer) - a dynamic memory safety error detector designed to find out-of-bounds and use-after-free bugs.
See Documentation/dev-tools/kasan.rst for details.
For better error reports, also enable CONFIG_STACKTRACE.
- Depends on
((HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC || HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS) && CC_HAS_WORKING_NOSANITIZE_ADDRESS || HAVE_ARCH_KASAN_HW_TAGS) && SYSFS && !SLUB_TINY - Selects
STACKDEPOT_ALWAYS_INIT if ((HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC || HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS) && CC_HAS_WORKING_NOSANITIZE_ADDRESS || HAVE_ARCH_KASAN_HW_TAGS) && SYSFS && !SLUB_TINY
If KASAN
CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
The compiler is able to prefix memintrinsics with __asan or __hwasan.
- Depends on
KASAN && !KASAN_HW_TAGS
KASAN mode
KASAN has three modes:
1. Generic KASAN (supported by many architectures, enabled with CONFIG_KASAN_GENERIC, similar to userspace ASan), 2. Software Tag-Based KASAN (arm64 only, based on software memory tagging, enabled with CONFIG_KASAN_SW_TAGS, similar to userspace HWASan), and 3. Hardware Tag-Based KASAN (arm64 only, based on hardware memory tagging, enabled with CONFIG_KASAN_HW_TAGS).
See Documentation/dev-tools/kasan.rst for details about each mode.
CONFIG_KASAN_GENERIC Generic KASAN
Enables Generic KASAN.
Requires GCC 8.3.0+ or Clang.
Consumes about 1/8th of available memory at kernel start and adds an overhead of ~50% for dynamic allocations. The performance slowdown is ~x3.
- Depends on
KASAN && HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC && CC_HAS_WORKING_NOSANITIZE_ADDRESS - Selects
SLUB_DEBUG if KASAN && HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC && CC_HAS_WORKING_NOSANITIZE_ADDRESS - Selects
CONSTRUCTORS if KASAN && HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC && CC_HAS_WORKING_NOSANITIZE_ADDRESS
CONFIG_KASAN_SW_TAGS Software Tag-Based KASAN
Enables Software Tag-Based KASAN.
Requires GCC 11+ or Clang.
Supported only on arm64 CPUs and relies on Top Byte Ignore.
Consumes about 1/16th of available memory at kernel start and add an overhead of ~20% for dynamic allocations.
May potentially introduce problems related to pointer casting and comparison, as it embeds a tag into the top byte of each pointer.
- Depends on
KASAN && HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS && CC_HAS_WORKING_NOSANITIZE_ADDRESS - Selects
SLUB_DEBUG if KASAN && HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS && CC_HAS_WORKING_NOSANITIZE_ADDRESS - Selects
CONSTRUCTORS if KASAN && HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS && CC_HAS_WORKING_NOSANITIZE_ADDRESS
CONFIG_KASAN_HW_TAGS Hardware Tag-Based KASAN
Enables Hardware Tag-Based KASAN.
Requires GCC 10+ or Clang 12+.
Supported only on arm64 CPUs starting from ARMv8.5 and relies on Memory Tagging Extension and Top Byte Ignore.
Consumes about 1/32nd of available memory.
May potentially introduce problems related to pointer casting and comparison, as it embeds a tag into the top byte of each pointer.
- Depends on
KASAN && HAVE_ARCH_KASAN_HW_TAGS
Instrumentation type
- Depends on
KASAN && (KASAN_GENERIC || KASAN_SW_TAGS)
CONFIG_KASAN_OUTLINE Outline instrumentation
Makes the compiler insert function calls that check whether the memory is accessible before each memory access. Slower than KASAN_INLINE, but does not bloat the size of the kernel's .text section so much.
- Depends on
KASAN && (KASAN_GENERIC || KASAN_SW_TAGS)
CONFIG_KASAN_INLINE Inline instrumentation
Makes the compiler directly insert memory accessibility checks before each memory access. Faster than KASAN_OUTLINE (gives ~x2 boost for some workloads), but makes the kernel's .text size much bigger.
- Depends on
KASAN && (KASAN_GENERIC || KASAN_SW_TAGS) && !ARCH_DISABLE_KASAN_INLINE
CONFIG_KASAN_STACK Stack instrumentation (unsafe)
Disables stack instrumentation and thus KASAN's ability to detect out-of-bounds bugs in stack variables.
With Clang, stack instrumentation has a problem that causes excessive stack usage, see https://llvm.org/pr38809. Thus, with Clang, this option is deemed unsafe.
This option is always disabled when compile-testing with Clang to avoid cluttering the log with stack overflow warnings.
With GCC, enabling stack instrumentation is assumed to be safe.
If the architecture disables inline instrumentation via ARCH_DISABLE_KASAN_INLINE, stack instrumentation gets disabled as well, as it adds inline-style instrumentation that is run unconditionally.
- Depends on
KASAN && (KASAN_GENERIC || KASAN_SW_TAGS) && !ARCH_DISABLE_KASAN_INLINE
CONFIG_KASAN_VMALLOC Check accesses to vmalloc allocations
Makes KASAN check the validity of accesses to vmalloc allocations.
With software KASAN modes, all types vmalloc allocations are checked. Enabling this option leads to higher memory usage.
With Hardware Tag-Based KASAN, only non-executable VM_ALLOC mappings are checked. There is no additional memory usage.
- Depends on
KASAN && HAVE_ARCH_KASAN_VMALLOC
CONFIG_KASAN_KUNIT_TEST KUnit-compatible tests of KASAN bug detection capabilities
- Off
- Module
- Built in
A KUnit-based KASAN test suite. Triggers different kinds of out-of-bounds and use-after-free accesses. Useful for testing whether KASAN can detect certain bug types.
For more information on KUnit and unit tests in general, please refer to the KUnit documentation in Documentation/dev-tools/kunit/.
- Depends on
KASAN && KUNIT && TRACEPOINTS
CONFIG_KASAN_EXTRA_INFO Record and report more information
Record and report more information to help us find the cause of the bug and to help us correlate the error with other system events.
Currently, the CPU number and timestamp are additionally recorded for each heap block at allocation and free time, and 8 bytes will be added to each metadata structure that records allocation or free information.
In Generic KASAN, each kmalloc-8 and kmalloc-16 object will add 16 bytes of additional memory consumption, and each kmalloc-32 object will add 8 bytes of additional memory consumption, not affecting other larger objects.
In SW_TAGS KASAN and HW_TAGS KASAN, depending on the stack_ring_size boot parameter, it will add 8 * stack_ring_size bytes of additional memory consumption.