Skip to content

Commit b13448d

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: potential double-free of env->insn_aux_data
Function bpf_patch_insn_data() has the following structure: static struct bpf_prog *bpf_patch_insn_data(... env ...) { struct bpf_prog *new_prog; struct bpf_insn_aux_data *new_data = NULL; if (len > 1) { new_data = vrealloc(...); // <--------- (1) if (!new_data) return NULL; env->insn_aux_data = new_data; // <---- (2) } new_prog = bpf_patch_insn_single(env->prog, off, patch, len); if (IS_ERR(new_prog)) { ... vfree(new_data); // <----------------- (3) return NULL; } ... happy path ... } In case if bpf_patch_insn_single() returns an error the `new_data` allocated at (1) will be freed at (3). However, at (2) this pointer is stored in `env->insn_aux_data`. Which is freed unconditionally by verifier.c:bpf_check() on both happy and error paths. Thus, leading to double-free. Fix this by removing vfree() call at (3), ownership over `new_data` is already passed to `env->insn_aux_data` at this point. Fixes: 77620d1 ("bpf: use realloc in bpf_patch_insn_data") Reported-by: Chris Mason <[email protected]> Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 3ae4c52 commit b13448d

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20800,7 +20800,6 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 of
2080020800
verbose(env,
2080120801
"insn %d cannot be patched due to 16-bit range\n",
2080220802
env->insn_aux_data[off].orig_idx);
20803-
vfree(new_data);
2080420803
return NULL;
2080520804
}
2080620805
adjust_insn_aux_data(env, new_prog, off, len);

0 commit comments

Comments
 (0)