Kconfig.kfence 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_SAMPLE_INTERVAL
  23. int "Default sample interval in milliseconds"
  24. default 100
  25. help
  26. The KFENCE sample interval determines the frequency with which heap
  27. allocations will be guarded by KFENCE. May be overridden via boot
  28. parameter "kfence.sample_interval".
  29. Set this to 0 to disable KFENCE by default, in which case only
  30. setting "kfence.sample_interval" to a non-zero value enables KFENCE.
  31. config KFENCE_NUM_OBJECTS
  32. int "Number of guarded objects available"
  33. range 1 65535
  34. default 255
  35. help
  36. The number of guarded objects available. For each KFENCE object, 2
  37. pages are required; with one containing the object and two adjacent
  38. ones used as guard pages.
  39. config KFENCE_DEFERRABLE
  40. bool "Use a deferrable timer to trigger allocations"
  41. help
  42. Use a deferrable timer to trigger allocations. This avoids forcing
  43. CPU wake-ups if the system is idle, at the risk of a less predictable
  44. sample interval.
  45. Warning: The KUnit test suite fails with this option enabled - due to
  46. the unpredictability of the sample interval!
  47. Say N if you are unsure.
  48. config KFENCE_STATIC_KEYS
  49. bool "Use static keys to set up allocations" if EXPERT
  50. depends on JUMP_LABEL
  51. help
  52. Use static keys (static branches) to set up KFENCE allocations. This
  53. option is only recommended when using very large sample intervals, or
  54. performance has carefully been evaluated with this option.
  55. Using static keys comes with trade-offs that need to be carefully
  56. evaluated given target workloads and system architectures. Notably,
  57. enabling and disabling static keys invoke IPI broadcasts, the latency
  58. and impact of which is much harder to predict than a dynamic branch.
  59. Say N if you are unsure.
  60. config KFENCE_STRESS_TEST_FAULTS
  61. int "Stress testing of fault handling and error reporting" if EXPERT
  62. default 0
  63. help
  64. The inverse probability with which to randomly protect KFENCE object
  65. pages, resulting in spurious use-after-frees. The main purpose of
  66. this option is to stress test KFENCE with concurrent error reports
  67. and allocations/frees. A value of 0 disables stress testing logic.
  68. Only for KFENCE testing; set to 0 if you are not a KFENCE developer.
  69. config KFENCE_KUNIT_TEST
  70. tristate "KFENCE integration test suite" if !KUNIT_ALL_TESTS
  71. default KUNIT_ALL_TESTS
  72. depends on TRACEPOINTS && KUNIT
  73. help
  74. Test suite for KFENCE, testing various error detection scenarios with
  75. various allocation types, and checking that reports are correctly
  76. output to console.
  77. Say Y here if you want the test to be built into the kernel and run
  78. during boot; say M if you want the test to build as a module; say N
  79. if you are unsure.
  80. endif # KFENCE