public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: fix mmp use after free during unmount
@ 2016-10-20 18:19 Eric Sandeen
  2016-10-20 20:26 ` Andreas Dilger
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2016-10-20 18:19 UTC (permalink / raw)
  To: linux-ext4@vger.kernel.org; +Cc: shuwang

In ext4_put_super, we call brelse on the buffer head containing
the ext4 superblock, but then try to use it when we stop the
mmp thread, because when the thread shuts down it does:

write_mmp_block
  ext4_mmp_csum_set
    ext4_has_metadata_csum
      WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb)...)

which reaches into sb->s_fs_info->s_es->s_feature_ro_compat,
which lives in the superblock buffer s_sbh which we just released.

Fix this by moving the brelse down to a point where we are no
longer using it.

Reported-by: Wang Shu <shuwang@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

Note: found by inspection after a bug report via KASAN,
compile-tested only.

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 6db81fb..f273212 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -862,7 +862,6 @@ static void ext4_put_super(struct super_block *sb)
 	percpu_counter_destroy(&sbi->s_dirs_counter);
 	percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
 	percpu_free_rwsem(&sbi->s_journal_flag_rwsem);
-	brelse(sbi->s_sbh);
 #ifdef CONFIG_QUOTA
 	for (i = 0; i < EXT4_MAXQUOTAS; i++)
 		kfree(sbi->s_qf_names[i]);
@@ -894,6 +893,9 @@ static void ext4_put_super(struct super_block *sb)
 	}
 	if (sbi->s_mmp_tsk)
 		kthread_stop(sbi->s_mmp_tsk);
+
+	/* Don't let this go until everything is done with the ext4 super */
+	brelse(sbi->s_sbh);
 	sb->s_fs_info = NULL;
 	/*
 	 * Now that we are completely done shutting down the



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

* Re: [PATCH] ext4: fix mmp use after free during unmount
  2016-10-20 18:19 [PATCH] ext4: fix mmp use after free during unmount Eric Sandeen
@ 2016-10-20 20:26 ` Andreas Dilger
  2016-11-26 19:31   ` Theodore Ts'o
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Dilger @ 2016-10-20 20:26 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: linux-ext4@vger.kernel.org, shuwang

[-- Attachment #1: Type: text/plain, Size: 1883 bytes --]

On Oct 20, 2016, at 12:19 PM, Eric Sandeen <sandeen@redhat.com> wrote:
> 
> In ext4_put_super, we call brelse on the buffer head containing
> the ext4 superblock, but then try to use it when we stop the
> mmp thread, because when the thread shuts down it does:
> 
> write_mmp_block
>  ext4_mmp_csum_set
>    ext4_has_metadata_csum
>      WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb)...)
> 
> which reaches into sb->s_fs_info->s_es->s_feature_ro_compat,
> which lives in the superblock buffer s_sbh which we just released.
> 
> Fix this by moving the brelse down to a point where we are no
> longer using it.
> 
> Reported-by: Wang Shu <shuwang@redhat.com>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> 
> Note: found by inspection after a bug report via KASAN,
> compile-tested only.
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 6db81fb..f273212 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -862,7 +862,6 @@ static void ext4_put_super(struct super_block *sb)
> 	percpu_counter_destroy(&sbi->s_dirs_counter);
> 	percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
> 	percpu_free_rwsem(&sbi->s_journal_flag_rwsem);
> -	brelse(sbi->s_sbh);
> #ifdef CONFIG_QUOTA
> 	for (i = 0; i < EXT4_MAXQUOTAS; i++)
> 		kfree(sbi->s_qf_names[i]);
> @@ -894,6 +893,9 @@ static void ext4_put_super(struct super_block *sb)
> 	}
> 	if (sbi->s_mmp_tsk)
> 		kthread_stop(sbi->s_mmp_tsk);
> +
> +	/* Don't let this go until everything is done with the ext4 super */
> +	brelse(sbi->s_sbh);
> 	sb->s_fs_info = NULL;
> 	/*
> 	 * Now that we are completely done shutting down the
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] ext4: fix mmp use after free during unmount
  2016-10-20 20:26 ` Andreas Dilger
@ 2016-11-26 19:31   ` Theodore Ts'o
  0 siblings, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2016-11-26 19:31 UTC (permalink / raw)
  To: Andreas Dilger; +Cc: Eric Sandeen, linux-ext4@vger.kernel.org, shuwang

On Thu, Oct 20, 2016 at 02:26:38PM -0600, Andreas Dilger wrote:
> On Oct 20, 2016, at 12:19 PM, Eric Sandeen <sandeen@redhat.com> wrote:
> > 
> > In ext4_put_super, we call brelse on the buffer head containing
> > the ext4 superblock, but then try to use it when we stop the
> > mmp thread, because when the thread shuts down it does:
> > 
> > write_mmp_block
> >  ext4_mmp_csum_set
> >    ext4_has_metadata_csum
> >      WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb)...)
> > 
> > which reaches into sb->s_fs_info->s_es->s_feature_ro_compat,
> > which lives in the superblock buffer s_sbh which we just released.
> > 
> > Fix this by moving the brelse down to a point where we are no
> > longer using it.
> > 
> > Reported-by: Wang Shu <shuwang@redhat.com>
> > Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> 
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>

Applied, thanks.

					- Ted

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

end of thread, other threads:[~2016-11-26 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-20 18:19 [PATCH] ext4: fix mmp use after free during unmount Eric Sandeen
2016-10-20 20:26 ` Andreas Dilger
2016-11-26 19:31   ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox