From: Martin KaFai Lau <martin.lau@linux.dev>
To: Mikhail Lobanov <m.lobanov@rosalinux.ru>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] bpf: dereference of null in __cgroup_bpf_query() function
Date: Mon, 8 Apr 2024 17:10:48 -0700 [thread overview]
Message-ID: <737ae55d-3cd0-40fb-b3e9-3b676f1f735f@linux.dev> (raw)
In-Reply-To: <20240406151457.4774-1-m.lobanov@rosalinux.ru>
On 4/6/24 8:14 AM, Mikhail Lobanov wrote:
> In the __cgroup_bpf_query() function, it is possible to dereference
> the null pointer in the line id = prog->aux->id; since there is no
> check for a non-zero value of the variable prog.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: af6eea57437a ("bpf: Implement bpf_link-based cgroup BPF program attachment")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
> ---
> kernel/bpf/cgroup.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> index 491d20038cbe..7f2db96f0c6a 100644
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -1092,6 +1092,8 @@ static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
> i = 0;
> hlist_for_each_entry(pl, progs, node) {
> prog = prog_list_prog(pl);
> + if (!prog_list_prog(pl))
prog cannot be null. It is under cgroup_lock().
> + continue;
> id = prog->aux->id;
> if (copy_to_user(prog_ids + i, &id, sizeof(id)))
> return -EFAULT;
prev parent reply other threads:[~2024-04-09 0:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-06 15:14 [PATCH] bpf: dereference of null in __cgroup_bpf_query() function Mikhail Lobanov
2024-04-09 0:10 ` Martin KaFai Lau [this message]
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=737ae55d-3cd0-40fb-b3e9-3b676f1f735f@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.lobanov@rosalinux.ru \
--cc=roman.gushchin@linux.dev \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
/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