From: sashiko-bot@kernel.org
To: "Pu Lehui" <pulehui@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v6 1/4] bpf: Fix potential UAF in bpf_netns_link_update_prog
Date: Wed, 22 Jul 2026 07:36:24 +0000 [thread overview]
Message-ID: <20260722073624.CEAAC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260722072326.1545677-2-pulehui@huaweicloud.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Preexisting Use-After-Free in generic bpf_link information retrieval and mprog attachment due to lockless access to link->prog.
--
--- Patch [1]: [PATCH bpf v6 1/4] bpf: Fix potential UAF in bpf_netns_link_update_prog ---
commit d5c566078955c1f4dfc1d9f1e23e9f6213c3dcfb
Author: Pu Lehui <pulehui@huawei.com>
bpf: Fix potential UAF in bpf_netns_link_update_prog
This commit fixes a potential use-after-free issue in
bpf_netns_link_update_prog() by moving the old_prog and prog->type checks
inside the netns_bpf_mutex critical section.
> diff --git a/kernel/bpf/net_namespace.c b/kernel/bpf/net_namespace.c
> index 25f30f9edaefd..9fc62db1441c6 100644
> --- a/kernel/bpf/net_namespace.c
> +++ b/kernel/bpf/net_namespace.c
> @@ -171,13 +171,17 @@ static int bpf_netns_link_update_prog(struct bpf_link *link,
> struct net *net;
> int idx, ret;
>
> - if (old_prog && old_prog != link->prog)
> - return -EPERM;
> - if (new_prog->type != link->prog->type)
> - return -EINVAL;
> -
> mutex_lock(&netns_bpf_mutex);
>
> + if (old_prog && old_prog != link->prog) {
> + ret = -EPERM;
> + goto out_unlock;
> + }
> + if (new_prog->type != link->prog->type) {
> + ret = -EINVAL;
> + goto out_unlock;
> + }
> +
[Severity: High]
This isn't a bug introduced by this patch, but while this change fixes the
concurrent update race in bpf_netns_link_update_prog(), could the subsequent
xchg() of link->prog cause a use-after-free regression in other functions
that read it locklessly?
If a user-space application concurrently calls bpf_obj_get_info_by_fd() or
reads fdinfo, the retrieval functions read link->prog locklessly without
holding rcu_read_lock(). If the reader thread is preempted immediately after
reading the pointer, and a concurrent link update replaces and frees the old
program, will the reader dereference freed memory?
This can happen in bpf_link_get_info_by_fd():
if (link->prog)
info.prog_id = link->prog->aux->id;
It also appears in bpf_link_show_fdinfo():
const struct bpf_prog *prog = link->prog;
...
bin2hex(prog_tag, prog->tag, sizeof(prog->tag));
And in bpf_mprog_link():
if (type && link->prog->type != type) {
Do these lockless accesses need rcu_read_lock() protection to safely read
the program fields when updates can happen concurrently?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260722072326.1545677-1-pulehui@huaweicloud.com?part=1
next prev parent reply other threads:[~2026-07-22 7:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 7:23 [PATCH bpf v6 0/4] Fixes for bpf link update Pu Lehui
2026-07-22 7:23 ` [PATCH bpf v6 1/4] bpf: Fix potential UAF in bpf_netns_link_update_prog Pu Lehui
2026-07-22 7:36 ` sashiko-bot [this message]
2026-07-22 7:45 ` Pu Lehui
2026-07-22 7:23 ` [PATCH bpf v6 2/4] bpf: Fix UAF due to missing link type check in mprog Pu Lehui
2026-07-22 7:33 ` sashiko-bot
2026-07-22 7:45 ` Pu Lehui
2026-07-22 16:25 ` Emil Tsalapatis
2026-07-22 7:23 ` [PATCH bpf v6 3/4] bpf: Fix potential UAF when reading bpf link info Pu Lehui
2026-07-22 7:23 ` [PATCH bpf v6 4/4] bpf, cgroup: Fix storage null-ptr-deref after replacing prog Pu Lehui
2026-07-22 7:35 ` sashiko-bot
2026-07-22 7:48 ` Pu Lehui
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=20260722073624.CEAAC1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=pulehui@huaweicloud.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox