Kconfig.kasan 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # This config refers to the generic KASAN mode.
  2. config HAVE_ARCH_KASAN
  3. bool
  4. config HAVE_ARCH_KASAN_SW_TAGS
  5. bool
  6. # Upstream uses $(cc-option, -fsanitize=kernel-address), which requires
  7. # cc-option support. Here we instead check CC in scripts/Makefile.kasan.
  8. config CC_HAS_KASAN_GENERIC
  9. def_bool HAVE_ARCH_KASAN
  10. config CC_HAS_KASAN_SW_TAGS
  11. def_bool HAVE_ARCH_KASAN_SW_TAGS
  12. config KASAN
  13. bool "KASAN: runtime memory debugger"
  14. depends on (HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \
  15. (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)
  16. depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB)
  17. help
  18. Enables KASAN (KernelAddressSANitizer) - runtime memory debugger,
  19. designed to find out-of-bounds accesses and use-after-free bugs.
  20. See Documentation/dev-tools/kasan.rst for details.
  21. choice
  22. prompt "KASAN mode"
  23. depends on KASAN
  24. default KASAN_GENERIC
  25. help
  26. KASAN has two modes: generic KASAN (similar to userspace ASan,
  27. x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC) and
  28. software tag-based KASAN (a version based on software memory
  29. tagging, arm64 only, similar to userspace HWASan, enabled with
  30. CONFIG_KASAN_SW_TAGS).
  31. Both generic and tag-based KASAN are strictly debugging features.
  32. config KASAN_GENERIC
  33. bool "Generic mode"
  34. depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC
  35. depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB)
  36. select SLUB_DEBUG if SLUB
  37. select CONSTRUCTORS
  38. select STACKDEPOT
  39. help
  40. Enables generic KASAN mode.
  41. Supported in both GCC and Clang. With GCC it requires version 4.9.2
  42. or later for basic support and version 5.0 or later for detection of
  43. out-of-bounds accesses for stack and global variables and for inline
  44. instrumentation mode (CONFIG_KASAN_INLINE). With Clang it requires
  45. version 3.7.0 or later and it doesn't support detection of
  46. out-of-bounds accesses for global variables yet.
  47. This mode consumes about 1/8th of available memory at kernel start
  48. and introduces an overhead of ~x1.5 for the rest of the allocations.
  49. The performance slowdown is ~x3.
  50. For better error detection enable CONFIG_STACKTRACE.
  51. Currently CONFIG_KASAN_GENERIC doesn't work with CONFIG_DEBUG_SLAB
  52. (the resulting kernel does not boot).
  53. config KASAN_SW_TAGS
  54. bool "Software tag-based mode"
  55. depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS
  56. depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB)
  57. select SLUB_DEBUG if SLUB
  58. select CONSTRUCTORS
  59. select STACKDEPOT
  60. help
  61. Enables software tag-based KASAN mode.
  62. This mode requires Top Byte Ignore support by the CPU and therefore
  63. is only supported for arm64.
  64. This mode requires Clang version 7.0.0 or later.
  65. This mode consumes about 1/16th of available memory at kernel start
  66. and introduces an overhead of ~20% for the rest of the allocations.
  67. This mode may potentially introduce problems relating to pointer
  68. casting and comparison, as it embeds tags into the top byte of each
  69. pointer.
  70. For better error detection enable CONFIG_STACKTRACE.
  71. Currently CONFIG_KASAN_SW_TAGS doesn't work with CONFIG_DEBUG_SLAB
  72. (the resulting kernel does not boot).
  73. endchoice
  74. choice
  75. prompt "Instrumentation type"
  76. depends on KASAN
  77. default KASAN_OUTLINE
  78. config KASAN_OUTLINE
  79. bool "Outline instrumentation"
  80. help
  81. Before every memory access compiler insert function call
  82. __asan_load*/__asan_store*. These functions performs check
  83. of shadow memory. This is slower than inline instrumentation,
  84. however it doesn't bloat size of kernel's .text section so
  85. much as inline does.
  86. config KASAN_INLINE
  87. bool "Inline instrumentation"
  88. help
  89. Compiler directly inserts code checking shadow memory before
  90. memory accesses. This is faster than outline (in some workloads
  91. it gives about x2 boost over outline instrumentation), but
  92. make kernel's .text size much bigger.
  93. For CONFIG_KASAN_GENERIC this requires GCC 5.0 or later.
  94. endchoice
  95. config KASAN_STACK_ENABLE
  96. bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST
  97. default !(CLANG_VERSION < 90000)
  98. depends on KASAN
  99. help
  100. The LLVM stack address sanitizer has a know problem that
  101. causes excessive stack usage in a lot of functions, see
  102. https://bugs.llvm.org/show_bug.cgi?id=38809
  103. Disabling asan-stack makes it safe to run kernels build
  104. with clang-8 with KASAN enabled, though it loses some of
  105. the functionality.
  106. This feature is always disabled when compile-testing with clang-8
  107. or earlier to avoid cluttering the output in stack overflow
  108. warnings, but clang-8 users can still enable it for builds without
  109. CONFIG_COMPILE_TEST. On gcc and later clang versions it is
  110. assumed to always be safe to use and enabled by default.
  111. config KASAN_STACK
  112. int
  113. default 1 if KASAN_STACK_ENABLE || CC_IS_GCC
  114. default 0
  115. config KASAN_SW_TAGS_IDENTIFY
  116. bool "Enable memory corruption identification"
  117. depends on KASAN_SW_TAGS
  118. help
  119. This option enables best-effort identification of bug type
  120. (use-after-free or out-of-bounds) at the cost of increased
  121. memory consumption.
  122. config TEST_KASAN
  123. tristate "Module for testing KASAN for bug detection"
  124. depends on m && KASAN
  125. help
  126. This is a test module doing various nasty things like
  127. out of bounds accesses, use after free. It is useful for testing
  128. kernel debugging features like KASAN.