bpf: Fix error path under memory pressure
Subsystems (4)
Alexei Starovoitov
maintainerPATCH 1/1 bpf: Fix error path under memory pressure
Restore the 'if (env->cur_state)' check that was incorrectly removed during code move. Under memory pressure env->cur_state can be freed and zeroed inside do_check(). Hence the check is necessary.
--- kernel/bpf/verifier.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +7 -2
@@ -9594,8 +9594,13 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog) ret =do_check (env); out: -free_verifier_state (env->cur_state, true); - env->cur_state =NULL ; +/* check for NULL is necessary, since cur_state can be freed inside +* do_check() under memory pressure. +*/ +if (env->cur_state) { +free_verifier_state (env->cur_state, true); + env->cur_state =NULL ; + }while (!pop_stack (env,NULL ,NULL ));free_states (env);if (ret)
Signature · 1 line
2.23.0
Quoted 7 lines · Alexei Starovoitov
Restore the 'if (
env->cur_state)' check that was incorrectly removed during code move. Under memory pressureenv->cur_statecan be freed and zeroed insidedo_check(). Hence the check is necessary.Fixes 51c39bb1d5d1 ("bpf: Introduce function-by-function verification")Signed-off-by Alexei Starovoitov <[email protected]>
Forgot to add:
Daniel, pls add while applying.
Song Liu
Acked-byQuoted 10 lines · Alexei Starovoitov
Quoted 5 lines · Alexei Starovoitov
Restore the 'if (
env->cur_state)' check that was incorrectly removed during code move. Under memory pressureenv->cur_statecan be freed and zeroed insidedo_check(). Hence the check is necessary.
Quoted 7 lines
Quoted 2 lines
Fixes 51c39bb1d5d1 ("bpf: Introduce function-by-function verification")Signed-off-by Alexei Starovoitov <[email protected]>Forgot to add:
Reported-by [email protected]Daniel, pls add while applying.
Thanks for the fix!
Daniel Borkmann
maintainerQuoted 6 lines · Alexei Starovoitov
Quoted 5 lines · Alexei Starovoitov
Restore the 'if (
env->cur_state)' check that was incorrectly removed during code move. Under memory pressureenv->cur_statecan be freed and zeroed insidedo_check(). Hence the check is necessary.
Quoted 7 lines
Quoted 2 lines
Fixes 51c39bb1d5d1 ("bpf: Introduce function-by-function verification")Signed-off-by Alexei Starovoitov <[email protected]>Forgot to add:
Reported-by [email protected]Daniel, pls add while applying.
Done & applied, thanks!