From: Alexei Starovoitov The loop that can exit, but is not known to, is accepted with may_goto added to it. The tests that expect "infinite loop detected" or "BPF program is too large" for such loop expect it to load: - verifier_cfg: conditional loop - verifier_movsx: MOV32SX, S8, var_off u32_max - verifier_search_pruning: short_loop1 - verif_scale_loop3 - test_verifier: "calls: conditional call 6". Don't run it, it takes may_goto 250ms to end it. The loops that never exit are rejected as before. verifier_precision/state_loop_first_last_equal: the loop converges on the second trip. Checkpoint with first_idx == last_idx doesn't happen. Expect mark_precise from the exit test of the first trip. Signed-off-by: Alexei Starovoitov --- .../bpf/prog_tests/bpf_verif_scale.c | 4 +-- .../selftests/bpf/progs/verifier_cfg.c | 4 +-- .../selftests/bpf/progs/verifier_movsx.c | 2 +- .../selftests/bpf/progs/verifier_precision.c | 29 ++++++++----------- .../bpf/progs/verifier_search_pruning.c | 3 +- tools/testing/selftests/bpf/verifier/calls.c | 5 ++-- 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c index 902a70d5afeb..2dc37090d7a4 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c @@ -154,9 +154,9 @@ void test_verif_scale_loop2() scale_test("loop2.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); } -void test_verif_scale_loop3_fail() +void test_verif_scale_loop3() { - scale_test("loop3.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */); + scale_test("loop3.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false); } void test_verif_scale_loop4() diff --git a/tools/testing/selftests/bpf/progs/verifier_cfg.c b/tools/testing/selftests/bpf/progs/verifier_cfg.c index 3c3bb03e8217..700eadf5d430 100644 --- a/tools/testing/selftests/bpf/progs/verifier_cfg.c +++ b/tools/testing/selftests/bpf/progs/verifier_cfg.c @@ -98,8 +98,8 @@ l0_%=: r1 = r0; \ SEC("socket") __description("conditional loop") -__failure __msg("infinite loop detected") -__msg_unpriv("back-edge") +__success +__failure_unpriv __msg_unpriv("back-edge") __naked void conditional_loop(void) { asm volatile (" \ diff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c index 195b27a51224..280ccee33663 100644 --- a/tools/testing/selftests/bpf/progs/verifier_movsx.c +++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c @@ -226,7 +226,7 @@ l0_%=: \ SEC("socket") __description("MOV32SX, S8, var_off u32_max") -__failure __msg("infinite loop detected") +__success __failure_unpriv __msg_unpriv("back-edge from insn 2 to 0") __naked void mov64sx_s32_varoff_1(void) { diff --git a/tools/testing/selftests/bpf/progs/verifier_precision.c b/tools/testing/selftests/bpf/progs/verifier_precision.c index f4459561bf39..88358586e796 100644 --- a/tools/testing/selftests/bpf/progs/verifier_precision.c +++ b/tools/testing/selftests/bpf/progs/verifier_precision.c @@ -152,22 +152,21 @@ __naked int bpf_store_release(void) SEC("?raw_tp") __success __log_level(2) /* - * Without the bug fix there will be no history between "last_idx 3 first_idx 3" - * and "parent state regs=" lines. "R0=6" parts are here to help anchor - * expected log messages to the one specific mark_chain_precision operation. - * - * This is quite fragile: if verifier checkpointing heuristic changes, this - * might need adjusting. + * The state is widened when it comes back to the loop head, so the exit test + * is decided only on the first trip around the loop. "R0=2" parts are here to + * help anchor expected log messages to that mark_chain_precision operation. */ -__msg("2: (07) r0 += 1 ; R0=6") +__msg("2: (07) r0 += 1 ; R0=2") __msg("3: (35) if r0 >= 0xa goto pc+1") -__msg("mark_precise: frame0: last_idx 3 first_idx 3 subseq_idx -1") +__msg("mark_precise: frame0: last_idx 3 first_idx 1 subseq_idx -1") __msg("mark_precise: frame0: regs=r0 stack= before 2: (07) r0 += 1") __msg("mark_precise: frame0: regs=r0 stack= before 1: (07) r0 += 1") -__msg("mark_precise: frame0: regs=r0 stack= before 4: (05) goto pc-4") -__msg("mark_precise: frame0: regs=r0 stack= before 3: (35) if r0 >= 0xa goto pc+1") -__msg("mark_precise: frame0: parent state regs= stack=: R0=P4") -__msg("3: R0=6") +__msg("mark_precise: frame0: parent state regs=r0 stack=: R0=P0") +__msg("mark_precise: frame0: last_idx 0 first_idx 0 subseq_idx 1") +__msg("mark_precise: frame0: regs=r0 stack= before 0: (b7) r0 = 0") +__msg("3: R0=2") +__msg("loop head 1 widened, pass 1") +__msg("1: safe") __naked int state_loop_first_last_equal(void) { asm volatile ( @@ -175,11 +174,7 @@ __naked int state_loop_first_last_equal(void) "l0_%=:" "r0 += 1;" "r0 += 1;" - /* every few iterations we'll have a checkpoint here with - * first_idx == last_idx, potentially confusing precision - * backtracking logic - */ - "if r0 >= 10 goto l1_%=;" /* checkpoint + mark_precise */ + "if r0 >= 10 goto l1_%=;" /* mark_precise */ "goto l0_%=;" "l1_%=:" "exit;" diff --git a/tools/testing/selftests/bpf/progs/verifier_search_pruning.c b/tools/testing/selftests/bpf/progs/verifier_search_pruning.c index f40e57251e94..7098b44faafc 100644 --- a/tools/testing/selftests/bpf/progs/verifier_search_pruning.c +++ b/tools/testing/selftests/bpf/progs/verifier_search_pruning.c @@ -341,8 +341,7 @@ l0_%=: r1 = 42; \ * test would take a very long time to verify. */ SEC("kprobe") -__failure __log_level(4) -__msg("BPF program is too large.") +__success __naked void short_loop1(void) { asm volatile ( diff --git a/tools/testing/selftests/bpf/verifier/calls.c b/tools/testing/selftests/bpf/verifier/calls.c index 8b94b87135bc..c7c501bfc660 100644 --- a/tools/testing/selftests/bpf/verifier/calls.c +++ b/tools/testing/selftests/bpf/verifier/calls.c @@ -559,8 +559,9 @@ BPF_EXIT_INSN(), }, .prog_type = BPF_PROG_TYPE_SCHED_CLS, - .errstr = "infinite loop detected", - .result = REJECT, + /* may_goto ends the loop after 250ms, do not run it */ + .result = ACCEPT, + .runs = -1, }, { "calls: using r0 returned by callee", -- 2.55.0