Kconfig.kfence 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. config HAVE_ARCH_KFENCE
  3. bool
  4. menuconfig KFENCE
  5. bool "KFENCE: low-overhead sampling-based memory safety error detector"
  6. depends on HAVE_ARCH_KFENCE && (SLAB || SLUB)
  7. select STACKTRACE
  8. select IRQ_WORK
  9. help
  10. KFENCE is a low-overhead sampling-based detector of heap out-of-bounds
  11. access, use-after-free, and invalid-free errors. KFENCE is designed
  12. to have negligible cost to permit enabling it in production
  13. environments.
  14. See <file:Documentation/dev-tools/kfence.rst> for more details.
  15. Note that, KFENCE is not a substitute for explicit testing with tools
  16. such as KASAN. KFENCE can detect a subset of bugs that KASAN can
  17. detect, albeit at very different performance profiles. If you can
  18. afford to use KASAN, continue using KASAN, for example in test
  19. environments. If your kernel targets production use, and cannot
  20. enable KASAN due to its cost, consider using KFENCE.
  21. if KFENCE
  22. config KFENCE_STATIC_KEYS
  23. bool "Use static keys to set up allocations"
  24. default y
  25. depends on JUMP_LABEL # To ensure performance, require jump labels
  26. help
  27. Use static keys (static branches) to set up KFENCE allocations. Using
  28. static keys is normally recommended, because it avoids a dynamic
  29. branch in the allocator's fast path. However, with very low sample
  30. intervals, or on systems that do not support jump labels, a dynamic
  31. branch may still be an acceptable performance trade-off.
  32. config KFENCE_SAMPLE_INTERVAL
  33. int "Default sample interval in milliseconds"
  34. default 100
  35. help
  36. The KFENCE sample interval determines the frequency with which heap
  37. allocations will be guarded by KFENCE. May be overridden via boot
  38. parameter "kfence.sample_interval".
  39. Set this to 0 to disable KFENCE by default, in which case only
  40. setting "kfence.sample_interval" to a non-zero value enables KFENCE.
  41. config KFENCE_NUM_OBJECTS
  42. int "Number of guarded objects available"
  43. range 1 65535
  44. default 255
  45. help
  46. The number of guarded objects available. For each KFENCE object, 2
  47. pages are required; with one containing the object and two adjacent
  48. ones used as guard pages.
  49. config KFENCE_STRESS_TEST_FAULTS
  50. int "Stress testing of fault handling and error reporting" if EXPERT
  51. default 0
  52. help
  53. The inverse probability with which to randomly protect KFENCE object
  54. pages, resulting in spurious use-after-frees. The main purpose of
  55. this option is to stress test KFENCE with concurrent error reports
  56. and allocations/frees. A value of 0 disables stress testing logic.
  57. Only for KFENCE testing; set to 0 if you are not a KFENCE developer.
  58. config KFENCE_KUNIT_TEST
  59. tristate "KFENCE integration test suite" if !KUNIT_ALL_TESTS
  60. default KUNIT_ALL_TESTS
  61. depends on TRACEPOINTS && KUNIT
  62. help
  63. Test suite for KFENCE, testing various error detection scenarios with
  64. various allocation types, and checking that reports are correctly
  65. output to console.
  66. Say Y here if you want the test to be built into the kernel and run
  67. during boot; say M if you want the test to build as a module; say N
  68. if you are unsure.
  69. endif # KFENCE