mirror-linux/lib/tests
Martin Kaiser ef5581bb30 test_kprobes: clear kprobes between test runs
Running the kprobes sanity tests twice makes all tests fail and
eventually crashes the kernel.

[root@martin-riscv-1 ~]# echo 1 > /sys/kernel/debug/kunit/kprobes_test/run
...
   # Totals: pass:5 fail:0 skip:0 total:5
   ok 1 kprobes_test
[root@martin-riscv-1 ~]# echo 1 > /sys/kernel/debug/kunit/kprobes_test/run
...
  # test_kprobe: EXPECTATION FAILED at lib/tests/test_kprobes.c:64
  Expected 0 == register_kprobe(&kp), but
      register_kprobe(&kp) == -22 (0xffffffffffffffea)
...
  Unable to handle kernel paging request ...

The testsuite defines several kprobes and kretprobes as static variables
that are preserved across test runs.

After register_kprobe and unregister_kprobe, a kprobe contains some
leftover data that must be cleared before the kprobe can be registered
again. The tests are setting symbol_name to define the probe location.
Address and flags must be cleared.

The existing code clears some of the probes between subsequent tests, but
not between two test runs. The leftover data from a previous test run
makes the registrations fail in the next run.

Move the cleanups for all kprobes into kprobes_test_init, this function
is called before each single test (including the first test of a test
run).

Link: https://lore.kernel.org/all/20260507134615.1010905-1-martin@kaiser.cx/

Fixes: e44e81c5b9 ("kprobes: convert tests to kunit")
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
2026-05-08 10:03:44 +09:00
..
module
Makefile printf: Compile the kunit test with DISABLE_BRANCH_PROFILING DISABLE_BRANCH_PROFILING 2026-04-15 09:36:30 +02:00
base64_kunit.c lib: add KUnit tests for base64 encoding/decoding 2025-11-20 14:03:44 -08:00
bitfield_kunit.c
bitops_kunit.c lib/tests: extend KUnit test for bitops with more cases 2026-02-08 18:47:29 -05:00
blackhole_dev_kunit.c Networking changes for 6.15. 2025-03-26 21:48:21 -07:00
checksum_kunit.c
cmdline_kunit.c
cpumask_kunit.c
ffs_kunit.c KUnit: ffs: Validate all the __attribute_const__ annotations 2025-09-08 14:58:52 -07:00
fortify_kunit.c kunit/fortify: Add back "volatile" for sizeof() constants 2025-07-14 22:43:52 -07:00
glob_kunit.c lib/glob: convert selftest to KUnit 2026-01-26 19:07:13 -08:00
hashtable_test.c
is_signed_type_kunit.c
kfifo_kunit.c
kunit_iov_iter.c lib: kunit_iov_iter: add tests for extract_iter_to_sg 2026-04-02 23:36:23 -07:00
list-private-test.c list: add kunit test for private list primitives 2026-02-08 00:13:32 -08:00
list-test.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
liveupdate.c liveupdate: remove liveupdate_test_unregister() 2026-04-18 00:10:50 -07:00
longest_symbol_kunit.c kunit: fix longest symbol length test 2025-07-10 14:02:07 -06:00
memcpy_kunit.c
min_heap_kunit.c lib/tests: convert test_min_heap module to KUnit 2026-01-26 19:07:10 -08:00
overflow_kunit.c kunit/overflow: Add tests for STACK_FLEX_ARRAY_SIZE() helper 2025-05-08 09:42:05 -07:00
printf_kunit.c printf: add IPv6 address format tests 2026-03-24 14:20:19 +01:00
randstruct_kunit.c lib/tests: randstruct: Add deep function pointer layout test 2025-05-08 09:42:40 -07:00
scanf_kunit.c
seq_buf_kunit.c seq_buf: Introduce KUnit tests 2025-07-19 23:03:24 -07:00
siphash_kunit.c
slub_kunit.c lib/tests/slub_kunit: add a test case for {kmalloc,kfree}_nolock 2026-04-07 11:21:32 +02:00
stackinit_kunit.c Kbuild: remove structleak gcc plugin 2025-04-30 21:57:09 +02:00
string_helpers_kunit.c
string_kunit.c lib/string_kunit: extend benchmarks to strnlen() and chr searches 2026-04-04 18:42:44 -06:00
test_bits.c test_bits: add tests for __GENMASK() and __GENMASK_ULL() 2025-07-31 11:28:03 -04:00
test_fprobe.c lib/test_fprobe: add testcase for mixed fprobe 2025-11-11 22:32:09 +09:00
test_hash.c
test_kprobes.c test_kprobes: clear kprobes between test runs 2026-05-08 10:03:44 +09:00
test_linear_ranges.c
test_list_sort.c test_list_sort: fix up const mismatch 2026-01-05 15:32:03 -07:00
test_ratelimit.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
test_sort.c
usercopy_kunit.c kunit/usercopy: Disable u64 test on 32-bit SPARC 2025-04-28 10:32:43 -07:00
util_macros_kunit.c
uuid_kunit.c lib/tests: convert test_uuid module to KUnit 2026-01-20 19:44:18 -08:00