Igris Blog
Understanding KASan

Understanding KASan

July 20, 2024
2 min read
Table of Contents

Kernel Address Sanitizer (KASAN) is a fast memory corruption detector for the Linux kernel. KASAN detects out-of-bounds, use-after-free, and invalid-free bugs in slab, page_alloc, vmalloc, stack, and global memory.

KASAN has 3 modes:

  • Generic KASAN, which is intended to be used for debugging. This mode is supported by many CPU architectures.
  • Software Tag-Based KASAN, which is intended for testing in near-production environments. This mode has a lower RAM overhead than the Generic mode but is only supported on arm64.
  • Hardware Tag-Based KASAN, which intended to be used in production as an in-field bug detector or a security mitigation. This mode is based on the Arm Memory Tagging Extension and is expected to have a very low performance overhead.

For more details about each mode, see the kernel documentation and these talks:

See KFENCE for an alternative sampling-based low-overhead memory corruption detector that can be used in production environments.

Configuration

CONFIG_KASAN=y
CONFIG_KASAN_GENERIC=y

Optionally, you can pass KASAN specific parameters at boot time to control its behavior:

kasane=1                 # Enable KASAN
kasan-out-of-bounds=on   # Report out-of-bounds access
kasan-use-after-free=on  # Report use-after-free bugs

Check kernel logs (dmesg command) or system logs (/var/log/messages, /var/log/syslog) for KASAN reports.

References