All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kaitao Cheng" <kaitao.cheng@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v11 6/8] bpf: Add bpf_list_add to insert node after a given list node
Date: Thu, 21 May 2026 12:49:27 +0000	[thread overview]
Message-ID: <20260521124928.14BAE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260521032306.97118-7-kaitao.cheng@linux.dev>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] The `bpf_list_add` kfunc frees the inserted node on runtime failure, but the BPF verifier unconditionally converts it to a non-owning reference, leading to a Use-After-Free (UAF) vulnerability.
- [High] The `bpf_list_add` kfunc is registered with `KF_IMPLICIT_ARGS` but lacks the required `_impl` function and BTF ID, causing the verifier to reject all programs attempting to call it.
--

commit 41c84b8182697296804a152b66297f50e3a604cb
Author: Kaitao Cheng <chengkaitao@kylinos.cn>

    bpf: Add bpf_list_add to insert node after a given list node

This commit adds a new kfunc bpf_list_add() that inserts 'new' after 'prev'
in a BPF linked list. The new node must be an owning reference, which the
kfunc consumes and converts to a non-owning reference upon insertion.

> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index 1c69476c8a094..89579165ef4dc 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
[ ... ]
> @@ -2577,6 +2577,16 @@ __bpf_kfunc int bpf_list_push_back_impl(struct bpf_list_head *head,
>  	return bpf_list_push_back(head, node, meta__ign, off);
>  }
>  
> +__bpf_kfunc int bpf_list_add(struct bpf_list_head *head, struct bpf_list_node *new,
> +			     struct bpf_list_node *prev__nonown_allowed,
> +			     struct btf_struct_meta *meta, u64 off)
> +{
> +	struct bpf_list_node_kern *n = (void *)new, *p = (void *)prev__nonown_allowed;
> +	struct list_head *prev_ptr = &p->list_head;
> +
> +	return __bpf_list_add(n, head, &prev_ptr, meta ? meta->record : NULL, off);
> +}

[Severity: Critical]
Is it possible for this to result in a use-after-free if __bpf_list_add() fails?

Looking at __bpf_list_add(), it introduces a runtime check that fails if the
prev node doesn't belong to the target list. When it fails, the function
calls __bpf_obj_drop_impl() to free the new node and returns -EINVAL.

However, the BPF verifier treats bpf_list_add() as a list push operation.
During check_kfunc_call(), it unconditionally consumes the owning reference to
the new node and converts it to a non-owning reference, assuming static
success.

If the runtime check fails, the BPF program would be granted a valid
non-owning reference to the freed new node inside the spinlock critical
section, potentially leading to memory corruption.

[ ... ]
> @@ -4756,6 +4766,7 @@ BTF_ID_FLAGS(func, bpf_list_push_front, KF_IMPLICIT_ARGS)
>  BTF_ID_FLAGS(func, bpf_list_push_front_impl)
>  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_add, KF_IMPLICIT_ARGS)

[Severity: High]
Does this kfunc lack a required _impl function?

When a kfunc is marked with KF_IMPLICIT_ARGS, the verifier's
find_kfunc_impl_proto() explicitly requires a corresponding _impl function
to resolve the full prototype.

Since there is no bpf_list_add_impl() defined in kernel/bpf/helpers.c and
registered with BTF, fetch_kfunc_meta() will return -EINVAL. Will this cause
the verifier to unconditionally reject any BPF program attempting to use
this kfunc?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260521032306.97118-1-kaitao.cheng@linux.dev?part=6

  parent reply	other threads:[~2026-05-21 12:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21  3:22 [PATCH bpf-next v11 0/8] bpf: Extend the bpf_list family of APIs Kaitao Cheng
2026-05-21  3:22 ` [PATCH bpf-next v11 1/8] bpf: refactor __bpf_list_del to take list node pointer Kaitao Cheng
2026-05-21  3:23 ` [PATCH bpf-next v11 2/8] bpf: clear list node owner and unlink before drop Kaitao Cheng
2026-05-21  4:08   ` bot+bpf-ci
2026-05-21  4:30   ` sashiko-bot
2026-05-21  6:11     ` Kaitao Cheng
2026-05-21  3:23 ` [PATCH bpf-next v11 3/8] bpf: allow non-owning list-node args via __nonown_allowed Kaitao Cheng
2026-05-21  4:08   ` bot+bpf-ci
2026-05-21  6:29     ` Kaitao Cheng
2026-05-21  3:23 ` [PATCH bpf-next v11 4/8] bpf: Introduce the bpf_list_del kfunc Kaitao Cheng
2026-05-21  4:08   ` bot+bpf-ci
2026-05-21  6:59     ` Kaitao Cheng
2026-05-21  3:23 ` [PATCH bpf-next v11 5/8] bpf: refactor __bpf_list_add to take insertion point via **prev_ptr Kaitao Cheng
2026-05-21  3:23 ` [PATCH bpf-next v11 6/8] bpf: Add bpf_list_add to insert node after a given list node Kaitao Cheng
2026-05-21  4:08   ` bot+bpf-ci
2026-05-21  7:35     ` Kaitao Cheng
2026-05-21 12:49   ` sashiko-bot [this message]
2026-05-21  3:23 ` [PATCH bpf-next v11 7/8] bpf: add bpf_list_is_first/last/empty kfuncs Kaitao Cheng
2026-05-21 13:29   ` sashiko-bot
2026-05-21  3:23 ` [PATCH bpf-next v11 8/8] selftests/bpf: Add test cases for bpf_list_del/add/is_first/is_last/empty Kaitao Cheng
2026-05-21  4:08   ` bot+bpf-ci
2026-05-21 10:00 ` [PATCH bpf-next v11 0/8] bpf: Extend the bpf_list family of APIs patchwork-bot+netdevbpf

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=20260521124928.14BAE1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kaitao.cheng@linux.dev \
    --cc=sashiko-reviews@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.