Skip to content

Commit ceb65eb

Browse files
borkmannAlexei Starovoitov
authored andcommitted
selftests/bpf: Add test coverage for reg_set_min_max handling
Add a test case for the jmp32/k fix to ensure selftests have coverage. Before fix: # ./vmtest.sh -- ./test_progs -t verifier_or_jmp32_k [...] ./test_progs -t verifier_or_jmp32_k tester_init:PASS:tester_log_buf 0 nsec process_subtest:PASS:obj_open_mem 0 nsec process_subtest:PASS:specs_alloc 0 nsec run_subtest:PASS:obj_open_mem 0 nsec run_subtest:FAIL:unexpected_load_success unexpected success: 0 Rust-for-Linux#492/1 verifier_or_jmp32_k/or_jmp32_k: bit ops + branch on unknown value:FAIL Rust-for-Linux#492 verifier_or_jmp32_k:FAIL Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED After fix: # ./vmtest.sh -- ./test_progs -t verifier_or_jmp32_k [...] ./test_progs -t verifier_or_jmp32_k Rust-for-Linux#492/1 verifier_or_jmp32_k/or_jmp32_k: bit ops + branch on unknown value:OK Rust-for-Linux#492 verifier_or_jmp32_k:OK Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/r/20240613115310.25383-3-daniel@iogearbox.net Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent e73cd1c commit ceb65eb

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tools/testing/selftests/bpf/prog_tests/verifier.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "verifier_movsx.skel.h"
5454
#include "verifier_netfilter_ctx.skel.h"
5555
#include "verifier_netfilter_retcode.skel.h"
56+
#include "verifier_or_jmp32_k.skel.h"
5657
#include "verifier_precision.skel.h"
5758
#include "verifier_prevent_map_lookup.skel.h"
5859
#include "verifier_raw_stack.skel.h"
@@ -170,6 +171,7 @@ void test_verifier_meta_access(void) { RUN(verifier_meta_access); }
170171
void test_verifier_movsx(void) { RUN(verifier_movsx); }
171172
void test_verifier_netfilter_ctx(void) { RUN(verifier_netfilter_ctx); }
172173
void test_verifier_netfilter_retcode(void) { RUN(verifier_netfilter_retcode); }
174+
void test_verifier_or_jmp32_k(void) { RUN(verifier_or_jmp32_k); }
173175
void test_verifier_precision(void) { RUN(verifier_precision); }
174176
void test_verifier_prevent_map_lookup(void) { RUN(verifier_prevent_map_lookup); }
175177
void test_verifier_raw_stack(void) { RUN(verifier_raw_stack); }
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
SEC("socket")
8+
__description("or_jmp32_k: bit ops + branch on unknown value")
9+
__failure
10+
__msg("R0 invalid mem access 'scalar'")
11+
__naked void or_jmp32_k(void)
12+
{
13+
asm volatile (" \
14+
r0 = 0xffffffff; \
15+
r0 /= 1; \
16+
r1 = 0; \
17+
w1 = -1; \
18+
w1 >>= 1; \
19+
w0 &= w1; \
20+
w0 |= 2; \
21+
if w0 != 0x7ffffffd goto l1; \
22+
r0 = 1; \
23+
exit; \
24+
l3: \
25+
r0 = 5; \
26+
*(u64*)(r0 - 8) = r0; \
27+
exit; \
28+
l2: \
29+
w0 -= 0xe; \
30+
if w0 == 1 goto l3; \
31+
r0 = 4; \
32+
exit; \
33+
l1: \
34+
w0 -= 0x7ffffff0; \
35+
if w0 s>= 0xe goto l2; \
36+
r0 = 3; \
37+
exit; \
38+
" ::: __clobber_all);
39+
}
40+
41+
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)