All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: Unregister sysfs path before destroying jbd2 journal
@ 2020-03-18  6:13 Ritesh Harjani
  2020-03-18  9:13 ` Jan Kara
  0 siblings, 1 reply; 3+ messages in thread
From: Ritesh Harjani @ 2020-03-18  6:13 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, jack, adilger.kernel, linux-fsdevel, Ritesh Harjani

Call ext4_unregister_sysfs(), before destroying jbd2 journal,
since below might cause, NULL pointer dereference issue.
This got reported with LTP tests.

ext4_put_super() 		cat /sys/fs/ext4/loop2/journal_task
	| 				ext4_attr_show();
ext4_jbd2_journal_destroy();  			|
    	|				 journal_task_show()
	| 					|
	| 				task_pid_vnr(NULL);
sbi->s_journal = NULL;

Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>
---
 fs/ext4/super.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 5dc65b7583cb..27ab130a40d1 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1024,6 +1024,13 @@ static void ext4_put_super(struct super_block *sb)
 
 	destroy_workqueue(sbi->rsv_conversion_wq);
 
+	/*
+	 * Unregister sysfs before destroying jbd2 journal.
+	 * Since we could still access attr_journal_task attribute via sysfs
+	 * path which could have sbi->s_journal->j_task as NULL
+	 */
+	ext4_unregister_sysfs(sb);
+
 	if (sbi->s_journal) {
 		aborted = is_journal_aborted(sbi->s_journal);
 		err = jbd2_journal_destroy(sbi->s_journal);
@@ -1034,7 +1041,6 @@ static void ext4_put_super(struct super_block *sb)
 		}
 	}
 
-	ext4_unregister_sysfs(sb);
 	ext4_es_unregister_shrinker(sbi);
 	del_timer_sync(&sbi->s_err_report);
 	ext4_release_system_zone(sb);
-- 
2.21.0


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

* Re: [PATCH] ext4: Unregister sysfs path before destroying jbd2 journal
  2020-03-18  6:13 [PATCH] ext4: Unregister sysfs path before destroying jbd2 journal Ritesh Harjani
@ 2020-03-18  9:13 ` Jan Kara
  2020-03-26 14:53   ` Theodore Y. Ts'o
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2020-03-18  9:13 UTC (permalink / raw)
  To: Ritesh Harjani; +Cc: linux-ext4, tytso, jack, adilger.kernel, linux-fsdevel

On Wed 18-03-20 11:43:01, Ritesh Harjani wrote:
> Call ext4_unregister_sysfs(), before destroying jbd2 journal,
> since below might cause, NULL pointer dereference issue.
> This got reported with LTP tests.
> 
> ext4_put_super() 		cat /sys/fs/ext4/loop2/journal_task
> 	| 				ext4_attr_show();
> ext4_jbd2_journal_destroy();  			|
>     	|				 journal_task_show()
> 	| 					|
> 	| 				task_pid_vnr(NULL);
> sbi->s_journal = NULL;
> 
> Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>

Yeah, makes sence. Thanks for the patch! You can add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/super.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 5dc65b7583cb..27ab130a40d1 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -1024,6 +1024,13 @@ static void ext4_put_super(struct super_block *sb)
>  
>  	destroy_workqueue(sbi->rsv_conversion_wq);
>  
> +	/*
> +	 * Unregister sysfs before destroying jbd2 journal.
> +	 * Since we could still access attr_journal_task attribute via sysfs
> +	 * path which could have sbi->s_journal->j_task as NULL
> +	 */
> +	ext4_unregister_sysfs(sb);
> +
>  	if (sbi->s_journal) {
>  		aborted = is_journal_aborted(sbi->s_journal);
>  		err = jbd2_journal_destroy(sbi->s_journal);
> @@ -1034,7 +1041,6 @@ static void ext4_put_super(struct super_block *sb)
>  		}
>  	}
>  
> -	ext4_unregister_sysfs(sb);
>  	ext4_es_unregister_shrinker(sbi);
>  	del_timer_sync(&sbi->s_err_report);
>  	ext4_release_system_zone(sb);
> -- 
> 2.21.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] ext4: Unregister sysfs path before destroying jbd2 journal
  2020-03-18  9:13 ` Jan Kara
@ 2020-03-26 14:53   ` Theodore Y. Ts'o
  0 siblings, 0 replies; 3+ messages in thread
From: Theodore Y. Ts'o @ 2020-03-26 14:53 UTC (permalink / raw)
  To: Jan Kara; +Cc: Ritesh Harjani, linux-ext4, adilger.kernel, linux-fsdevel

On Wed, Mar 18, 2020 at 10:13:18AM +0100, Jan Kara wrote:
> On Wed 18-03-20 11:43:01, Ritesh Harjani wrote:
> > Call ext4_unregister_sysfs(), before destroying jbd2 journal,
> > since below might cause, NULL pointer dereference issue.
> > This got reported with LTP tests.
> > 
> > ext4_put_super() 		cat /sys/fs/ext4/loop2/journal_task
> > 	| 				ext4_attr_show();
> > ext4_jbd2_journal_destroy();  			|
> >     	|				 journal_task_show()
> > 	| 					|
> > 	| 				task_pid_vnr(NULL);
> > sbi->s_journal = NULL;
> > 
> > Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>
> 
> Yeah, makes sence. Thanks for the patch! You can add:
> 
> Reviewed-by: Jan Kara <jack@suse.cz>

Applied, thanks.

					- Ted

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

end of thread, other threads:[~2020-03-26 14:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18  6:13 [PATCH] ext4: Unregister sysfs path before destroying jbd2 journal Ritesh Harjani
2020-03-18  9:13 ` Jan Kara
2020-03-26 14:53   ` Theodore Y. Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.