From: Arnd Bergmann The large 'bpf_verifier_state' structure causes the newly added bpf_guess_first_trips() function to have one of the largest stack frames in the kernel. With CONFIG_KASAN_STACK this exceeds the warning limit I have set on arm64: kernel/bpf/equation_join.c: In function 'bpf_guess_first_trips': kernel/bpf/equation_join.c:1502:1: error: the frame size of 1552 bytes is larger than 1536 bytes [-Werror=frame-larger-than=] There are already some dynamic allocations in this code path, so do the same here and use kzalloc_obj() as well here. Fixes: 97f92b0c1df6 ("bpf: Check the body of a counted loop once") Signed-off-by: Arnd Bergmann --- kernel/bpf/equation_join.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/equation_join.c b/kernel/bpf/equation_join.c index d7ad7fb52ed6..4123a8448237 100644 --- a/kernel/bpf/equation_join.c +++ b/kernel/bpf/equation_join.c @@ -1455,7 +1455,7 @@ int bpf_guess_first_trips(struct bpf_verifier_env *env, struct bpf_verifier_stat struct bpf_loop *loop) { struct loop_stack_entry *e = bpf_top_loop(st->frame[st->curframe]); - struct bpf_verifier_state next = {}; + struct bpf_verifier_state *next; struct bpf_loop_steps *steps; u64 trips = U64_MAX, xreg; struct scalar *s; @@ -1488,15 +1488,18 @@ int bpf_guess_first_trips(struct bpf_verifier_env *env, struct bpf_verifier_stat return 0; e->exit_threshold = e->trip_index.r64.base + trips; add_iv_threshold(env, loop, e->exit_threshold, 1, THRESHOLD_EXIT_JUMP, U32_MAX); + next = kzalloc_obj(*next); + if (!next) + return -ENOMEM; for (i = 0; i < min(trips, 2) && !err; i++) { - err = bpf_copy_verifier_state(env, &next, st); - if (err || !move_by_steps(env, &next, steps)) + err = bpf_copy_verifier_state(env, next, st); + if (err || !move_by_steps(env, next, steps)) break; - err = bpf_states_join(env, st, &next, loop, true); + err = bpf_states_join(env, st, next, loop, true); env->extra_values = true; bitmap_or(loop->nonlinear_xregs, loop->nonlinear_xregs, steps->nonlinear_xregs, MAX_BPF_XREG); } - bpf_free_verifier_state(env, &next, false); + bpf_free_verifier_state(env, next, true); return err ?: i > 0; } -- 2.53.0