From: Martin KaFai Lau <martin.lau@linux.dev>
To: Yosry Ahmed <yosryahmed@google.com>
Cc: Christian Brauner <brauner@kernel.org>, Tejun Heo <tj@kernel.org>,
syzbot <syzbot+534ee3d24c37c411f37f@syzkaller.appspotmail.com>,
gregkh@linuxfoundation.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
syzkaller-bugs@googlegroups.com,
"Christian A. Ehrhardt" <lk@c--e.de>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH] cgroup: Fix crash with CLONE_INTO_CGROUP and v1 cgroups
Date: Mon, 10 Oct 2022 11:38:39 -0700 [thread overview]
Message-ID: <5abb2728-9867-175c-911c-b0bb49b8babd@linux.dev> (raw)
In-Reply-To: <CAJD7tkaQSMSmrb3Nt17-NPAPkvEoUp5tJBg8e4UYn0eU6x-Gqw@mail.gmail.com>
On 10/9/22 11:42 AM, Yosry Ahmed wrote:
> On Sun, Oct 9, 2022 at 6:10 AM Christian A. Ehrhardt <lk@c--e.de> wrote:
>>
>>
>> Since commit f3a2aebdd6, Version 1 cgroups no longer cause an
>> error when used with CLONE_INTO_CGROUP. However, the permission
>> checks performed during clone assume a Version 2 cgroup.
>>
>> Restore the error check for V1 cgroups in the clone() path.
>>
>> Reported-by: syzbot+534ee3d24c37c411f37f@syzkaller.appspotmail.com
>> Link: https://lore.kernel.org/lkml/000000000000385cbf05ea3f1862@google.com/
>> Fixes: f3a2aebdd6 ("cgroup: enable cgroup_get_from_file() on cgroup1")
>
> Thanks for fixing this, and sorry if this caused a mess.
>
> cgroup_get_from_file() independently seemed like it can support
> cgroup1, I didn't realize that some of the callers depend on the fact
> that it only supports cgroup2.
>
> +Andrii Nakryiko +Alexei Starovoitov +Martin KaFai Lau +bpf
> I wonder if BPF users have this dependency. Does cgroup_bpf_attach()
> also depend on cgroup_get_from_fd() (which calls
> cgroup_get_from_file()) eliminating v1 cgroups?
Yes, cgroup_bpf_{prog,link}_attach() depends on cgroup_get_from_fd() only
returning v2 cgroup. Thus, it needs a fix to get back this filtering after
commit f3a2aebdd6.
>
> It seems like cgroup storages (and some other places) use cgroup ids.
> Collisions can happen in cgroup1 ids so I am assuming we want to add a
> check there as well. Perhaps in cgroup_bpf_attach() ?
From a quick look, cgroup storage should be fine. The insertion (where the
cgrp is required for the key purpose) has already passed the attach filtering.
Where 'other places' might have problem with the cgroup id?
>
> I can send a patch for this if that's the case.
>
>> Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
>> ---
>> kernel/cgroup/cgroup.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
>> index b6e3110b3ea7..f7fc3afa88c1 100644
>> --- a/kernel/cgroup/cgroup.c
>> +++ b/kernel/cgroup/cgroup.c
>> @@ -6244,6 +6244,11 @@ static int cgroup_css_set_fork(struct kernel_clone_args *kargs)
>> goto err;
>> }
>>
>> + if (!cgroup_on_dfl(dst_cgrp)) {
>> + ret = -EBADF;
>> + goto err;
>> + }
>> +
>> if (cgroup_is_dead(dst_cgrp)) {
>> ret = -ENODEV;
>> goto err;
>> --
>> 2.34.1
>>
next prev parent reply other threads:[~2022-10-10 18:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-05 0:59 [syzbot] general protection fault in kernfs_get_inode syzbot
2022-10-05 2:19 ` syzbot
2022-10-07 21:35 ` Tejun Heo
2022-10-08 5:46 ` Christian Brauner
2022-10-08 5:51 ` Christian Brauner
2022-10-08 11:15 ` syzbot
2022-10-08 18:29 ` Christian A. Ehrhardt
2022-10-09 8:42 ` Christian Brauner
2022-10-09 13:10 ` [PATCH] cgroup: Fix crash with CLONE_INTO_CGROUP and v1 cgroups Christian A. Ehrhardt
2022-10-09 17:35 ` Christian Brauner
2022-10-09 18:16 ` Greg KH
2022-10-10 18:48 ` Tejun Heo
2022-10-09 18:42 ` Yosry Ahmed
2022-10-10 18:38 ` Martin KaFai Lau [this message]
2022-10-10 18:43 ` Tejun Heo
2022-10-10 18:50 ` Yosry Ahmed
2022-10-10 19:51 ` Tejun Heo
2022-10-10 19:57 ` Yosry Ahmed
2022-10-10 20:07 ` Tejun Heo
2022-10-10 20:09 ` Yosry Ahmed
2022-11-17 7:26 ` [syzbot] general protection fault in kernfs_get_inode syzbot
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=5abb2728-9867-175c-911c-b0bb49b8babd@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lk@c--e.de \
--cc=syzbot+534ee3d24c37c411f37f@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tj@kernel.org \
--cc=yosryahmed@google.com \
/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;
as well as URLs for NNTP newsgroup(s).