I have clarified this issue in the [PATCH bpf-next v10 3/8] patch, with the link provided below:
https://lore.kernel.org/bpf/[email protected]/ 在 2026/5/12 14:41, [email protected] 写道: >> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c >> index 1e8754877dd1..51b6ea4bb8cb 100644 >> --- a/kernel/bpf/helpers.c >> +++ b/kernel/bpf/helpers.c >> @@ -2593,6 +2593,15 @@ __bpf_kfunc struct bpf_list_node >> *bpf_list_pop_back(struct bpf_list_head *head) >> return __bpf_list_del(head, h->prev); >> } >> >> +__bpf_kfunc struct bpf_list_node *bpf_list_del(struct bpf_list_head *head, >> + struct bpf_list_node *node) >> +{ >> + struct bpf_list_node_kern *kn = (void *)node; >> + >> + /* verifier guarantees node is a list node rather than list head */ >> + return __bpf_list_del(head, &kn->list_head); >> +} >> + > > Looking at bpf_list_pop_front() and bpf_list_pop_back() in the same > file, both functions read from the list_head (h->next or h->prev) > before passing it to __bpf_list_del(). If the list is uninitialized, > they end up passing potentially invalid pointer values to __bpf_list_del(), > which then has to handle this by initializing the list and returning NULL. > > While __bpf_list_del() handles this correctly, would it be clearer to > move the initialization check into the top-level kfuncs (like > bpf_list_pop_front/back) so that __bpf_list_del() always receives a > valid list_head pointer rather than potentially garbage values that > get ignored later? > > Reference: > https://lore.kernel.org/bpf/af50d188f6bc2de81fe3c321b26a645a9425ba9f2644cb6f8525d5bb63738...@mail.kernel.org/ > >> @@ -4725,6 +4734,7 @@ BTF_ID_FLAGS(func, bpf_list_push_back, >> KF_IMPLICIT_ARGS) >> BTF_ID_FLAGS(func, bpf_list_push_back_impl) >> BTF_ID_FLAGS(func, bpf_list_pop_front, KF_ACQUIRE | KF_RET_NULL) >> BTF_ID_FLAGS(func, bpf_list_pop_back, KF_ACQUIRE | KF_RET_NULL) >> +BTF_ID_FLAGS(func, bpf_list_del, KF_ACQUIRE | KF_RET_NULL) >> BTF_ID_FLAGS(func, bpf_list_front, KF_RET_NULL) >> BTF_ID_FLAGS(func, bpf_list_back, KF_RET_NULL) >> BTF_ID_FLAGS(func, bpf_task_acquire, KF_ACQUIRE | KF_RCU | KF_RET_NULL) > > [ ... ] > >> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c >> index 11054ad89c14..a6bcbe68cd72 100644 >> --- a/kernel/bpf/verifier.c >> +++ b/kernel/bpf/verifier.c >> @@ -10744,6 +10744,7 @@ enum special_kfunc_type { >> KF_bpf_list_push_back, >> KF_bpf_list_pop_front, >> KF_bpf_list_pop_back, >> + KF_bpf_list_del, >> KF_bpf_list_front, >> KF_bpf_list_back, >> KF_bpf_cast_to_kern_ctx, > > [ ... ] > >> @@ -11456,7 +11459,8 @@ static bool check_kfunc_is_graph_node_api(struct >> bpf_verifier_env *env, >> >> switch (node_field_type) { >> case BPF_LIST_NODE: >> - ret = is_bpf_list_push_kfunc(kfunc_btf_id); >> + ret = is_bpf_list_push_kfunc(kfunc_btf_id) || >> + kfunc_btf_id == special_kfunc_list[KF_bpf_list_del]; >> break; >> case BPF_RB_NODE: >> ret = (is_bpf_rbtree_add_kfunc(kfunc_btf_id) || > > Can bpf_list_del actually be called from BPF programs? Looking at the > verifier's handling of KF_ARG_PTR_TO_LIST_NODE arguments in > check_kfunc_args(): > > case KF_ARG_PTR_TO_LIST_NODE: > ... > if (!reg->ref_obj_id) { > verbose(env, "allocated object must be referenced\n"); > return -EINVAL; > } > > This code path unconditionally requires an owning reference (ref_obj_id > must be non-zero). However, once a node is added to the list via > bpf_list_push_front/back, the owning reference is converted to a > non-owning reference (ref_obj_id becomes 0). This means bpf_list_del > cannot be called on nodes that are actually in the list. > > The sister kfunc bpf_rbtree_remove handles this by having a special > branch in check_kfunc_args() that accepts non-owning references for > that specific kfunc. Does bpf_list_del need similar handling to allow > removing nodes that are actually in the list? > > Reference: > https://lore.kernel.org/bpf/294242698d576e4fedf243ab055c6f9a984e55033933a9bd09808f62a7018...@mail.kernel.org/ > > > --- > AI reviewed your patch. Please fix the bug or email reply why it's not a bug. > See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md > > CI run summary: https://github.com/kernel-patches/bpf/actions/runs/25716874656 -- Thanks Kaitao Cheng

