From: sashiko-bot@kernel.org
To: "Pu Lehui" <pulehui@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v3 1/3] bpf: Fix potential UAF when reading bpf link info
Date: Mon, 20 Jul 2026 03:50:31 +0000 [thread overview]
Message-ID: <20260720035032.6C8021F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260720033055.1215477-2-pulehui@huaweicloud.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] bpf_netns_link_update_prog checks link->prog locklessly, allowing a TOCTOU race that violates atomic replacement guarantees.
- [High] Concurrent BPF_LINK_UPDATE can race with bpf_mprog_link to cause a Use-After-Free when dereferencing link->prog->type.
--
--- Patch [1]: [PATCH bpf v3 1/3] bpf: Fix potential UAF when reading bpf link info ---
commit 5b8e0ac8575ebc387f2ddc7dee211697bb704588
Author: Pu Lehui <pulehui@huawei.com>
bpf: Fix potential UAF when reading bpf link info
This commit addresses a potential Use-After-Free issue when accessing
link->prog without locks in bpf_link_show_fdinfo and bpf_link_get_info_by_fd.
It resolves the problem by acquiring both normal RCU and tasks trace RCU
read locks before dereferencing the program, preventing concurrent freeing
during bpf_link_update operations.
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 6db306d23b479..2458c68146b95 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -3490,13 +3491,23 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
> }
> seq_printf(m, "link_id:\t%u\n", link->id);
>
> + /* prog can be sleepable */
> + rcu_read_lock_trace();
> + rcu_read_lock();
> + prog = READ_ONCE(link->prog);
[Severity: High]
This isn't a bug introduced by this patch, but since you are fixing lockless
dereferences of link->prog here, could a similar TOCTOU race happen in
bpf_netns_link_update_prog()?
kernel/bpf/net_namespace.c:bpf_netns_link_update_prog() {
...
if (old_prog && old_prog != link->prog)
return -EPERM;
if (new_prog->type != link->prog->type)
return -EINVAL;
mutex_lock(&netns_bpf_mutex);
...
}
Two threads concurrently calling BPF_LINK_UPDATE on a netns link could both
evaluate the old_prog != link->prog check locklessly and pass it. If they
acquire netns_bpf_mutex one after the other, would the second thread
blindly overwrite link->prog, overriding the first thread's update and
violating the BPF_F_REPLACE API contract?
[Severity: High]
This is also a pre-existing issue, but does a similar Use-After-Free race
exist in bpf_mprog_link()?
kernel/bpf/mprog.c:bpf_mprog_link() {
...
if (type && link->prog->type != type) {
bpf_link_put(link);
return -EINVAL;
}
...
}
If a thread calls BPF_PROG_ATTACH on a tcx hook (holding the sleepable
rtnl_lock) and supplies a relative_fd pointing to a netns link,
bpf_mprog_link() executes without an RCU read-side critical section.
Could this thread be preempted, allowing a concurrent BPF_LINK_UPDATE on
the same netns link to replace and free link->prog? When the first thread
resumes, it would dereference link->prog->type where link->prog now points
to freed memory.
> if (prog) {
> bin2hex(prog_tag, prog->tag, sizeof(prog->tag));
> + prog_id = prog->aux->id;
> + }
> + rcu_read_unlock();
> + rcu_read_unlock_trace();
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720033055.1215477-1-pulehui@huaweicloud.com?part=1
next prev parent reply other threads:[~2026-07-20 3:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 3:30 [PATCH bpf v3 0/3] Fixes for bpf link update Pu Lehui
2026-07-20 3:30 ` [PATCH bpf v3 1/3] bpf: Fix potential UAF when reading bpf link info Pu Lehui
2026-07-20 3:50 ` sashiko-bot [this message]
2026-07-20 12:13 ` Pu Lehui
2026-07-20 4:04 ` bot+bpf-ci
2026-07-20 12:17 ` Pu Lehui
2026-07-20 3:30 ` [PATCH bpf v3 2/3] bpf, cgroup: Fix storage not restored when update_effective_progs failed Pu Lehui
2026-07-20 3:41 ` sashiko-bot
2026-07-20 12:06 ` Pu Lehui
2026-07-20 3:30 ` [PATCH bpf v3 3/3] bpf, cgroup: Fix storage null-ptr-deref after replacing prog 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=20260720035032.6C8021F00A3A@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 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.