fs/ntfs3: Fix memory leak in ntfs_fill_super()

Message ID 20230916175852.1607269-1-syoshida@redhat.com
State New
Headers
Series fs/ntfs3: Fix memory leak in ntfs_fill_super() |

Commit Message

Shigeru Yoshida Sept. 16, 2023, 5:58 p.m. UTC
  syzbot reported memory leak in ntfs_fill_super(). ntfs_fill_super() calls
wnd_init() and this allocates memory. So, we need to free those memory on the
error handling path in ntfs_fill_super().

Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Reported-and-tested-by: syzbot+9ccdd15480e9d9833822@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9ccdd15480e9d9833822
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
---
 fs/ntfs3/super.c | 7 +++++++
 1 file changed, 7 insertions(+)
  

Patch

diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index cfec5e0c7f66..a9610f5f4cc0 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -1563,6 +1563,13 @@  static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	iput(inode);
 out:
 	kfree(boot2);
+
+	if (sbi->mft.bitmap.inited)
+		wnd_close(&sbi->mft.bitmap);
+
+	if (sbi->used.bitmap.inited)
+		wnd_close(&sbi->used.bitmap);
+
 	return err;
 }