BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pu Lehui" <pulehui@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v6 4/4] bpf, cgroup: Fix storage null-ptr-deref after replacing prog
Date: Wed, 22 Jul 2026 07:35:00 +0000	[thread overview]
Message-ID: <20260722073501.64ACE1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260722072326.1545677-5-pulehui@huaweicloud.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing rollback of `pl->flags` on the error path in `__cgroup_bpf_attach` permanently corrupts the execution order of the replaced program.
--

--- Patch [4]: [PATCH bpf v6 4/4] bpf, cgroup: Fix storage null-ptr-deref after replacing prog ---
commit f8726e124d0a4e72b87976830f0741e286d474df
Author: Pu Lehui <pulehui@huawei.com>

bpf, cgroup: Fix storage null-ptr-deref after replacing prog

Syzkaller reported a storage null-ptr-deref issue after replacing a prog.
The issue is fixed by properly allocating the storage and comparing the old
and new storage pointers, falling back to an RCU-safe update if they change.
Additionally, proper rollbacks for storage and flags are added to the error
path in __cgroup_bpf_attach for code rigor.

> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -883,7 +885,10 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
>  	pl->prog = prog;
>  	pl->link = link;
>  	pl->flags = flags;
> +	if (old_prog)
> +		bpf_cgroup_storages_assign(old_storage, pl->storage);
>  	bpf_cgroup_storages_assign(pl->storage, storage);
> +	old_flags = cgrp->bpf.flags[atype];
>  	cgrp->bpf.flags[atype] = saved_flags;
>  
>  	if (type == BPF_LSM_CGROUP) {

[ ... ]

> @@ -915,12 +920,14 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
>  	if (old_prog) {
>  		pl->prog = old_prog;
>  		pl->link = NULL;
> +		bpf_cgroup_storages_assign(pl->storage, old_storage);
>  	}

[Severity: High]
This is a pre-existing issue, but since this patch tightens the error handling
and rollbacks in __cgroup_bpf_attach(), should we also restore the original
pl->flags here?

Earlier in the function, pl->flags is overwritten with the incoming flags:

	pl->prog = prog;
	pl->link = link;
	pl->flags = flags;

If update_effective_progs() later fails (e.g., due to memory allocation
failure), the error path restores pl->prog, pl->link, and pl->storage, but
misses pl->flags. If a user attempts to replace a program using BPF_F_REPLACE
with different BPF_F_PREORDER settings and the replacement fails, could this
leave the original program active but with its execution order silently
corrupted?

>  	bpf_cgroup_storages_free(new_storage);
>  	if (!old_prog) {
>  		hlist_del(&pl->node);
>  		kfree(pl);
>  	}
> +	cgrp->bpf.flags[atype] = old_flags;
>  	return err;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260722072326.1545677-1-pulehui@huaweicloud.com?part=4

  reply	other threads:[~2026-07-22  7:35 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
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 [this message]
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=20260722073501.64ACE1F00A3A@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