Skip to content

Commit fb4e3b3

Browse files
eddyz87borkmann
authored andcommitted
bpf: Fix for use-after-free bug in inline_bpf_loop
As reported by Dan Carpenter, the following statements in inline_bpf_loop() might cause a use-after-free bug: struct bpf_prog *new_prog; // ... new_prog = bpf_patch_insn_data(env, position, insn_buf, *cnt); // ... env->prog->insnsi[call_insn_offset].imm = callback_offset; The bpf_patch_insn_data() might free the memory used by env->prog. Fixes: 1ade237 ("bpf: Inline calls to bpf_loop when callback is known") Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Eduard Zingerman <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 395e942 commit fb4e3b3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14417,7 +14417,7 @@ static struct bpf_prog *inline_bpf_loop(struct bpf_verifier_env *env,
1441714417
/* Note: insn_buf[12] is an offset of BPF_CALL_REL instruction */
1441814418
call_insn_offset = position + 12;
1441914419
callback_offset = callback_start - call_insn_offset - 1;
14420-
env->prog->insnsi[call_insn_offset].imm = callback_offset;
14420+
new_prog->insnsi[call_insn_offset].imm = callback_offset;
1442114421

1442214422
return new_prog;
1442314423
}

0 commit comments

Comments
 (0)