Skip to content

Commit b183c01

Browse files
Martin KaFai LauAlexei Starovoitov
authored andcommitted
bpf: Check KF_bpf_rbtree_add_impl for the "case KF_ARG_PTR_TO_RB_NODE"
In a later patch, two new kfuncs will take the bpf_rb_node pointer arg. struct bpf_rb_node *bpf_rbtree_left(struct bpf_rb_root *root, struct bpf_rb_node *node); struct bpf_rb_node *bpf_rbtree_right(struct bpf_rb_root *root, struct bpf_rb_node *node); In the check_kfunc_call, there is a "case KF_ARG_PTR_TO_RB_NODE" to check if the reg->type should be an allocated pointer or should be a non_owning_ref. The later patch will need to ensure that the bpf_rb_node pointer passing to the new bpf_rbtree_{left,right} must be a non_owning_ref. This should be the same requirement as the existing bpf_rbtree_remove. This patch swaps the current "if else" statement. Instead of checking the bpf_rbtree_remove, it checks the bpf_rbtree_add. Then the new bpf_rbtree_{left,right} will fall into the "else" case to make the later patch simpler. bpf_rbtree_add should be the only one that needs an allocated pointer. This should be a no-op change considering there are only two kfunc(s) taking bpf_rb_node pointer arg, rbtree_add and rbtree_remove. Acked-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 62e23f1 commit b183c01

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

kernel/bpf/verifier.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13200,22 +13200,22 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
1320013200
return ret;
1320113201
break;
1320213202
case KF_ARG_PTR_TO_RB_NODE:
13203-
if (meta->func_id == special_kfunc_list[KF_bpf_rbtree_remove]) {
13204-
if (!type_is_non_owning_ref(reg->type) || reg->ref_obj_id) {
13205-
verbose(env, "rbtree_remove node input must be non-owning ref\n");
13203+
if (meta->func_id == special_kfunc_list[KF_bpf_rbtree_add_impl]) {
13204+
if (reg->type != (PTR_TO_BTF_ID | MEM_ALLOC)) {
13205+
verbose(env, "arg#%d expected pointer to allocated object\n", i);
1320613206
return -EINVAL;
1320713207
}
13208-
if (in_rbtree_lock_required_cb(env)) {
13209-
verbose(env, "rbtree_remove not allowed in rbtree cb\n");
13208+
if (!reg->ref_obj_id) {
13209+
verbose(env, "allocated object must be referenced\n");
1321013210
return -EINVAL;
1321113211
}
1321213212
} else {
13213-
if (reg->type != (PTR_TO_BTF_ID | MEM_ALLOC)) {
13214-
verbose(env, "arg#%d expected pointer to allocated object\n", i);
13213+
if (!type_is_non_owning_ref(reg->type) || reg->ref_obj_id) {
13214+
verbose(env, "rbtree_remove node input must be non-owning ref\n");
1321513215
return -EINVAL;
1321613216
}
13217-
if (!reg->ref_obj_id) {
13218-
verbose(env, "allocated object must be referenced\n");
13217+
if (in_rbtree_lock_required_cb(env)) {
13218+
verbose(env, "rbtree_remove not allowed in rbtree cb\n");
1321913219
return -EINVAL;
1322013220
}
1322113221
}

0 commit comments

Comments
 (0)