]> www.infradead.org Git - users/jedix/linux-maple.git/commit
selftests/bpf: Test referenced kptr arguments of struct_ops programs
authorAmery Hung <amery.hung@bytedance.com>
Mon, 17 Feb 2025 19:06:38 +0000 (11:06 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 18 Feb 2025 02:47:27 +0000 (18:47 -0800)
commit6991ec6beb262b8c21ba3ee1992d7e81d8203769
tree0e2c2700f53e83677b2822d745e448bd9a5a7c17
parenta687df2008f66669deec27f74d1793c8a537a4bd
selftests/bpf: Test referenced kptr arguments of struct_ops programs

Test referenced kptr acquired through struct_ops argument tagged with
"__ref". The success case checks whether 1) a reference to the correct
type is acquired, and 2) the referenced kptr argument can be accessed in
multiple paths as long as it hasn't been released. In the fail cases,
we first confirm that a referenced kptr acquried through a struct_ops
argument is not allowed to be leaked. Then, we make sure this new
referenced kptr acquiring mechanism does not accidentally allow referenced
kptrs to flow into global subprograms through their arguments.

Signed-off-by: Amery Hung <amery.hung@bytedance.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20250217190640.1748177-4-ameryhung@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/test_struct_ops_refcounted.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/struct_ops_refcounted.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/struct_ops_refcounted_fail__global_subprog.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/struct_ops_refcounted_fail__ref_leak.c [new file with mode: 0644]
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
tools/testing/selftests/bpf/test_kmods/bpf_testmod.h