From: Alexei Starovoitov A valid program with recursion can be rejected with "the call stack of 33 frames is too deep". No unsafe program is accepted, because the path-sensitive run accepts nothing. A pass can check a recursive function on its own, with no frame for each call. The run has each call of a static function in frames. It can run out of frames and get -E2BIG where no pass does. If the last pass had another error at that call, for example a callx with an unknown target, the run takes -E2BIG for the failing path. The budget of the next passes is cut. If the program needs more, it is rejected. Drop such a path. If each pass is out of frames too, the program is still rejected. Now its log has only the last basic block, not the full path. Fixes: a46de5d64e18 ("bpf: Reproduce an error on one path, with no joins") Signed-off-by: Alexei Starovoitov --- include/linux/bpf_verifier.h | 5 ++++- kernel/bpf/verifier.c | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 942629cc49..05a52913ae 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -586,7 +586,10 @@ struct bpf_verifier_state { struct bpf_reference_state *refs; u32 insn_idx; bool speculative; - /* an xreg has no value: unreachable. Only a path-sensitive run drops such a state. */ + /* + * An xreg has no value: unreachable. Only a path-sensitive run drops such a state. + * The run also sets it when it is out of frames. + */ bool infeasible; /* an error only in a leftover, see check_held_in_leftover() */ bool holds_too_much; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 907691a67a..fe6209c166 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -11240,6 +11240,8 @@ static int setup_func_entry(struct bpf_verifier_env *env, int subprog, int calls if (state->curframe + 1 >= MAX_CALL_FRAMES) { verbose(env, "the call stack of %d frames is too deep\n", state->curframe + 2); + /* drop the path: a pass possibly does not have these calls in frames */ + env->cur_state->infeasible |= env->path_sensitive; return -E2BIG; } /* in the frames of the callers it has no end */ -- 2.55.0