[PATCH v2 0/3] fs/ntfs3: accept later attribute segments written by ntfs-3g and ntfs
From: Ernest Borowski via B4 Relay
Date: Sat Dec 05 2026 - 13:27:26 EST
mi_enum_attr() checks every attribute segment on its own, but two of its
checks assume that a later segment (svcn != 0) carries the same flags and
compression unit as the first one, or none at all. Files written by
ntfs-3g and by the ntfs driver do not always match that, and ntfs3 marks
them bad although ntfs-3g, ntfs and ntfsck read and check them fine:
- a sparse file whose later segments were created before it became
sparse keeps those segments flagged as normal, and their vcns may lie
past the end of the volume (patch 1, a regression in v7.3);
- ntfs-3g stores the compression unit in every segment of a compressed
file (patch 3).
Patch 2 closes a hole that patch 3 would otherwise open: ntfs3 never
checks that the segment it takes for the first one starts at vcn 0. In
a record without an attribute list, a crafted $DATA segment that starts
at a later vcn is used as the start of the attribute. A nonzero
compression unit kept such a segment off the compressed paths so far.
The two cases above are reproduced on a fragmented 64 MiB volume with
512-byte clusters in QEMU. With the series applied, ntfs3 reads all test
files with the expected contents, the sanitizers stay quiet and the
remaining checks still bound every segment. For patch 2, ntfs-3g writes
a plain and a compressed file, and their $DATA segment is then moved to
start at vcn 16. Without the series ntfs3 loads the plain file, with v1
it loads both, and with v2 it refuses both.
Zhan Xusheng's "fs/ntfs3: accept $Bad covering the last partial
cluster" [1] relaxes the same evcn check for the first segment of
$BadClus:$Bad. The two accept different cases, but they edit the same
comment and lines, so whichever is applied second needs a small manual
merge.
Joas Antonio dos Santos's "ntfs3: reject on-disk c_unit values that
cause shift overflow" [2] adds a bound on c_unit two lines above the
check that patch 2 changes. The two do not conflict in meaning, but the
one applied second needs its context adjusted.
The series is based on the master branch of the ntfs3 tree,
https://github.com/Paragon-Software-Group/linux-ntfs3.git (6ad211033e3e).
[1] https://lore.kernel.org/all/20261119070319.3803611-1-zhanxusheng1024@xxxxxxxxx/
[2] https://lore.kernel.org/all/20261108-ntfs3-cunit-fix-v1-1-fb8d02b3f8a2@xxxxxxxxx/
---
Changes in v2:
- Patch 1 bounds the end vcn of a later segment by sb->s_maxbytes
instead of sbi->maxbytes_sparse, which is 16 clusters short of the
largest file with 32-bit cluster numbers.
- New patch 2: reject a first segment that does not start at vcn 0. v1
let a crafted compressed segment through in a record without an
attribute list.
- Patch 3 (patch 2 in v1): commit message says why patch 2 makes the
relaxed check safe.
- Link to v1: https://patch.msgid.link/20261204-b4-ntfs3-extent-checks-v1-0-646a5fb09b0f@xxxxxxxxx
---
Ernest Borowski (3):
fs/ntfs3: do not bound the vcns of later attribute segments by the volume
fs/ntfs3: reject a first attribute segment that does not start at vcn 0
fs/ntfs3: do not require compression unit 0 in later attribute segments
fs/ntfs3/inode.c | 10 ++++++++++
fs/ntfs3/record.c | 27 +++++++++++++++++++++++----
2 files changed, 33 insertions(+), 4 deletions(-)
---
base-commit: 6ad211033e3e31dbbc8c6c1b8a0949adc7ddf2e9
change-id: 20261121-b4-ntfs3-extent-checks-c2825b793a6b
Best regards,
--
Ernest Borowski <ernest.borowski.git@xxxxxxxxx>