Re: [PATCH] nilfs2: fix use-after-free bug in nilfs_mdt_destroy()

From: Dongliang Mu
Date: Tue Aug 16 2022 - 02:40:30 EST


On Tue, Aug 16, 2022 at 11:11 AM Ryusuke Konishi
<konishi.ryusuke@xxxxxxxxx> wrote:
>
> On Tue, Aug 16, 2022 at 8:04 AM Al Viro wrote:
> >
> > On Tue, Aug 16, 2022 at 05:34:12AM +0900, Ryusuke Konishi wrote:
> >
> > > Yes, I agree it's better if security_inode_alloc() is moved to the end as
> > > possible in the sense of avoiding similar issues.
> > > But, would that vfs change be safe to backport to stable trees?
> >
> > Yes.
> >
> > > It looks like the error handling for security_inode_alloc() is in the
> > > middle of inode_init_always() for a very long time..
> >
> > Look at the initializations done after it. The only thing with effects
> > outside of inode itself is (since 2010) an increment of nr_inodes.
> >
> > > If you want to see the impact of the vfs change, I think it's one way
> > > to apply this one in advance. Or if you want to fix it in one step,
> > > I think it's good too. How do you feel about this ?
> >
> > IMO that should go into inode_init_always(), with Cc:stable. If you
> > (or Dongliang Mu, or anybody else) would post such variant with
> > reasonable commit message, I'll pick it into vfs.git and feed to Linus
> > in the next window. E.g. into #work.inode, with that branch being
> > made never-rebased, so that you could pull it into your development
> > branch as soon as it's there...
>
> I agree with your thoughts on the course of action.
> Andrew, I withdraw this patch.
>
> Dongliang (or Jiacheng?), would it be possible for you to post a revised patch
> against inode_init_always() that moves the call of security_inode_alloc()
> instead of i_private initialization (as Al Viro said in a nearby thread [1]) ?
> If you have time, I would like to leave it to you since you wrote the
> original patch for inode_init_always().

Sure, I will post a v2 patch that moves security_inode_alloc to the
location just prior to
this_cpu_inc(nr_inodes);
with proper commit message.

>
> [1] https://lkml.kernel.org/r/CAO4S-mficMz1mQW06EuCF+o11+mRDiCpufqVfoHkcRbQbs8kVw@xxxxxxxxxxxxxx
>
> Thanks,
> Ryusuke Konishi