Skip to content

Commit 94ac755

Browse files
ameryhungAlexei Starovoitov
authored andcommitted
bpf: Assign reg->id when getting referenced kptr from ctx
Assign reg->id when getting referenced kptr from read program context to be consistent with R0 of KF_ACQUIRE kfunc. skb dynptr will track the referenced skb in qdisc programs using a new field reg->parent_id in a later patch. Acked-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Amery Hung <ameryhung@gmail.com> Link: https://lore.kernel.org/r/20260529014936.2811085-4-ameryhung@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent b5c0a07 commit 94ac755

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

kernel/bpf/verifier.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6208,8 +6208,6 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct b
62086208
} else {
62096209
mark_reg_known_zero(env, regs,
62106210
value_regno);
6211-
if (type_may_be_null(info.reg_type))
6212-
regs[value_regno].id = ++env->id_gen;
62136211
/* A load of ctx field could have different
62146212
* actual load size with the one encoded in the
62156213
* insn. When the dst is PTR, it is for sure not
@@ -6219,8 +6217,11 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct b
62196217
if (base_type(info.reg_type) == PTR_TO_BTF_ID) {
62206218
regs[value_regno].btf = info.btf;
62216219
regs[value_regno].btf_id = info.btf_id;
6220+
regs[value_regno].id = info.ref_obj_id;
62226221
regs[value_regno].ref_obj_id = info.ref_obj_id;
62236222
}
6223+
if (type_may_be_null(info.reg_type) && !regs[value_regno].id)
6224+
regs[value_regno].id = ++env->id_gen;
62246225
}
62256226
regs[value_regno].type = info.reg_type;
62266227
}

0 commit comments

Comments
 (0)