Skip to content

Commit d59232a

Browse files
davemarchevskyAlexei Starovoitov
authored andcommitted
bpf: Rename ARG_PTR_TO_KPTR -> ARG_KPTR_XCHG_DEST
ARG_PTR_TO_KPTR is currently only used by the bpf_kptr_xchg helper. Although it limits reg types for that helper's first arg to PTR_TO_MAP_VALUE, any arbitrary mapval won't do: further custom verification logic ensures that the mapval reg being xchgd-into is pointing to a kptr field. If this is not the case, it's not safe to xchg into that reg's pointee. Let's rename the bpf_arg_type to more accurately describe the fairly specific expectations that this arg type encodes. This is a nonfunctional change. Acked-by: Martin KaFai Lau <[email protected]> Signed-off-by: Dave Marchevsky <[email protected]> Signed-off-by: Amery Hung <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 7a851ec commit d59232a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

include/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ enum bpf_arg_type {
744744
ARG_PTR_TO_STACK, /* pointer to stack */
745745
ARG_PTR_TO_CONST_STR, /* pointer to a null terminated read-only string */
746746
ARG_PTR_TO_TIMER, /* pointer to bpf_timer */
747-
ARG_PTR_TO_KPTR, /* pointer to referenced kptr */
747+
ARG_KPTR_XCHG_DEST, /* pointer to destination that kptrs are bpf_kptr_xchg'd into */
748748
ARG_PTR_TO_DYNPTR, /* pointer to bpf_dynptr. See bpf_type_flag for dynptr type */
749749
__BPF_ARG_TYPE_MAX,
750750

kernel/bpf/helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ static const struct bpf_func_proto bpf_kptr_xchg_proto = {
16361636
.gpl_only = false,
16371637
.ret_type = RET_PTR_TO_BTF_ID_OR_NULL,
16381638
.ret_btf_id = BPF_PTR_POISON,
1639-
.arg1_type = ARG_PTR_TO_KPTR,
1639+
.arg1_type = ARG_KPTR_XCHG_DEST,
16401640
.arg2_type = ARG_PTR_TO_BTF_ID_OR_NULL | OBJ_RELEASE,
16411641
.arg2_btf_id = BPF_PTR_POISON,
16421642
};

kernel/bpf/verifier.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8412,7 +8412,7 @@ static const struct bpf_reg_types func_ptr_types = { .types = { PTR_TO_FUNC } };
84128412
static const struct bpf_reg_types stack_ptr_types = { .types = { PTR_TO_STACK } };
84138413
static const struct bpf_reg_types const_str_ptr_types = { .types = { PTR_TO_MAP_VALUE } };
84148414
static const struct bpf_reg_types timer_types = { .types = { PTR_TO_MAP_VALUE } };
8415-
static const struct bpf_reg_types kptr_types = { .types = { PTR_TO_MAP_VALUE } };
8415+
static const struct bpf_reg_types kptr_xchg_dest_types = { .types = { PTR_TO_MAP_VALUE } };
84168416
static const struct bpf_reg_types dynptr_types = {
84178417
.types = {
84188418
PTR_TO_STACK,
@@ -8444,7 +8444,7 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
84448444
[ARG_PTR_TO_STACK] = &stack_ptr_types,
84458445
[ARG_PTR_TO_CONST_STR] = &const_str_ptr_types,
84468446
[ARG_PTR_TO_TIMER] = &timer_types,
8447-
[ARG_PTR_TO_KPTR] = &kptr_types,
8447+
[ARG_KPTR_XCHG_DEST] = &kptr_xchg_dest_types,
84488448
[ARG_PTR_TO_DYNPTR] = &dynptr_types,
84498449
};
84508450

@@ -9044,7 +9044,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
90449044
return err;
90459045
break;
90469046
}
9047-
case ARG_PTR_TO_KPTR:
9047+
case ARG_KPTR_XCHG_DEST:
90489048
err = process_kptr_func(env, regno, meta);
90499049
if (err)
90509050
return err;

0 commit comments

Comments
 (0)