[PATCH] fs/ntfs3: check wnd_set_used() in ntfs_look_free_mft()

From: Baolin Liu

Date: Wed Aug 05 2026 - 03:36:25 EST


From: Baolin Liu <liubaolin@xxxxxxxxxx>

wnd_set_used() can fail, but ntfs_look_free_mft() ignored
the error and could return success after leaving the MFT
bitmap unmarked.

Check the return value and unwind the new subrecord on failure.

Signed-off-by: Baolin Liu <liubaolin@xxxxxxxxxx>
---
fs/ntfs3/fsntfs.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c
index d0434756029b..ab9e03156cce 100644
--- a/fs/ntfs3/fsntfs.c
+++ b/fs/ntfs3/fsntfs.c
@@ -741,10 +741,19 @@ int ntfs_look_free_mft(struct ntfs_sb_info *sbi, CLST *rno, bool mft,
}

/* We have found a record that are not reserved for next MFT. */
- if (*rno >= MFT_REC_FREE)
- wnd_set_used(wnd, *rno, 1);
- else if (*rno >= MFT_REC_RESERVED && sbi->mft.reserved_bitmap_inited)
+ if (*rno >= MFT_REC_FREE) {
+ err = wnd_set_used(wnd, *rno, 1);
+ if (err) {
+ if (ni) {
+ ni_remove_mi(ni, *mi);
+ mi_put(*mi);
+ *mi = NULL;
+ }
+ goto out;
+ }
+ } else if (*rno >= MFT_REC_RESERVED && sbi->mft.reserved_bitmap_inited) {
__set_bit(*rno - MFT_REC_RESERVED, &sbi->mft.reserved_bitmap);
+ }

out:
if (!mft)
--
2.51.0