From: sashiko-bot@kernel.org
To: "Pu Lehui" <pulehui@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v3] bpf, cgroup: Fix invalid storage access after __cgroup_bpf_attach failed
Date: Mon, 03 Aug 2026 01:50:36 +0000 [thread overview]
Message-ID: <20260803015036.E47F71F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260803013934.4036646-1-pulehui@huaweicloud.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] When updating a cgroup BPF link via `bpf_link_update`, `__cgroup_bpf_replace` does not allocate new `cgroup_storage` for the new program and lacks map compatibility checks, leading to severe out-of-bounds kernel memory access.
--
--- Patch [1]: [PATCH bpf v3] bpf, cgroup: Fix invalid storage access after __cgroup_bpf_attach failed ---
commit 91e5396c1d1312a251035a5e4902151e56fc5bdf
Author: Pu Lehui <pulehui@huawei.com>
bpf, cgroup: Fix invalid storage access after __cgroup_bpf_attach failed
This commit fixes a potential invalid storage access issue when replacing a
cgroup BPF program in multi-attach mode fails midway. It saves the old
program's state and storage prior to the update, and properly restores them
in the cleanup path on error.
> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> index 4355ccb78a9c6..57fd1d784e440 100644
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
[ ... ]
While reviewing this file, I noticed a potential issue in __cgroup_bpf_replace():
> static int __cgroup_bpf_replace(struct cgroup *cgrp,
> struct bpf_cgroup_link *link,
> struct bpf_prog *new_prog)
> {
[ ... ]
> cgrp->bpf.revisions[atype] += 1;
> old_prog = xchg(&link->link.prog, new_prog);
[Severity: Critical]
This is a pre-existing issue, but does this function properly handle
cgroup_storage when replacing the program?
If a user replaces an existing cgroup BPF program using bpf_link_update with
a new program that uses a BPF_MAP_TYPE_CGROUP_STORAGE map with a larger
value_size, could this result in an out-of-bounds memory access?
It appears we swap the attached BPF program on the link here without
verifying that the new program's cgroup_storage maps have identical
value sizes to the old program, nor do we allocate new appropriately
sized storage buffers.
Since the verifier authorized the memory access for the new program based on
its larger map size, could bpf_get_local_storage return the smaller old
buffer leading to out-of-bounds read and write accesses?
> replace_effective_prog(cgrp, atype, pl);
> bpf_prog_put(old_prog);
> return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260803013934.4036646-1-pulehui@huaweicloud.com?part=1
next prev parent reply other threads:[~2026-08-03 1:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 1:39 [PATCH bpf v3] bpf, cgroup: Fix invalid storage access after __cgroup_bpf_attach failed Pu Lehui
2026-08-03 1:50 ` sashiko-bot [this message]
2026-08-03 2:11 ` Pu Lehui
2026-08-04 23:20 ` 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=20260803015036.E47F71F00A3D@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