[PATCH v2 2/3] fs/ntfs3: reject a first attribute segment that does not start at vcn 0
From: Ernest Borowski via B4 Relay
Date: Sat Dec 05 2026 - 13:27:28 EST
From: Ernest Borowski <ernest.borowski.git@xxxxxxxxx>
ntfs_read_mft() takes the segment that the attribute list names at vcn 0
for the first segment of an attribute, and the attribute of the base
record when there is no attribute list. ni_find_attr() does the same
when there is no attribute list. None of them checks that the segment
itself starts at vcn 0. A crafted record whose first $DATA segment
starts at a later vcn is therefore used as the start of the attribute:
its runlist is unpacked from that vcn on, and fields that only a first
segment has, such as the compressed size of a compressed attribute
(attr_ondisk_size()), are read from a header that may not have room for
them.
On a valid volume the first segment starts at vcn 0. Reject one that
does not when the inode is read, as ntfs_read_mft() does for other
malformed attributes.
The next patch accepts a nonzero compression unit in later segments,
which so far kept such a crafted segment off the compressed read and
write paths when there is no attribute list.
Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ernest Borowski <ernest.borowski.git@xxxxxxxxx>
---
fs/ntfs3/inode.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index c31423c4e0c..ba96a32b29b 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -147,6 +147,16 @@ static int ntfs_read_mft(struct inode *inode, const struct cpu_str *name,
goto attr_unpack_run;
}
+ /*
+ * This is the first segment of the attribute: its attribute list
+ * entry says vcn 0, or there is no attribute list and it is the only
+ * one. Its header must start at vcn 0 too, or fields that only a
+ * first segment has, such as the compressed size, are read from a
+ * later segment that may not have room for them.
+ */
+ if (attr->non_res && attr->nres.svcn)
+ goto out;
+
roff = attr->non_res ? 0 : le16_to_cpu(attr->res.data_off);
rsize = attr->non_res ? 0 : le32_to_cpu(attr->res.data_size);
asize = le32_to_cpu(attr->size);
--
2.56.1