Skip to content

Commit

Permalink
bpf: Fix error path under memory pressure
Browse files Browse the repository at this point in the history
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.

Fixes: 51c39bb ("bpf: Introduce function-by-function verification")
Reported-by: syzbot+b296579ba5015704d9fa@syzkaller.appspotmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200122024138.3385590-1-ast@kernel.org
  • Loading branch information
Alexei Starovoitov authored and Daniel Borkmann committed Jan 22, 2020
1 parent 05d57f1 commit f59bbfc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions kernel/bpf/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f59bbfc

Please sign in to comment.