From: Ritesh Harjani <riteshh@linux.ibm.com>
Subject: [PATCH] ext4: Unregister sysfs path before destroying jbd2 journal
Patch-mainline: v5.7-rc1
Git-commit: 5e47868fb94b63c7068dcfd2469d99fba06bae9d
References: bsc#1167338 bsc#1167288
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>
Acked-by: Jan Kara <jack@suse.cz>
---
fs/ext4/super.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -982,6 +982,13 @@ static void ext4_put_super(struct super_
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);
@@ -990,7 +997,6 @@ static void ext4_put_super(struct super_
ext4_abort(sb, "Couldn't clean up the journal");
}
- ext4_unregister_sysfs(sb);
ext4_es_unregister_shrinker(sbi);
del_timer_sync(&sbi->s_err_report);
ext4_release_system_zone(sb);