selftests/bpf: Test PTR_MAYBE_NULL arguments of struct_ops operators.
authorKui-Feng Lee <thinker.li@gmail.com>
Fri, 9 Feb 2024 02:37:50 +0000 (18:37 -0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Tue, 13 Feb 2024 23:16:44 +0000 (15:16 -0800)
commit00f239eccf461a6403b3c16e767d04f3954cae98
tree2f57131d002ff067db53ab4a62ccd8d5f735ef54
parent1611603537a4b88cec7993f32b70c03113801a46
selftests/bpf: Test PTR_MAYBE_NULL arguments of struct_ops operators.

Test if the verifier verifies nullable pointer arguments correctly for BPF
struct_ops programs.

"test_maybe_null" in struct bpf_testmod_ops is the operator defined for the
test cases here.

A BPF program should check a pointer for NULL beforehand to access the
value pointed by the nullable pointer arguments, or the verifier should
reject the programs. The test here includes two parts; the programs
checking pointers properly and the programs not checking pointers
beforehand. The test checks if the verifier accepts the programs checking
properly and rejects the programs not checking at all.

Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240209023750.1153905-5-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.h
tools/testing/selftests/bpf/prog_tests/test_struct_ops_maybe_null.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/struct_ops_maybe_null.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/struct_ops_maybe_null_fail.c [new file with mode: 0644]