Kconfig.ubsan

CONFIG_ARCH_HAS_UBSAN

On

CONFIG_UBSAN Undefined behaviour sanity checker

On

This option enables the Undefined Behaviour sanity checker. Compile-time instrumentation is used to detect various undefined behaviours at runtime. For more details, see: Documentation/dev-tools/ubsan.rst

If UBSAN

CONFIG_UBSAN_TRAP Abort on Sanitizer warnings (smaller kernel but less verbose)

Unknown

Building kernels with Sanitizer features enabled tends to grow the kernel size by around 5%, due to adding all the debugging text on failure paths. To avoid this, Sanitizer instrumentation can just issue a trap. This reduces the kernel size overhead but turns all warnings (including potentially harmless conditions) into full exceptions that abort the running kernel code (regardless of context, locks held, etc), which may destabilize the system. For some system builders this is an acceptable trade-off.

Also note that selecting Y will cause your kernel to Oops with an "illegal instruction" error with no further details when a UBSAN violation occurs. (Except on arm64 and x86, which will report which Sanitizer failed.) This may make it hard to determine whether an Oops was caused by UBSAN or to figure out the details of a UBSAN violation. It makes the kernel log output less useful for bug reports.

CONFIG_CC_HAS_UBSAN_BOUNDS_STRICT

On

The -fsanitize=bounds-strict option is only available on GCC, but uses the more strict handling of arrays that includes knowledge of flexible arrays, which is comparable to Clang's regular -fsanitize=bounds.

CONFIG_CC_HAS_UBSAN_ARRAY_BOUNDS

Unknown

Under Clang, the -fsanitize=bounds option is actually composed of two more specific options, -fsanitize=array-bounds and -fsanitize=local-bounds. However, -fsanitize=local-bounds can only be used when trap mode is enabled. (See also the help for CONFIG_LOCAL_BOUNDS.) Explicitly check for -fsanitize=array-bounds so that we can build up the options needed for UBSAN_BOUNDS with or without UBSAN_TRAP.

CONFIG_UBSAN_LOCAL_BOUNDS

Unknown

This option enables Clang's -fsanitize=local-bounds which traps when an access through a pointer that is derived from an object of a statically-known size, where an added offset (which may not be known statically) is out-of-bounds. Since this option is trap-only, it depends on CONFIG_UBSAN_TRAP.

CONFIG_UBSAN_SHIFT Perform checking for bit-shift overflows

On

This option enables -fsanitize=shift which checks for bit-shift operations that overflow to the left or go switch to negative for signed types.

CONFIG_UBSAN_DIV_ZERO Perform checking for integer divide-by-zero

On

This option enables -fsanitize=integer-divide-by-zero which checks for integer division by zero. This is effectively redundant with the kernel's existing exception handling, though it can provide greater debugging information.

CONFIG_UBSAN_UNREACHABLE Perform checking for unreachable code

Unknown

This option enables -fsanitize=unreachable which checks for control flow reaching an expected-to-be-unreachable position.

CONFIG_UBSAN_INTEGER_WRAP Perform checking for integer arithmetic wrap-around

Unknown

This option enables all of the sanitizers involved in integer overflow (wrap-around) mitigation: signed-integer-overflow, unsigned-integer-overflow, implicit-signed-integer-truncation, and implicit-unsigned-integer-truncation. This is currently limited only to the size_t type while testing and compiler development continues.

  • Depends onn

CONFIG_UBSAN_BOOL Perform checking for non-boolean values used as boolean

On

This option enables -fsanitize=bool which checks for boolean values being loaded that are neither 0 nor 1.

CONFIG_UBSAN_ENUM Perform checking for out of bounds enum values

On

This option enables -fsanitize=enum which checks for values being loaded into an enum that are outside the range of given values for the given enum.

CONFIG_TEST_UBSAN Module for testing for undefined behavior detection

  • Off
  • Module
  • Built in

This is a test module for UBSAN. It triggers various undefined behavior, and detect it.

  • Depends onUBSAN && m &&

CONFIG_UBSAN_KVM_EL2 UBSAN for KVM code at EL2

Unknown

Enable UBSAN when running on ARM64 with KVM in a split mode (nvhe/hvhe/protected) for the hypervisor code running in EL2. In this mode, any UBSAN violation in EL2 would panic the kernel and information similar to UBSAN_TRAP would be printed.