Kconfig.kasan

CONFIG_HAVE_ARCH_KASAN

On

CONFIG_HAVE_ARCH_KASAN_SW_TAGS

Unknown

CONFIG_HAVE_ARCH_KASAN_HW_TAGS

Unknown

CONFIG_HAVE_ARCH_KASAN_VMALLOC

On

CONFIG_ARCH_DISABLE_KASAN_INLINE

Unknown

Disables both inline and stack instrumentation. Selected by architectures that do not support these instrumentation types.

CONFIG_ARCH_NEEDS_DEFER_KASAN

Unknown

CONFIG_ARCH_DEFER_KASAN

Unknown

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.

CONFIG_CC_HAS_KASAN_GENERIC

On
Default
  • y

CONFIG_CC_HAS_KASAN_SW_TAGS

On
Default
  • y

CONFIG_KASAN KASAN: dynamic memory safety error detector

On

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.

If KASAN

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

On

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.

CONFIG_KASAN_SW_TAGS Software Tag-Based KASAN

Unknown

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.

CONFIG_KASAN_HW_TAGS Hardware Tag-Based KASAN

Unknown

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.

End of KASAN mode

Instrumentation type

CONFIG_KASAN_OUTLINE Outline instrumentation

Off

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.

CONFIG_KASAN_INLINE Inline instrumentation

On

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.

End of Instrumentation type

CONFIG_KASAN_STACK Stack instrumentation (unsafe)

On

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.

CONFIG_KASAN_VMALLOC Check accesses to vmalloc allocations

On

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.

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

CONFIG_KASAN_EXTRA_INFO Record and report more information

On

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.