From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Liu Jing <liujing@cmss.chinamobile.com>, ast@kernel.org
Cc: daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com,
memxor@gmail.com, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com,
ihor.solodrai@linux.dev, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] bpf: cgroup: fix null-ptr-deref in __cgroup_bpf_attach
Date: Wed, 2 Sep 2026 17:41:34 +0800 [thread overview]
Message-ID: <286de7d2-3750-4a44-a8e8-7054c8cf51d9@linux.dev> (raw)
In-Reply-To: <20260902090220.16395-1-liujing@cmss.chinamobile.com>
on 9/2/26 5:02 PM, Liu Jing wrote:
> In __cgroup_bpf_attach(), the expression "prog ? : link->link.prog"
> dereferences link before validating that link is non-NULL. If both
> prog and link are NULL (a contract violation by the caller), this
> causes a null pointer dereference.
Both being NULL is unreachable, so the new check is dead code.
It's meaningless.
>
> Add a safe ternary fallback and a NULL check for new_prog before
> it is used further.
>
> Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
> ---
> kernel/bpf/cgroup.c | 4 +++-
> 1 file changed, 3 insertion(+), 1 deletion(-)
>
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -814,7 +814,7 @@
> struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
> struct bpf_cgroup_storage *new_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
> struct bpf_cgroup_storage *old_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
> - struct bpf_prog *new_prog = prog ? : link->link.prog;
> + struct bpf_prog *new_prog = prog ? : (link ? link->link.prog : NULL);
> enum cgroup_bpf_attach_type atype;
> u32 old_flags, old_pl_flags;
> struct bpf_prog_list *pl;
> @@ -833,6 +833,8 @@
> return -EINVAL;
> if (!!replace_prog != !!(flags & BPF_F_REPLACE))
> /* replace_prog implies BPF_F_REPLACE, and vice versa */
> + return -EINVAL;
> + if (!new_prog)
> return -EINVAL;
>
> atype = bpf_cgroup_atype_find(type, new_prog->aux->attach_btf_id);
>
> --
> 2.43.0
next prev parent reply other threads:[~2026-09-02 9:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 9:02 [PATCH] bpf: cgroup: fix null-ptr-deref in __cgroup_bpf_attach Liu Jing
2026-09-02 9:41 ` Jiayuan Chen [this message]
2026-09-08 16:00 ` Emil Tsalapatis
2026-09-02 9:52 ` bot+bpf-ci
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=286de7d2-3750-4a44-a8e8-7054c8cf51d9@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liujing@cmss.chinamobile.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@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.