Re: [syzbot] general protection fault in kernfs_get_inode
From: Christian Brauner
Date: Sat Oct 08 2022 - 01:51:47 EST
On Sat, Oct 08, 2022 at 07:46:12AM +0200, Christian Brauner wrote:
> 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;
>
> Tejun, thanks for the Cc.
> Yep, that seems to be the correct analysis.
> I assume you're turning this into a proper patch, so:
>
> Reviewed-by: Christian Brauner (Microsoft) <brauner@xxxxxxxxxx>
#syz test: git@xxxxxxxxxx:brauner/linux.git kernel.cgroup_may_write.fix