blob: 58f8d03d037b55207cd625c793ba34e6f08a79ac [file] [log] [blame]
Thomas Gleixnerec8f24b2019-05-19 13:07:45 +01001# SPDX-License-Identifier: GPL-2.0-only
Andrey Ryabininc6d30852016-01-20 15:00:55 -08002config ARCH_HAS_UBSAN_SANITIZE_ALL
3 bool
4
Kees Cook277a1082020-04-06 20:12:31 -07005menuconfig UBSAN
Andrey Ryabininc6d30852016-01-20 15:00:55 -08006 bool "Undefined behaviour sanity checker"
7 help
Kees Cook0887a7e2020-04-06 20:12:27 -07008 This option enables the Undefined Behaviour sanity checker.
Andrey Ryabininc6d30852016-01-20 15:00:55 -08009 Compile-time instrumentation is used to detect various undefined
Kees Cook0887a7e2020-04-06 20:12:27 -070010 behaviours at runtime. For more details, see:
11 Documentation/dev-tools/ubsan.rst
12
Kees Cook277a1082020-04-06 20:12:31 -070013if UBSAN
14
Kees Cook0887a7e2020-04-06 20:12:27 -070015config UBSAN_TRAP
16 bool "On Sanitizer warnings, abort the running kernel code"
Kees Cook0887a7e2020-04-06 20:12:27 -070017 depends on $(cc-option, -fsanitize-undefined-trap-on-error)
18 help
19 Building kernels with Sanitizer features enabled tends to grow
20 the kernel size by around 5%, due to adding all the debugging
21 text on failure paths. To avoid this, Sanitizer instrumentation
22 can just issue a trap. This reduces the kernel size overhead but
23 turns all warnings (including potentially harmless conditions)
24 into full exceptions that abort the running kernel code
25 (regardless of context, locks held, etc), which may destabilize
26 the system. For some system builders this is an acceptable
27 trade-off.
Andrey Ryabininc6d30852016-01-20 15:00:55 -080028
Arnd Bergmannea91a1d2020-05-21 16:20:37 +020029config UBSAN_KCOV_BROKEN
30 def_bool KCOV && CC_HAS_SANCOV_TRACE_PC
31 depends on CC_IS_CLANG
32 depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=bounds -fsanitize-coverage=trace-pc)
33 help
34 Some versions of clang support either UBSAN or KCOV but not the
35 combination of the two.
36 See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status
37 in newer releases.
38
Kees Cook277a1082020-04-06 20:12:31 -070039config UBSAN_BOUNDS
40 bool "Perform array index bounds checking"
41 default UBSAN
Arnd Bergmannea91a1d2020-05-21 16:20:37 +020042 depends on !UBSAN_KCOV_BROKEN
Kees Cook277a1082020-04-06 20:12:31 -070043 help
44 This option enables detection of directly indexed out of bounds
45 array accesses, where the array size is known at compile time.
46 Note that this does not protect array overflows via bad calls
47 to the {str,mem}*cpy() family of functions (that is addressed
48 by CONFIG_FORTIFY_SOURCE).
49
George Popescu6a6155f2020-10-15 20:13:38 -070050config UBSAN_LOCAL_BOUNDS
51 bool "Perform array local bounds checking"
52 depends on UBSAN_TRAP
53 depends on CC_IS_CLANG
54 depends on !UBSAN_KCOV_BROKEN
55 help
56 This option enables -fsanitize=local-bounds which traps when an
57 exception/error is detected. Therefore, it should be enabled only
58 if trapping is expected.
59 Enabling this option detects errors due to accesses through a
60 pointer that is derived from an object of a statically-known size,
61 where an added offset (which may not be known statically) is
62 out-of-bounds.
63
Kees Cook277a1082020-04-06 20:12:31 -070064config UBSAN_MISC
65 bool "Enable all other Undefined Behavior sanity checks"
66 default UBSAN
67 help
68 This option enables all sanity checks that don't have their
69 own Kconfig options. Disable this if you only want to have
70 individually selected checks.
71
Andrey Ryabininc6d30852016-01-20 15:00:55 -080072config UBSAN_SANITIZE_ALL
73 bool "Enable instrumentation for the entire kernel"
Andrey Ryabininc6d30852016-01-20 15:00:55 -080074 depends on ARCH_HAS_UBSAN_SANITIZE_ALL
Andrey Ryabinindde5cf32016-03-22 14:27:45 -070075
76 # We build with -Wno-maybe-uninitilzed, but we still want to
77 # use -Wmaybe-uninitilized in allmodconfig builds.
78 # So dependsy bellow used to disable this option in allmodconfig
79 depends on !COMPILE_TEST
Andrey Ryabininc6d30852016-01-20 15:00:55 -080080 default y
81 help
82 This option activates instrumentation for the entire kernel.
83 If you don't enable this option, you have to explicitly specify
84 UBSAN_SANITIZE := y for the files/directories you want to check for UB.
Yang Shi77075352016-02-11 16:12:55 -080085 Enabling this option will get kernel image size increased
86 significantly.
Andrey Ryabininc6d30852016-01-20 15:00:55 -080087
Anders Roxell1a6a1db2019-03-07 16:30:16 -080088config UBSAN_ALIGNMENT
Kees Cook8d58f222020-05-07 18:36:23 -070089 bool "Enable checks for pointers alignment"
90 default !HAVE_EFFICIENT_UNALIGNED_ACCESS
Kees Cook9380ce2462020-06-01 21:52:46 -070091 depends on !UBSAN_TRAP
Kees Cook8d58f222020-05-07 18:36:23 -070092 help
93 This option enables the check of unaligned memory accesses.
94 Enabling this option on architectures that support unaligned
95 accesses may produce a lot of false positives.
Anders Roxell1a6a1db2019-03-07 16:30:16 -080096
Jinbum Park854686f2018-04-10 16:32:58 -070097config TEST_UBSAN
98 tristate "Module for testing for undefined behavior detection"
Kees Cook277a1082020-04-06 20:12:31 -070099 depends on m
Jinbum Park854686f2018-04-10 16:32:58 -0700100 help
101 This is a test module for UBSAN.
102 It triggers various undefined behavior, and detect it.
Kees Cook277a1082020-04-06 20:12:31 -0700103
104endif # if UBSAN