From: Christian Brauner <brauner@kernel.org>
To: "Christian A. Ehrhardt" <lk@c--e.de>
Cc: Tejun Heo <tj@kernel.org>,
syzbot <syzbot+534ee3d24c37c411f37f@syzkaller.appspotmail.com>,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
syzkaller-bugs@googlegroups.com,
Yosry Ahmed <yosryahmed@google.com>
Subject: Re: [syzbot] general protection fault in kernfs_get_inode
Date: Sun, 9 Oct 2022 10:42:59 +0200 [thread overview]
Message-ID: <20221009084039.cw6meqbvy4362lsa@wittgenstein> (raw)
In-Reply-To: <Y0HBlJ4AoZba93Uf@cae.in-ulm.de>
On Sat, Oct 08, 2022 at 08:29:40PM +0200, Christian A. Ehrhardt wrote:
>
> Hi (from another Christian),
>
> On Fri, Oct 07, 2022 at 11:35:49AM -1000, Tejun Heo wrote:
> > (cc'ing Christian and quoting whole body)
> >
> > Christan, I can't repro it here but think what we need is sth like the
> > following. The problem is that cgroup_is_dead() check in the fork path isn't
> > enough as the perm check depends on cgrp->procs_file being available but
> > that is cleared while DYING before DEAD. So, depending on the timing, we can
> > end up trying to deref NULL pointer in may_write.
> >
> > diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> > index 8ad2c267ff471..603b7167450a1 100644
> > --- a/kernel/cgroup/cgroup.c
> > +++ b/kernel/cgroup/cgroup.c
> > @@ -4934,6 +4934,10 @@ static int cgroup_may_write(const struct cgroup *cgrp, struct super_block *sb)
> >
> > lockdep_assert_held(&cgroup_mutex);
> >
> > + /*if @cgrp is being removed, procs_file may already be gone */
> > + if (!cgrp->procs_file.kn)
> > + return -ENODEV;
> > +
> > inode = kernfs_get_inode(sb, cgrp->procs_file.kn);
> > if (!inode)
> > return -ENOMEM;
>
> I had syzbot hit the same crash here and as can be seen from the
> reproducer the root cause is that the target cgroup (specified
> via CLONE_INTO_CGROUP) is a version 1 cgroup. These cgroups just
> don't initialize ->procs_file.kn.
>
> This is a regression from v6.0 caused by
>
> f3a2aebdd6 ("cgroup: enable cgroup_get_from_file() on cgroup1")
Yeah, this patch is wrong in its simple form and definitely breaks CLONE_INTO_CGROUP.
CLONE_INTO_CGROUP can only work with cgroup2 fds. It absolutely cannot
work with cgroup1 fds. The semantics would be terrible as controllers
can be mounted into separate hierarchies.
>
> Unless we want to revert this patch the correct fix might be
> something like this:
>
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index f487c54a0087..67474b1ae087 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -6249,6 +6249,11 @@ static int cgroup_css_set_fork(struct kernel_clone_args *kargs)
> goto err;
> }
>
> + if (!cgroup_on_dfl(dst_cgrp)) {
> + ret = -EBADF;
> + goto err;
> + }
That seems like a good enough patch to me.
next prev parent reply other threads:[~2022-10-09 8:43 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 [this message]
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
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=20221009084039.cw6meqbvy4362lsa@wittgenstein \
--to=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).