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