Skip to content

Commit d400a6c

Browse files
committed
bpf: Mark PTR_TO_FUNC register initially with zero offset
Similar as with other pointer types where we use ldimm64, clear the register content to zero first, and then populate the PTR_TO_FUNC type and subprogno number. Currently this is not done, and leads to reuse of stale register tracking data. Given for special ldimm64 cases we always clear the register offset, make it common for all cases, so it won't be forgotten in future. Fixes: 69c087b ("bpf: Add bpf_for_each_map_elem() helper") Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: John Fastabend <[email protected]> Acked-by: Alexei Starovoitov <[email protected]>
1 parent be80a1d commit d400a6c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kernel/bpf/verifier.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9508,9 +9508,13 @@ static int check_ld_imm(struct bpf_verifier_env *env, struct bpf_insn *insn)
95089508
return 0;
95099509
}
95109510

9511-
if (insn->src_reg == BPF_PSEUDO_BTF_ID) {
9512-
mark_reg_known_zero(env, regs, insn->dst_reg);
9511+
/* All special src_reg cases are listed below. From this point onwards
9512+
* we either succeed and assign a corresponding dst_reg->type after
9513+
* zeroing the offset, or fail and reject the program.
9514+
*/
9515+
mark_reg_known_zero(env, regs, insn->dst_reg);
95139516

9517+
if (insn->src_reg == BPF_PSEUDO_BTF_ID) {
95149518
dst_reg->type = aux->btf_var.reg_type;
95159519
switch (base_type(dst_reg->type)) {
95169520
case PTR_TO_MEM:
@@ -9548,7 +9552,6 @@ static int check_ld_imm(struct bpf_verifier_env *env, struct bpf_insn *insn)
95489552
}
95499553

95509554
map = env->used_maps[aux->map_index];
9551-
mark_reg_known_zero(env, regs, insn->dst_reg);
95529555
dst_reg->map_ptr = map;
95539556

95549557
if (insn->src_reg == BPF_PSEUDO_MAP_VALUE ||

0 commit comments

Comments
 (0)