ntfs: stop MFT writeback at allocated boundary
PATCH 1/1 ntfs: stop MFT writeback at allocated boundary
ntfs_write_mft_block() tests vcn in the loop condition before recalculating it for the current MFT record.
When a folio straddles the end of the allocated MFT, the stale vcn from the previous record admits one more iteration. The recalculated vcn can then equal end_vcn. Runlist lookup fails and the volume is marked erroneous.
This was reproduced on arm64 with 16 KiB pages, 4 KiB clusters and 1 KiB MFT records. With allocated_size 0x13000, writeback of folio index 0x4 attempted to map VCN 0x13. Creating an empty file left the volume dirty and the next mount was read-only. A mount and unmount without the file creation remained clean.
Calculate vcn for the current record first and stop at the allocated boundary. The patched driver passed file creation and deletion, a 64 MiB fio write/read verification with crc32c, sync, unmount and read-write remount.
--- fs/ntfs/mft.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ntfs/mft.c +3 -1
@@ -2681,12 +2681,14 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w/* Clear the page uptodate flag whilst the mst fixups are applied. */ folio_clear_uptodate (folio); -for (mft_ofs =0 ; mft_ofs <PAGE_SIZE && vcn < end_vcn; +for (mft_ofs =0 ; mft_ofs <PAGE_SIZE ; mft_ofs += vol->mft_record_size) {/* Get the mft record number. */ mft_no = (((s64 )folio->index <<PAGE_SHIFT ) + mft_ofs) >> vol->mft_record_size_bits; vcn =ntfs_mft_no_to_cluster (vol, mft_no); +if (vcn >= end_vcn) +break ;/* Check whether to write this mft record. */ tni =NULL ; if (ntfs_may_write_mft_record(vol, mft_no,
Signature · 1 line
2.47.3
Quoted 34 lines · Marek Wesołowski
ntfs_write_mft_block()tests vcn in the loop condition before recalculating it for the current MFT record.When a folio straddles the end of the allocated MFT, the stale vcn from the previous record admits one more iteration. The recalculated vcn can then equal
end_vcn. Runlist lookup fails and the volume is marked erroneous.This was reproduced on arm64 with 16 KiB pages, 4 KiB clusters and 1 KiB MFT records. With
allocated_size0x13000, writeback of folio index0x4attempted to map VCN0x13. Creating an empty file left the volume dirty and the next mount was read-only. A mount and unmount without the file creation remained clean.Calculate vcn for the current record first and stop at the allocated boundary. The patched driver passed file creation and deletion, a 64 MiB fio write/read verification with crc32c, sync, unmount and read-write remount.
Fixes 115380f9a2f9 ("ntfs: update mft operations")Signed-off-by Marek Wesołowski <[email protected]>--- fs/ntfs/mft.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/ntfs/mft.c +1
-1@@ -2681,12 +2681,14 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w/* Clear the page uptodate flag whilst the mst fixups are applied. */ folio_clear_uptodate (folio); - for (mft_ofs = 0; mft_ofs < PAGE_SIZE && vcn < end_vcn; + for (mft_ofs = 0; mft_ofs < PAGE_SIZE;
fs/ntfs/mft.c static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w · line 2694
Quoted 10 lines
fs/ntfs/mft.c +2
-0mft_ofs += vol->mft_record_size) {/* Get the mft record number. */ mft_no = (((s64 )folio->index <<PAGE_SHIFT ) + mft_ofs) >> vol->mft_record_size_bits; vcn =ntfs_mft_no_to_cluster (vol, mft_no); +if (vcn >= end_vcn) +break ;/* Check whether to write this mft record. */ tni =NULL ; if (ntfs_may_write_mft_record(vol, mft_no,
Looks good to me.
Namjae Jeon
maintainerQuoted 14 lines · Marek Wesołowski
ntfs_write_mft_block()tests vcn in the loop condition before recalculating it for the current MFT record.When a folio straddles the end of the allocated MFT, the stale vcn from the previous record admits one more iteration. The recalculated vcn can then equal
end_vcn. Runlist lookup fails and the volume is marked erroneous.This was reproduced on arm64 with 16 KiB pages, 4 KiB clusters and 1 KiB MFT records. With
allocated_size0x13000, writeback of folio index0x4attempted to map VCN0x13. Creating an empty file left the volume dirty and the next mount was read-only. A mount and unmount without the file creation remained clean.
Quoted 7 lines
Calculate vcn for the current record first and stop at the allocated boundary. The patched driver passed file creation and deletion, a 64 MiB fio write/read verification with crc32c, sync, unmount and read-write remount.
Fixes 115380f9a2f9 ("ntfs: update mft operations")Signed-off-by Marek Wesołowski <[email protected]>
I can not apply this patch to the latest #ntfs-next branch. Could you please check if this patch is no longer necessary in #ntfs-next branch?
https://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/ntfs.git ntfs-next
Thanks.
Quoted 23 lines · Namjae Jeon
Quoted 14 lines · Marek Wesołowski
ntfs_write_mft_block()tests vcn in the loop condition before recalculating it for the current MFT record.When a folio straddles the end of the allocated MFT, the stale vcn from the previous record admits one more iteration. The recalculated vcn can then equal
end_vcn. Runlist lookup fails and the volume is marked erroneous.This was reproduced on arm64 with 16 KiB pages, 4 KiB clusters and 1 KiB MFT records. With
allocated_size0x13000, writeback of folio index0x4attempted to map VCN0x13. Creating an empty file left the volume dirty and the next mount was read-only. A mount and unmount without the file creation remained clean.Quoted 7 lines
Calculate vcn for the current record first and stop at the allocated boundary. The patched driver passed file creation and deletion, a 64 MiB fio write/read verification with crc32c, sync, unmount and read-write remount.
Fixes 115380f9a2f9 ("ntfs: update mft operations")Signed-off-by Marek Wesołowski <[email protected]>
Quoted 7 lines
I can not apply this patch to the latest #ntfs-next branch. Could you please check if this patch is no longer necessary in #ntfs-next branch?
https://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/ntfs.git ntfs-next
Thanks.
Hi Namjae, Marek,
Sorry, when reviewing this patch earlier, I did not check whether the
issue had already been addressed in the latest ntfs-next.
I have now checked, and e543dc6c5f1e ("ntfs: write MFT folios through
mapped I/O units") eliminates the problematic loop.
That commit checks the current record's byte offset againstmin(i_size, allocated_size) before selecting it for writeback. The I/O preparation loop also stops at that limit before mapping the next unit. For the reported allocation boundary of 0x13000, this prevents the lookup of VCN 0x13 that caused the error.
I therefore think this patch should no longer be needed on the
current ntfs-next.
Marek, could you please double-check this?
I'll make sure to check the latest ntfs-next when reviewing patches
in the future.
Thanks,
Baolin.
Namjae Jeon
maintainerQuoted 43 lines · liubaolin
Quoted 23 lines · Namjae Jeon
Quoted 14 lines · Marek Wesołowski
ntfs_write_mft_block()tests vcn in the loop condition before recalculating it for the current MFT record.When a folio straddles the end of the allocated MFT, the stale vcn from the previous record admits one more iteration. The recalculated vcn can then equal
end_vcn. Runlist lookup fails and the volume is marked erroneous.This was reproduced on arm64 with 16 KiB pages, 4 KiB clusters and 1 KiB MFT records. With
allocated_size0x13000, writeback of folio index0x4attempted to map VCN0x13. Creating an empty file left the volume dirty and the next mount was read-only. A mount and unmount without the file creation remained clean.Quoted 7 lines
Calculate vcn for the current record first and stop at the allocated boundary. The patched driver passed file creation and deletion, a 64 MiB fio write/read verification with crc32c, sync, unmount and read-write remount.
Fixes 115380f9a2f9 ("ntfs: update mft operations")Signed-off-by Marek Wesołowski <[email protected]>Quoted 7 lines
I can not apply this patch to the latest #ntfs-next branch. Could you please check if this patch is no longer necessary in #ntfs-next branch?
https://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/ntfs.git ntfs-next
Thanks.
Hi Namjae, Marek,
Sorry, when reviewing this patch earlier, I did not check whether the
issue had already been addressed in the latest ntfs-next.I have now checked, and
e543dc6c5f1e("ntfs: write MFT folios through
mapped I/O units") eliminates the problematic loop.
Quoted 8 lines
That commit checks the current record's byte offset against
min(i_size, allocated_size)before selecting it for writeback. The I/O preparation loop also stops at that limit before mapping the next unit. For the reported allocation boundary of0x13000, this prevents the lookup of VCN0x13that caused the error.I therefore think this patch should no longer be needed on the
current ntfs-next.
Thanks for checking it:)
Quoted 4 lines
Marek, could you please double-check this?
I'll make sure to check the latest ntfs-next when reviewing patches
in the future.
Okay.