Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add kprobe session verifier test for return value

Making sure kprobe.session program can return only [0,1] values.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20241108134544.480660-11-jolsa@kernel.org

authored by

Jiri Olsa and committed by
Andrii Nakryiko
504d21d9 8c3a48b0

+33
+2
tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
··· 6 6 #include "kprobe_multi_override.skel.h" 7 7 #include "kprobe_multi_session.skel.h" 8 8 #include "kprobe_multi_session_cookie.skel.h" 9 + #include "kprobe_multi_verifier.skel.h" 9 10 #include "bpf/libbpf_internal.h" 10 11 #include "bpf/hashmap.h" 11 12 ··· 765 764 test_session_skel_api(); 766 765 if (test__start_subtest("session_cookie")) 767 766 test_session_cookie_skel_api(); 767 + RUN_TESTS(kprobe_multi_verifier); 768 768 }
+31
tools/testing/selftests/bpf/progs/kprobe_multi_verifier.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include "vmlinux.h" 3 + #include <bpf/bpf_helpers.h> 4 + #include <bpf/bpf_tracing.h> 5 + #include <bpf/usdt.bpf.h> 6 + #include "bpf_misc.h" 7 + 8 + char _license[] SEC("license") = "GPL"; 9 + 10 + 11 + SEC("kprobe.session") 12 + __success 13 + int kprobe_session_return_0(struct pt_regs *ctx) 14 + { 15 + return 0; 16 + } 17 + 18 + SEC("kprobe.session") 19 + __success 20 + int kprobe_session_return_1(struct pt_regs *ctx) 21 + { 22 + return 1; 23 + } 24 + 25 + SEC("kprobe.session") 26 + __failure 27 + __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]") 28 + int kprobe_session_return_2(struct pt_regs *ctx) 29 + { 30 + return 2; 31 + }