Skip to contentSkip to conversation

fs/ntfs3: Fix error handling in ntfs_new_inode()

PATCH In review Shigeru Yoshida 2 participants 3 messages Jan 4, 2023 – Jan 16, 2023 NTFS3 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/ntfs3: Fix error handling in ntfs_new_inode()

When memory allocation for mi->mrec fails, ntfs_new_inode() calls iput(). iput() calls ni_write_inode() indirectly, it references uninitialized mi->mrec, and this causes the kernel crash. This patch fixes the issue by making the inode bad before calling iput().

---
 fs/ntfs3/fsntfs.c | 1 +
 1 file changed, 1 insertion(+)
fs/ntfs3/fsntfs.c +1 -0
index 567563771bf8..7b93f2aeb6f6 100644
@@ -1683,6 +1683,7 @@ struct ntfs_inode *ntfs_new_inode(struct ntfs_sb_info *sbi, CLST rno, bool dir)
 
 out:
 	if (err) {
+		_ntfs_bad_inode(inode);
 		iput(inode);
 		ni = ERR_PTR(err);
 	}
Signature · 1 line
2.39.0
#1 lore raw
Quoted 15 lines · Shigeru Yoshida

When memory allocation for mi->mrec fails, ntfs_new_inode() calls iput(). iput() calls ni_write_inode() indirectly, it references uninitialized mi->mrec, and this causes the kernel crash. This patch fixes the issue by making the inode bad before calling iput().

---
  fs/ntfs3/fsntfs.c | 1 +
  1 file changed, 1 insertion(+)
fs/ntfs3/fsntfs.c +0 -0
index 567563771bf8..7b93f2aeb6f6 100644

fs/ntfs3/fsntfs.c struct ntfs_inode *ntfs_new_inode(struct ntfs_sb_info *sbi, CLST rno, bool dir) · line 1689

Quoted 7 lines
fs/ntfs3/fsntfs.c +1 -0
@@ -1683,6 +1683,7 @@ struct ntfs_inode *ntfs_new_inode(struct ntfs_sb_info *sbi, CLST rno, bool dir)
 
  out:
  	if (err) {
+		_ntfs_bad_inode(inode);
  		iput(inode);
  		ni = ERR_PTR(err);
  	}

Hello.

This bug have been already fixed by Ye Bin (https://lore.kernel.org/lkml/[email protected]/).

* Thanks for your work.

#2 lore raw

Hi,

Quoted 25 lines · Konstantin Komarov
Quoted 15 lines · Shigeru Yoshida

When memory allocation for mi->mrec fails, ntfs_new_inode() calls iput(). iput() calls ni_write_inode() indirectly, it references uninitialized mi->mrec, and this causes the kernel crash. This patch fixes the issue by making the inode bad before calling iput().

---
  fs/ntfs3/fsntfs.c | 1 +
  1 file changed, 1 insertion(+)
fs/ntfs3/fsntfs.c +0 -0
index 567563771bf8..7b93f2aeb6f6 100644

fs/ntfs3/fsntfs.c struct ntfs_inode *ntfs_new_inode(struct ntfs_sb_info *sbi, CLST rno, bool dir) · line 1688

Quoted 6 lines
fs/ntfs3/fsntfs.c +1 -0
@@ -1683,6 +1683,7 @@ struct ntfs_inode *ntfs_new_inode(struct ntfs_sb_info *sbi, CLST rno, bool dir)
  out:
  	if (err) {
+		_ntfs_bad_inode(inode);
  		iput(inode);
  		ni = ERR_PTR(err);
  	}

Hello.

Quoted 1 line

This bug have been already fixed by Ye Bin (https://lore.kernel.org/lkml/[email protected]/).

I've missed the fix you mentioned.
Thank you so much for your reply!

Shigeru

Quoted 3 lines

* Thanks for your work.