From: Kaitao Cheng <kaitao.cheng@linux.dev>
To: bot+bpf-ci@kernel.org
Cc: martin.lau@linux.dev, john.fastabend@gmail.com,
yonghong.song@linux.dev, song@kernel.org, eddyz87@gmail.com,
andrii@kernel.org, daniel@iogearbox.net, ast@kernel.org,
linux-kselftest@vger.kernel.org, chengkaitao@kylinos.cn,
shuah@kernel.org, jolsa@kernel.org, haoluo@google.com,
sdf@fomichev.me, kpsingh@kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, martin.lau@kernel.org,
clm@meta.com, ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v10 3/8] bpf: Introduce the bpf_list_del kfunc.
Date: Tue, 28 Apr 2026 22:32:56 +0800 [thread overview]
Message-ID: <0637c1ce-0e73-4505-8a0c-e77339f4aefb@linux.dev> (raw)
In-Reply-To: <294242698d576e4fedf243ab055c6f9a984e55033933a9bd09808f62a7018e9d@mail.kernel.org>
在 2026/4/28 02:43, bot+bpf-ci@kernel.org 写道:
>> 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?
I have already fixed this issue in [PATCH bpf-next v10 7/8].
> 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?
In previous discussions, people generally advised against keeping
warnings on this kind of path that can be triggered by BPF programs.
> 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?
I have already fixed this issue in [PATCH bpf-next v10 2/8].
>> @@ -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
--
Thanks
Kaitao Cheng
next prev parent reply other threads:[~2026-04-28 14:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 16:58 [PATCH bpf-next v10 0/8] bpf: Extend the bpf_list family of APIs Kaitao cheng
2026-04-27 16:58 ` [PATCH bpf-next v10 1/8] bpf: refactor __bpf_list_del to take list node pointer Kaitao cheng
2026-04-27 18:43 ` bot+bpf-ci
2026-04-28 13:52 ` Kaitao Cheng
2026-04-27 16:59 ` [PATCH bpf-next v10 2/8] bpf: clear list node owner and unlink before drop Kaitao cheng
2026-04-27 18:43 ` bot+bpf-ci
2026-04-28 14:08 ` Kaitao Cheng
2026-04-27 16:59 ` [PATCH bpf-next v10 3/8] bpf: Introduce the bpf_list_del kfunc Kaitao cheng
2026-04-27 18:43 ` bot+bpf-ci
2026-04-28 14:32 ` Kaitao Cheng [this message]
2026-04-27 16:59 ` [PATCH bpf-next v10 4/8] bpf: refactor __bpf_list_add to take insertion point via **prev_ptr Kaitao cheng
2026-04-27 16:59 ` [PATCH bpf-next v10 5/8] bpf: Add bpf_list_add to insert node after a given list node Kaitao cheng
2026-04-27 18:43 ` bot+bpf-ci
2026-04-28 14:18 ` Kaitao Cheng
2026-04-27 16:59 ` [PATCH bpf-next v10 6/8] bpf: add bpf_list_is_first/last/empty kfuncs Kaitao cheng
2026-04-27 16:59 ` [PATCH bpf-next v10 7/8] bpf: allow non-owning list-node args via __nonown_allowed Kaitao cheng
2026-04-27 16:59 ` [PATCH bpf-next v10 8/8] selftests/bpf: Add test cases for bpf_list_del/add/is_first/is_last/empty Kaitao cheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0637c1ce-0e73-4505-8a0c-e77339f4aefb@linux.dev \
--to=kaitao.cheng@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chengkaitao@kylinos.cn \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox