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

selftests/bpf: Negative test case for tail call map

This patch adds a negative test case for the following verifier error.

expected prog array map for tail call

Acked-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/aGu0i1X_jII-3aFa@mail.gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Paul Chaignon and committed by
Alexei Starovoitov
192e3aa1 df4b1eeb

+33
+2
tools/testing/selftests/bpf/prog_tests/verifier.c
··· 85 85 #include "verifier_store_release.skel.h" 86 86 #include "verifier_subprog_precision.skel.h" 87 87 #include "verifier_subreg.skel.h" 88 + #include "verifier_tailcall.skel.h" 88 89 #include "verifier_tailcall_jit.skel.h" 89 90 #include "verifier_typedef.skel.h" 90 91 #include "verifier_uninit.skel.h" ··· 220 219 void test_verifier_store_release(void) { RUN(verifier_store_release); } 221 220 void test_verifier_subprog_precision(void) { RUN(verifier_subprog_precision); } 222 221 void test_verifier_subreg(void) { RUN(verifier_subreg); } 222 + void test_verifier_tailcall(void) { RUN(verifier_tailcall); } 223 223 void test_verifier_tailcall_jit(void) { RUN(verifier_tailcall_jit); } 224 224 void test_verifier_typedef(void) { RUN(verifier_typedef); } 225 225 void test_verifier_uninit(void) { RUN(verifier_uninit); }
+31
tools/testing/selftests/bpf/progs/verifier_tailcall.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/bpf.h> 4 + #include <bpf/bpf_helpers.h> 5 + #include "bpf_misc.h" 6 + 7 + struct { 8 + __uint(type, BPF_MAP_TYPE_ARRAY); 9 + __uint(max_entries, 1); 10 + __type(key, __u32); 11 + __type(value, __u32); 12 + } map_array SEC(".maps"); 13 + 14 + SEC("socket") 15 + __description("invalid map type for tail call") 16 + __failure __msg("expected prog array map for tail call") 17 + __failure_unpriv 18 + __naked void invalid_map_for_tail_call(void) 19 + { 20 + asm volatile (" \ 21 + r2 = %[map_array] ll; \ 22 + r3 = 0; \ 23 + call %[bpf_tail_call]; \ 24 + exit; \ 25 + " : 26 + : __imm(bpf_tail_call), 27 + __imm_addr(map_array) 28 + : __clobber_all); 29 + } 30 + 31 + char _license[] SEC("license") = "GPL";