From: Kaitao Cheng <kaitao.cheng@linux.dev>
To: bot+bpf-ci@kernel.org, emil@etsalapatis.com
Cc: shuah@kernel.org, john.fastabend@gmail.com,
yonghong.song@linux.dev, song@kernel.org, eddyz87@gmail.com,
andrii@kernel.org, ast@kernel.org, martin.lau@linux.dev,
daniel@iogearbox.net, 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, chengkaitao@kylinos.cn,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v10 1/8] bpf: refactor __bpf_list_del to take list node pointer
Date: Tue, 28 Apr 2026 21:52:33 +0800 [thread overview]
Message-ID: <e908cd1a-a0ee-49b1-8528-c455bbd4c432@linux.dev> (raw)
In-Reply-To: <af50d188f6bc2de81fe3c321b26a645a9425ba9f2644cb6f8525d5bb637385f9@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
>> --- a/kernel/bpf/helpers.c
>> +++ b/kernel/bpf/helpers.c
>
> [ ... ]
>
>> @@ -2575,12 +2577,16 @@ static struct bpf_list_node *__bpf_list_del(struct bpf_list_head *head,
>>
>> __bpf_kfunc struct bpf_list_node *bpf_list_pop_front(struct bpf_list_head *head)
>> {
>> - return __bpf_list_del(head, false);
>> + struct list_head *h = (void *)head;
>> +
>> + return __bpf_list_del(head, h->next);
>> }
>
> This addresses an unaddressed review comment from Emil Tsalapatis in v8.
> The code reads h->next before __bpf_list_del checks if the list is
> initialized. If the list is uninitialized (h->next is NULL), a NULL pointer
> is passed to __bpf_list_del.
>
> While the function will eventually initialize the list and return NULL without
> dereferencing the NULL pointer:
>
> kernel/bpf/helpers.c:__bpf_list_del() {
> if (unlikely(!h->next)) {
> INIT_LIST_HEAD(h);
> return NULL;
> }
> ...
> }
>
> this is counterintuitive - passing a potentially garbage value that is later
> ignored.
>
> Emil suggested moving the init check logic into the top-level kfuncs
> (bpf_list_pop_front/bpf_list_pop_back) to ensure the list_head passed to
> __bpf_list_del is always valid. You can also just init the list and return
> NULL in that case - we know it's empty.
>
> The same issue applies to bpf_list_pop_back() which reads h->prev before
> the initialization check.
>
> Original comment from Emil Tsalapatis (Thu, 19 Mar 2026 12:17:50 -0400):
> https://lore.kernel.org/bpf/DH6W7K2SLPYB.PCO7FQ6CR1YZ@etsalapatis.com/
>
> "The new code reads n _before_ we check if the list is initialized. So the n
> we are passing from the caller may well be NULL. However, __bpf_list_del()
> will in that case now a) call INIT_LIST_HEAD(() to properly set up prev/next,
> b) call list_empty() on the newly initialized list and exit without ever
> reading the NULL passed by the caller.
>
> This is kind of counterintuitive: We are passing essentially a garbage value
> to __bpf_list_del that we thankfully end upi ignoring. Can you move the init
> check logic into the top-level kfuncs to make sure the list_head we're passing
> to __bpf_list_del is always valid? You can also just init the list and return
> NULL in that case - we know it's empty."
>
> This issue remains unaddressed in v10.
>
>
> ---
> 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
The '__bpf_list_del' function is a static function, so its scope and
associated risk are both very limited. I think its purpose is code
reuse and avoiding duplication.
If we move 'unlikely(!h->next)' to the outer callers, I believe it
brings no benefit other than making the code more redundant. Also,
I think validating a function's parameters before execution is not
counterintuitive; on the contrary, for global functions it is almost
a hard requirement.
--
Thanks
Kaitao Cheng
next prev parent reply other threads:[~2026-04-28 13:53 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 [this message]
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
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=e908cd1a-a0ee-49b1-8528-c455bbd4c432@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=emil@etsalapatis.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