Skip to contentSkip to conversation

fs/ntfs3: Fix NULL dereference in ntfs_update_mftmirr

PATCH New Konstantin Komarov 1 participant 1 message Nov 30, 2021

Subsystems (2)
lore
Share & tools
lore

Konstantin Komarov

author maintainer
#0 lore raw

PATCH 1/1 fs/ntfs3: Fix NULL dereference in ntfs_update_mftmirr

We can get NULL pointer to struct super_block.
This commit adds check for such situation.

Fixes 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")

Thread: https://lore.kernel.org/lkml/20211125140816.GC3109@xsang-OptiPlex-9020/

---
 fs/ntfs3/fsntfs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/ntfs3/fsntfs.c +6 -3
index 4de9acb16968..38de8cb53183 100644
@@ -831,14 +831,17 @@ int ntfs_update_mftmirr(struct ntfs_sb_info *sbi, int wait)
 {
 	int err;
 	struct super_block *sb = sbi->sb;
-	u32 blocksize = sb->s_blocksize;
+	u32 blocksize, bytes;
 	sector_t block1, block2;
-	u32 bytes;
 
-	if (!(sbi->flags & NTFS_FLAGS_MFTMIRR))
+	/*
+	 * sb can be NULL here. In this case sbi->flags should be 0 too.
+	 */
+	if (!sb || !(sbi->flags & NTFS_FLAGS_MFTMIRR))
 		return 0;
 
 	err = 0;
+	blocksize = sb->s_blocksize;
 	bytes = sbi->mft.recs_mirr << sbi->record_bits;
 	block1 = sbi->mft.lbo >> sb->s_blocksize_bits;
 	block2 = sbi->mft.lbo2 >> sb->s_blocksize_bits;
Signature · 1 line
2.33.1