Skip to contentSkip to conversation

bpf: Fix error path under memory pressure

PATCH In review Alexei Starovoitov 4 participants 4 messages Jan 22, 2020

Subsystems (4)
lore
Share & tools
lore

Alexei Starovoitov

author maintainer
#0 lore raw

PATCH 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.

Fixes 51c39bb1d5d1 ("bpf: Introduce function-by-function verification")
---
 kernel/bpf/verifier.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +7 -2
index ca17dccc17ba..6defbec9eb62 100644
@@ -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
#1 lore raw
Quoted 7 lines · Alexei Starovoitov

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 51c39bb1d5d1 ("bpf: Introduce function-by-function verification")

Forgot to add:

Reported-by [email protected]

Daniel, pls add while applying.

Acked-by
#2 lore raw
Quoted 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 pressure env->cur_state can be freed and zeroed inside do_check(). Hence the check is necessary.

Quoted 7 lines
Quoted 2 lines
Fixes 51c39bb1d5d1 ("bpf: Introduce function-by-function verification")

Forgot to add:

Reported-by [email protected]

Daniel, pls add while applying.

Thanks for the fix!

maintainer
#3 lore raw
In reply to Alexei Starovoitov
Quoted 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 pressure env->cur_state can be freed and zeroed inside do_check(). Hence the check is necessary.

Quoted 7 lines
Quoted 2 lines
Fixes 51c39bb1d5d1 ("bpf: Introduce function-by-function verification")

Forgot to add:

Reported-by [email protected]

Daniel, pls add while applying.

Done & applied, thanks!