bpf: Fix insn_aux_data leak on verifier err_free_env path
PATCH 1/1 bpf: Fix insn_aux_data leak on verifier err_free_env path
When bpf_check() allocates env->insn_aux_data successfully but later fails to allocate env->succ, it jumps directly to err_free_env.
The existing vfree(env->insn_aux_data) sits before the err_free_env label, so that direct jump bypasses it and leaks insn_aux_data.
Move vfree(env->insn_aux_data) into err_free_env so all early and late exit paths release it consistently.
--- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/verifier.c +1 -1
@@ -19994,13 +19994,13 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,if (!is_priv)mutex_unlock (&bpf_verifier_lock);bpf_clear_insn_aux_data (env,0 , env->prog->len); -vfree (env->insn_aux_data); err_free_env:bpf_stack_liveness_free (env);kvfree (env->cfg.insn_postorder);kvfree (env->scc_info);kvfree (env->succ);kvfree (env->gotox_tmp_buf); +vfree (env->insn_aux_data);kvfree (env);return ret; }
Signature · 1 line
2.43.0
Quoted 21 lines · KaFai Wan
When
bpf_check()allocatesenv->insn_aux_datasuccessfully but later fails to allocateenv->succ, it jumps directly toerr_free_env.The existing
vfree(env->insn_aux_data)sits before theerr_free_envlabel, so that direct jump bypasses it and leaksinsn_aux_data.Move
vfree(env->insn_aux_data)intoerr_free_envso all early and late exit paths release it consistently.Fixes 2f69c5685427 ("bpf: make bpf_insn_successors to return a pointer")Signed-off-by KaFai Wan <[email protected]>--- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/verifier.c +0
-0@@ -19994,13 +19994,13 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,if (!is_priv)
kernel/bpf/verifier.c int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, · line 20003
Quoted 10 lines
kernel/bpf/verifier.c +1
-1mutex_unlock (&bpf_verifier_lock);bpf_clear_insn_aux_data (env,0 , env->prog->len); -vfree (env->insn_aux_data); err_free_env:bpf_stack_liveness_free (env);kvfree (env->cfg.insn_postorder);kvfree (env->scc_info);kvfree (env->succ);kvfree (env->gotox_tmp_buf); +vfree (env->insn_aux_data);
Thanks!
Quoted 6 lines
kernel/bpf/verifier.c +0
-0kvfree (env);return ret; }Signature · 1 line
2.43.0
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 10 lines · On Wed, 24 Jun 2026 20:35:35 +0800 you wrote:
When
bpf_check()allocatesenv->insn_aux_datasuccessfully but later fails to allocateenv->succ, it jumps directly toerr_free_env.The existing
vfree(env->insn_aux_data)sits before theerr_free_envlabel, so that direct jump bypasses it and leaksinsn_aux_data.Move
vfree(env->insn_aux_data)intoerr_free_envso all early and late exit paths release it consistently.[...]
Here is the summary with links:
- [bpf,1/1] bpf: Fix insn_aux_data leak on verifier err_free_env path
https://git.kernel.org/bpf/bpf/c/26490a375cb9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html