Re: [PATCH bpf-next v10 3/8] bpf: Introduce the bpf_list_del kfunc.

bot+bpf-ci
2026-04-27T18:43:45Z

[-- Attachment #1: Type: text/plain, Size: 3758 bytes --]

> 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);
> +}

Can this kfunc actually be called from any BPF program? 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->type != (PTR_TO_BTF_ID | MEM_ALLOC)) {
verbose(env, "%s expected pointer to allocated object\n", ...);
return -EINVAL;
}
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) via ref_convert_owning_non_owning() and the
original owning reference is released. Any subsequent access to that
in-list node (including via bpf_list_front/back) only provides
non-owning references with ref_obj_id == 0.

This means:
- Passing a non-owning ref to bpf_list_del() fails the verifier's
"!reg->ref_obj_id" check with "allocated object must be referenced"
- Passing an owning ref to a node not yet in the list passes the
verifier check, but __bpf_list_del() will return NULL because
node_kern->owner != head

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?

Looking at __bpf_list_del() in kernel/bpf/helpers.c:

node = container_of(n, struct bpf_list_node_kern, list_head);
if (unlikely(READ_ONCE(node->owner) != head))
return NULL;

Emil Tsalapatis and the Sashiko review bot raised concerns about
removing the WARN_ON_ONCE that was in v8 of this series. The original
WARN_ON_ONCE helped detect list corruption by triggering a kernel
warning when owner != head. The current unlikely() check silently
returns NULL instead.

Should this check trigger a warning for debugging list corruption issues?

Additionally, the Sashiko review noted a reuse bug: when
bpf_list_head_free() is called on a list that still contains elements,
those elements remain allocated but their owner field still points to
the now-freed head. Since the owner field is checked but never cleared,
could this lead to dangling pointer issues if nodes aren't freed
properly during list cleanup?

> @@ -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)

[ ... ]

---
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/25009536772