| 1 | # SPDX-License-Identifier: GPL-2.0-only |
| 2 | config HAVE_ARCH_KMSAN |
| 3 | bool |
| 4 | |
| 5 | config HAVE_KMSAN_COMPILER |
| 6 | def_bool $(cc-option,-fsanitize=kernel-memory) |
| 7 | |
| 8 | config KMSAN |
| 9 | bool "KMSAN: detector of uninitialized values use" |
| 10 | depends on HAVE_ARCH_KMSAN && HAVE_KMSAN_COMPILER |
| 11 | depends on DEBUG_KERNEL && !KASAN && !KCSAN |
| 12 | depends on !PREEMPT_RT |
| 13 | select STACKDEPOT |
| 14 | select STACKDEPOT_ALWAYS_INIT |
| 15 | help |
| 16 | KernelMemorySanitizer (KMSAN) is a dynamic detector of uses of |
| 17 | uninitialized values in the kernel. It is based on compiler |
| 18 | instrumentation provided by Clang and thus requires Clang to build. |
| 19 | |
| 20 | An important note is that KMSAN is not intended for production use, |
| 21 | because it drastically increases kernel memory footprint and slows |
| 22 | the whole system down. |
| 23 | |
| 24 | See <file:Documentation/dev-tools/kmsan.rst> for more details. |
| 25 | |
| 26 | if KMSAN |
| 27 | |
| 28 | config KMSAN_CHECK_PARAM_RETVAL |
| 29 | bool "Check for uninitialized values passed to and returned from functions" |
| 30 | default y |
| 31 | help |
| 32 | If the compiler supports -fsanitize-memory-param-retval, KMSAN will |
| 33 | eagerly check every function parameter passed by value and every |
| 34 | function return value. |
| 35 | |
| 36 | Disabling KMSAN_CHECK_PARAM_RETVAL will result in tracking shadow for |
| 37 | function parameters and return values across function borders. This |
| 38 | is a more relaxed mode, but it generates more instrumentation code and |
| 39 | may potentially report errors in corner cases when non-instrumented |
| 40 | functions call instrumented ones. |
| 41 | |
| 42 | config KMSAN_KUNIT_TEST |
| 43 | tristate "KMSAN integration test suite" if !KUNIT_ALL_TESTS |
| 44 | default KUNIT_ALL_TESTS |
| 45 | depends on TRACEPOINTS && KUNIT |
| 46 | help |
| 47 | Test suite for KMSAN, testing various error detection scenarios, |
| 48 | and checking that reports are correctly output to console. |
| 49 | |
| 50 | Say Y here if you want the test to be built into the kernel and run |
| 51 | during boot; say M if you want the test to build as a module; say N |
| 52 | if you are unsure. |
| 53 | |
| 54 | endif |