Re: [PATCH] nilfs2: fix use-after-free bug of nilfs_root in nilfs_evict_inode()

From: Andrew Morton
Date: Fri May 12 2023 - 19:46:33 EST


On Fri, 12 May 2023 16:44:24 -0700 Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Wed, 10 May 2023 00:29:56 +0900 Ryusuke Konishi <konishi.ryusuke@xxxxxxxxx> wrote:
>
> > During unmount process of nilfs2, nothing holds nilfs_root structure after
> > nilfs2 detaches its writer in nilfs_detach_log_writer(). However, since
> > nilfs_evict_inode() uses nilfs_root for some cleanup operations, it may
> > cause use-after-free read if inodes are left in "garbage_list" and
> > released by nilfs_dispose_list() at the end of nilfs_detach_log_writer().
> >
> > Fix this issue by modifying nilfs_evict_inode() to only clear inode
> > without additional metadata changes that use nilfs_root if the file system
> > is degraded to read-only or the writer is detached.
> >
> > ...
> >
> > --- a/fs/nilfs2/inode.c
> > +++ b/fs/nilfs2/inode.c
> > @@ -917,6 +917,7 @@ void nilfs_evict_inode(struct inode *inode)
> > struct nilfs_transaction_info ti;
> > struct super_block *sb = inode->i_sb;
> > struct nilfs_inode_info *ii = NILFS_I(inode);
> > + struct the_nilfs *nilfs;
> > int ret;
>
> `the_nilfs' is unused - I'll zap it.

argh, sorry, brainfart.