Kconfig.kasan 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. # This config refers to the generic KASAN mode.
  3. config HAVE_ARCH_KASAN
  4. bool
  5. config HAVE_ARCH_KASAN_SW_TAGS
  6. bool
  7. config HAVE_ARCH_KASAN_HW_TAGS
  8. bool
  9. config HAVE_ARCH_KASAN_VMALLOC
  10. bool
  11. config CC_HAS_KASAN_GENERIC
  12. def_bool $(cc-option, -fsanitize=kernel-address)
  13. config CC_HAS_KASAN_SW_TAGS
  14. def_bool $(cc-option, -fsanitize=kernel-hwaddress)
  15. # This option is only required for software KASAN modes.
  16. # Old GCC versions don't have proper support for no_sanitize_address.
  17. # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89124 for details.
  18. config CC_HAS_WORKING_NOSANITIZE_ADDRESS
  19. def_bool !CC_IS_GCC || GCC_VERSION >= 80300
  20. menuconfig KASAN
  21. bool "KASAN: runtime memory debugger"
  22. depends on (((HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \
  23. (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)) && \
  24. CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \
  25. HAVE_ARCH_KASAN_HW_TAGS
  26. depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB)
  27. select STACKDEPOT
  28. help
  29. Enables KASAN (KernelAddressSANitizer) - runtime memory debugger,
  30. designed to find out-of-bounds accesses and use-after-free bugs.
  31. See Documentation/dev-tools/kasan.rst for details.
  32. if KASAN
  33. choice
  34. prompt "KASAN mode"
  35. default KASAN_GENERIC
  36. help
  37. KASAN has three modes:
  38. 1. generic KASAN (similar to userspace ASan,
  39. x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC),
  40. 2. software tag-based KASAN (arm64 only, based on software
  41. memory tagging (similar to userspace HWASan), enabled with
  42. CONFIG_KASAN_SW_TAGS), and
  43. 3. hardware tag-based KASAN (arm64 only, based on hardware
  44. memory tagging, enabled with CONFIG_KASAN_HW_TAGS).
  45. All KASAN modes are strictly debugging features.
  46. For better error reports enable CONFIG_STACKTRACE.
  47. config KASAN_GENERIC
  48. bool "Generic mode"
  49. depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC
  50. select SLUB_DEBUG if SLUB
  51. select CONSTRUCTORS
  52. help
  53. Enables generic KASAN mode.
  54. This mode is supported in both GCC and Clang. With GCC it requires
  55. version 8.3.0 or later. Any supported Clang version is compatible,
  56. but detection of out-of-bounds accesses for global variables is
  57. supported only since Clang 11.
  58. This mode consumes about 1/8th of available memory at kernel start
  59. and introduces an overhead of ~x1.5 for the rest of the allocations.
  60. The performance slowdown is ~x3.
  61. Currently CONFIG_KASAN_GENERIC doesn't work with CONFIG_DEBUG_SLAB
  62. (the resulting kernel does not boot).
  63. config KASAN_SW_TAGS
  64. bool "Software tag-based mode"
  65. depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS
  66. select SLUB_DEBUG if SLUB
  67. select CONSTRUCTORS
  68. help
  69. Enables software tag-based KASAN mode.
  70. This mode require software memory tagging support in the form of
  71. HWASan-like compiler instrumentation.
  72. Currently this mode is only implemented for arm64 CPUs and relies on
  73. Top Byte Ignore. This mode requires Clang.
  74. This mode consumes about 1/16th of available memory at kernel start
  75. and introduces an overhead of ~20% for the rest of the allocations.
  76. This mode may potentially introduce problems relating to pointer
  77. casting and comparison, as it embeds tags into the top byte of each
  78. pointer.
  79. Currently CONFIG_KASAN_SW_TAGS doesn't work with CONFIG_DEBUG_SLAB
  80. (the resulting kernel does not boot).
  81. config KASAN_HW_TAGS
  82. bool "Hardware tag-based mode"
  83. depends on HAVE_ARCH_KASAN_HW_TAGS
  84. depends on SLUB
  85. help
  86. Enables hardware tag-based KASAN mode.
  87. This mode requires hardware memory tagging support, and can be used
  88. by any architecture that provides it.
  89. Currently this mode is only implemented for arm64 CPUs starting from
  90. ARMv8.5 and relies on Memory Tagging Extension and Top Byte Ignore.
  91. endchoice
  92. choice
  93. prompt "Instrumentation type"
  94. depends on KASAN_GENERIC || KASAN_SW_TAGS
  95. default KASAN_OUTLINE
  96. config KASAN_OUTLINE
  97. bool "Outline instrumentation"
  98. help
  99. Before every memory access compiler insert function call
  100. __asan_load*/__asan_store*. These functions performs check
  101. of shadow memory. This is slower than inline instrumentation,
  102. however it doesn't bloat size of kernel's .text section so
  103. much as inline does.
  104. config KASAN_INLINE
  105. bool "Inline instrumentation"
  106. help
  107. Compiler directly inserts code checking shadow memory before
  108. memory accesses. This is faster than outline (in some workloads
  109. it gives about x2 boost over outline instrumentation), but
  110. make kernel's .text size much bigger.
  111. endchoice
  112. config KASAN_STACK
  113. bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST
  114. depends on KASAN_GENERIC || KASAN_SW_TAGS
  115. default y if CC_IS_GCC
  116. help
  117. The LLVM stack address sanitizer has a know problem that
  118. causes excessive stack usage in a lot of functions, see
  119. https://bugs.llvm.org/show_bug.cgi?id=38809
  120. Disabling asan-stack makes it safe to run kernels build
  121. with clang-8 with KASAN enabled, though it loses some of
  122. the functionality.
  123. This feature is always disabled when compile-testing with clang
  124. to avoid cluttering the output in stack overflow warnings,
  125. but clang users can still enable it for builds without
  126. CONFIG_COMPILE_TEST. On gcc it is assumed to always be safe
  127. to use and enabled by default.
  128. config KASAN_S390_4_LEVEL_PAGING
  129. bool "KASan: use 4-level paging"
  130. depends on S390
  131. help
  132. Compiling the kernel with KASan disables automatic 3-level vs
  133. 4-level paging selection. 3-level paging is used by default (up
  134. to 3TB of RAM with KASan enabled). This options allows to force
  135. 4-level paging instead.
  136. config KASAN_SW_TAGS_IDENTIFY
  137. bool "Enable memory corruption identification"
  138. depends on KASAN_SW_TAGS
  139. help
  140. This option enables best-effort identification of bug type
  141. (use-after-free or out-of-bounds) at the cost of increased
  142. memory consumption.
  143. config KASAN_VMALLOC
  144. bool "Back mappings in vmalloc space with real shadow memory"
  145. depends on KASAN_GENERIC && HAVE_ARCH_KASAN_VMALLOC
  146. help
  147. By default, the shadow region for vmalloc space is the read-only
  148. zero page. This means that KASAN cannot detect errors involving
  149. vmalloc space.
  150. Enabling this option will hook in to vmap/vmalloc and back those
  151. mappings with real shadow memory allocated on demand. This allows
  152. for KASAN to detect more sorts of errors (and to support vmapped
  153. stacks), but at the cost of higher memory usage.
  154. config KASAN_KUNIT_TEST
  155. tristate "KUnit-compatible tests of KASAN bug detection capabilities" if !KUNIT_ALL_TESTS
  156. depends on KASAN && KUNIT
  157. default KUNIT_ALL_TESTS
  158. help
  159. This is a KUnit test suite doing various nasty things like
  160. out of bounds and use after free accesses. It is useful for testing
  161. kernel debugging features like KASAN.
  162. For more information on KUnit and unit tests in general, please refer
  163. to the KUnit documentation in Documentation/dev-tools/kunit.
  164. config KASAN_MODULE_TEST
  165. tristate "KUnit-incompatible tests of KASAN bug detection capabilities"
  166. depends on m && KASAN && !KASAN_HW_TAGS
  167. help
  168. This is a part of the KASAN test suite that is incompatible with
  169. KUnit. Currently includes tests that do bad copy_from/to_user
  170. accesses.
  171. endif # KASAN