linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix use-after-free issue with sbi->stat_info
@ 2018-12-24 13:06 Sahitya Tummala
  2018-12-25  3:06 ` Chao Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Sahitya Tummala @ 2018-12-24 13:06 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu, linux-f2fs-devel; +Cc: linux-kernel, Sahitya Tummala

iput() on sbi->node_inode can update sbi->stat_info
in the below context, if the f2fs_write_checkpoint()
has failed with error.

f2fs_balance_fs_bg+0x1ac/0x1ec
f2fs_write_node_pages+0x4c/0x260
do_writepages+0x80/0xbc
__writeback_single_inode+0xdc/0x4ac
writeback_single_inode+0x9c/0x144
write_inode_now+0xc4/0xec
iput+0x194/0x22c
f2fs_put_super+0x11c/0x1e8
generic_shutdown_super+0x70/0xf4
kill_block_super+0x2c/0x5c
kill_f2fs_super+0x44/0x50
deactivate_locked_super+0x60/0x8c
deactivate_super+0x68/0x74
cleanup_mnt+0x40/0x78

Fix this by moving f2fs_destroy_stats() further below iput().

Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
---
 fs/f2fs/super.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index e184ad4e..df41a3a 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1058,9 +1058,6 @@ static void f2fs_put_super(struct super_block *sb)
 		f2fs_write_checkpoint(sbi, &cpc);
 	}
 
-	/* f2fs_write_checkpoint can update stat informaion */
-	f2fs_destroy_stats(sbi);
-
 	/*
 	 * normally superblock is clean, so we need to release this.
 	 * In addition, EIO will skip do checkpoint, we need this as well.
@@ -1080,6 +1077,12 @@ static void f2fs_put_super(struct super_block *sb)
 	iput(sbi->node_inode);
 	iput(sbi->meta_inode);
 
+	/*
+	 * iput() can update stat information, if f2fs_write_checkpoint()
+	 * above failed with error.
+	 */
+	f2fs_destroy_stats(sbi);
+
 	/* destroy f2fs internal modules */
 	f2fs_destroy_node_manager(sbi);
 	f2fs_destroy_segment_manager(sbi);
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] f2fs: fix use-after-free issue with sbi->stat_info
  2018-12-24 13:06 [PATCH] f2fs: fix use-after-free issue with sbi->stat_info Sahitya Tummala
@ 2018-12-25  3:06 ` Chao Yu
  2018-12-26  4:26   ` Sahitya Tummala
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2018-12-25  3:06 UTC (permalink / raw)
  To: Sahitya Tummala, Jaegeuk Kim, linux-f2fs-devel; +Cc: linux-kernel

On 2018/12/24 21:06, Sahitya Tummala wrote:
> iput() on sbi->node_inode can update sbi->stat_info
> in the below context, if the f2fs_write_checkpoint()
> has failed with error.
> 
> f2fs_balance_fs_bg+0x1ac/0x1ec
> f2fs_write_node_pages+0x4c/0x260
> do_writepages+0x80/0xbc
> __writeback_single_inode+0xdc/0x4ac
> writeback_single_inode+0x9c/0x144
> write_inode_now+0xc4/0xec
> iput+0x194/0x22c
> f2fs_put_super+0x11c/0x1e8
> generic_shutdown_super+0x70/0xf4
> kill_block_super+0x2c/0x5c
> kill_f2fs_super+0x44/0x50
> deactivate_locked_super+0x60/0x8c
> deactivate_super+0x68/0x74
> cleanup_mnt+0x40/0x78
> 
> Fix this by moving f2fs_destroy_stats() further below iput().
> 
> Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
> ---
>  fs/f2fs/super.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index e184ad4e..df41a3a 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -1058,9 +1058,6 @@ static void f2fs_put_super(struct super_block *sb)
>  		f2fs_write_checkpoint(sbi, &cpc);
>  	}
>  
> -	/* f2fs_write_checkpoint can update stat informaion */
> -	f2fs_destroy_stats(sbi);

The code order in error path of fill_super is almost the same as the one of
put_super, could you please check that as well?

Thanks,

> -
>  	/*
>  	 * normally superblock is clean, so we need to release this.
>  	 * In addition, EIO will skip do checkpoint, we need this as well.
> @@ -1080,6 +1077,12 @@ static void f2fs_put_super(struct super_block *sb)
>  	iput(sbi->node_inode);
>  	iput(sbi->meta_inode);
>  
> +	/*
> +	 * iput() can update stat information, if f2fs_write_checkpoint()
> +	 * above failed with error.
> +	 */
> +	f2fs_destroy_stats(sbi);
> +
>  	/* destroy f2fs internal modules */
>  	f2fs_destroy_node_manager(sbi);
>  	f2fs_destroy_segment_manager(sbi);
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] f2fs: fix use-after-free issue with sbi->stat_info
  2018-12-25  3:06 ` Chao Yu
@ 2018-12-26  4:26   ` Sahitya Tummala
  0 siblings, 0 replies; 3+ messages in thread
From: Sahitya Tummala @ 2018-12-26  4:26 UTC (permalink / raw)
  To: Chao Yu; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel

On Tue, Dec 25, 2018 at 11:06:45AM +0800, Chao Yu wrote:
> On 2018/12/24 21:06, Sahitya Tummala wrote:
> > iput() on sbi->node_inode can update sbi->stat_info
> > in the below context, if the f2fs_write_checkpoint()
> > has failed with error.
> > 
> > f2fs_balance_fs_bg+0x1ac/0x1ec
> > f2fs_write_node_pages+0x4c/0x260
> > do_writepages+0x80/0xbc
> > __writeback_single_inode+0xdc/0x4ac
> > writeback_single_inode+0x9c/0x144
> > write_inode_now+0xc4/0xec
> > iput+0x194/0x22c
> > f2fs_put_super+0x11c/0x1e8
> > generic_shutdown_super+0x70/0xf4
> > kill_block_super+0x2c/0x5c
> > kill_f2fs_super+0x44/0x50
> > deactivate_locked_super+0x60/0x8c
> > deactivate_super+0x68/0x74
> > cleanup_mnt+0x40/0x78
> > 
> > Fix this by moving f2fs_destroy_stats() further below iput().
> > 
> > Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
> > ---
> >  fs/f2fs/super.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> > index e184ad4e..df41a3a 100644
> > --- a/fs/f2fs/super.c
> > +++ b/fs/f2fs/super.c
> > @@ -1058,9 +1058,6 @@ static void f2fs_put_super(struct super_block *sb)
> >  		f2fs_write_checkpoint(sbi, &cpc);
> >  	}
> >  
> > -	/* f2fs_write_checkpoint can update stat informaion */
> > -	f2fs_destroy_stats(sbi);
> 
> The code order in error path of fill_super is almost the same as the one of
> put_super, could you please check that as well?
> 

Thanks Chao, for pointing it out. Yes, the same issue exists in error path of
fill_super as well. I will fix it.

> Thanks,
> 
> > -
> >  	/*
> >  	 * normally superblock is clean, so we need to release this.
> >  	 * In addition, EIO will skip do checkpoint, we need this as well.
> > @@ -1080,6 +1077,12 @@ static void f2fs_put_super(struct super_block *sb)
> >  	iput(sbi->node_inode);
> >  	iput(sbi->meta_inode);
> >  
> > +	/*
> > +	 * iput() can update stat information, if f2fs_write_checkpoint()
> > +	 * above failed with error.
> > +	 */
> > +	f2fs_destroy_stats(sbi);
> > +
> >  	/* destroy f2fs internal modules */
> >  	f2fs_destroy_node_manager(sbi);
> >  	f2fs_destroy_segment_manager(sbi);
> > 
> 

-- 
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-26  4:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-24 13:06 [PATCH] f2fs: fix use-after-free issue with sbi->stat_info Sahitya Tummala
2018-12-25  3:06 ` Chao Yu
2018-12-26  4:26   ` Sahitya Tummala

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).