Skip to content

Commit 270386d

Browse files
mykyta5Kernel Patches Daemon
authored andcommitted
bpf: verifier: centralize const dynptr check in unmark_stack_slots_dynptr()
Move the const dynptr check into unmark_stack_slots_dynptr() so callers don’t have to duplicate it. This puts the validation next to the code that manipulates dynptr stack slots and allows upcoming changes to reuse it directly. Signed-off-by: Mykyta Yatsenko <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Eduard Zingerman <[email protected]>
1 parent 486ef88 commit 270386d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

kernel/bpf/verifier.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,15 @@ static int unmark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_re
828828
struct bpf_func_state *state = func(env, reg);
829829
int spi, ref_obj_id, i;
830830

831+
/*
832+
* This can only be set for PTR_TO_STACK, as CONST_PTR_TO_DYNPTR cannot
833+
* be released by any dynptr helper. Hence, unmark_stack_slots_dynptr
834+
* is safe to do directly.
835+
*/
836+
if (reg->type == CONST_PTR_TO_DYNPTR) {
837+
verifier_bug(env, "CONST_PTR_TO_DYNPTR cannot be released");
838+
return -EFAULT;
839+
}
831840
spi = dynptr_get_spi(env, reg);
832841
if (spi < 0)
833842
return spi;
@@ -11514,15 +11523,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
1151411523

1151511524
if (meta.release_regno) {
1151611525
err = -EINVAL;
11517-
/* This can only be set for PTR_TO_STACK, as CONST_PTR_TO_DYNPTR cannot
11518-
* be released by any dynptr helper. Hence, unmark_stack_slots_dynptr
11519-
* is safe to do directly.
11520-
*/
1152111526
if (arg_type_is_dynptr(fn->arg_type[meta.release_regno - BPF_REG_1])) {
11522-
if (regs[meta.release_regno].type == CONST_PTR_TO_DYNPTR) {
11523-
verifier_bug(env, "CONST_PTR_TO_DYNPTR cannot be released");
11524-
return -EFAULT;
11525-
}
1152611527
err = unmark_stack_slots_dynptr(env, &regs[meta.release_regno]);
1152711528
} else if (func_id == BPF_FUNC_kptr_xchg && meta.ref_obj_id) {
1152811529
u32 ref_obj_id = meta.ref_obj_id;

0 commit comments

Comments
 (0)