[PATCH v3] fs/ntfs: fix BUG_ON of ntfs_read_block()

xu xin posted 1 patch 3 years, 9 months ago
fs/ntfs/aops.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
[PATCH v3] fs/ntfs: fix BUG_ON of ntfs_read_block()
Posted by xu xin 3 years, 9 months ago
As the bug description at
https://lore.kernel.org/lkml/20220623033635.973929-1-xu.xin16@zte.com.cn/
attckers can use this bug to crash the system.

So to avoid panic, remove the BUG_ON, and use ntfs_warning to output a
warning to the syslog and return ERR.

Cc: stable@vger.kernel.org
Cc: Songyi Zhang <zhang.songyi@zte.com.cn>
Cc: Yang Yang <yang.yang29@zte.com.cn>
Cc: Jiang Xuexin<jiang.xuexin@zte.com.cn>
Cc: Zhang wenya<zhang.wenya1@zte.com.cn>
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---

Changelog for v3:
- Use IS_ERR_OR_NULL to check runlist.rl in ntfs_read_block
- Modify ntfs error log.

Changelog for v2:
- Use ntfs_warning instead of WARN().
- Add the tag Cc: stable@vger.kernel.org.

---
 fs/ntfs/aops.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c
index 5f4fb6ca6f2e..b9421552686a 100644
--- a/fs/ntfs/aops.c
+++ b/fs/ntfs/aops.c
@@ -183,7 +183,14 @@ static int ntfs_read_block(struct page *page)
 	vol = ni->vol;
 
 	/* $MFT/$DATA must have its complete runlist in memory at all times. */
-	BUG_ON(!ni->runlist.rl && !ni->mft_no && !NInoAttr(ni));
+	if (IS_ERR_OR_NULL(ni->runlist.rl) && !ni->mft_no && !NInoAttr(ni)) {
+		ntfs_error(vol->sb, "Runlist of $MFT/$DATA is not cached. "
+				    "$MFT is corrupt.");
+		unlock_page(page);
+		if (IS_ERR(ni->runlist.rl))
+			return PTR_ERR(ni->runlist.rl);
+		return -EFAULT;
+	}
 
 	blocksize = vol->sb->s_blocksize;
 	blocksize_bits = vol->sb->s_blocksize_bits;
-- 
2.25.1