ntfs3: attr_insert_range() shifts nres.evcn of a resident attribute past the end of the MFT record buffer
Subsystems (2)
Hi,
fallocate(FALLOC_FL_INSERT_RANGE) on a crafted NTFS image reaches a segment-enumeration loop in attr_insert_range() that shifts the svcn/evcn of every following DATA attribute without checking whether the enumerated attribute is non-resident. A resident attribute placed at the end of an extension MFT record makes le64_add_cpu(&nres.evcn, len) do an 8-byte read-modify-write past the end of the 1024-byte record buffer.
BUG: KASAN: slab-out-of-bounds in attr_insert_range+0x14a1/0x1670 [ntfs3] Read of size 8 at addr ffff8880062d9400 by task init/1 ... allocated 1024-byte region [ffff8880062d9000, ffff8880062d9400) The buggy address is located 0 bytes to the right
Reproduced 3/3. The negative control changes only that attribute's type from ATTR_DATA to ATTR_END; fallocate() then returns 0 with no KASAN report.
## This is the other branch of the function
bf9a6578e0 ("fs/ntfs3: fix slab-out-of-bounds write in attr_insert_range()", in 7.4) fixed the **resident** branch: the inline-data memmove used the insert length as both source offset and copy size. The current tree has that fix:
memmove(data + vbo + bytes, data + vbo, data_size - vbo);
The **non-resident** branch - the loop below it - is a separate path that still has no bound (fs/ntfs3/attrib.c):
next_svcn = le64_to_cpu(attr->nres.evcn) + 1;
while ((attr = ni_enum_attr_ex(ni, attr, &le, &mi)) &&
attr->type == ATTR_DATA && !attr->name_len) {
le64_add_cpu(&attr->nres.svcn, len);
le64_add_cpu(&attr->nres.evcn, len);
...
}The loop condition checks only the attribute type and name. The attributes come from ni_enum_attr_ex(), which walks the attribute list into extension MFT records, and does not imply any residency check. nres.evcn has no meaning for a resident attribute: in that layout the first four bytes at the same offset are res.data_size, and the 8-byte RMW reaches past the record buffer when the attribute is placed at its tail.
Both branches are reachable from the same fallocate() syscall; the resident one is fixed, this one is not. Current mainline (fs/ntfs3/attrib.c) still has the loop verbatim.
## Suggested fix
Reject resident attributes in the enumeration loop:
while ((attr = ni_enum_attr_ex(ni, attr, &le, &mi)) &&
attr->type == ATTR_DATA && !attr->name_len) {+ if (!attr->non_res) {
+ err = -EFSCORRUPTED;
+ goto out;
+ }
le64_add_cpu(&attr->nres.svcn, len);
le64_add_cpu(&attr->nres.evcn, len);Checking at the ni_enum_attr_ex() level would cover other callers with the same assumption, but the local check is the minimal fix for this path.
## Reproducer
The crafted image places a resident DATA attribute at the end of an extension MFT record so that the enumerated attribute is resident and tail-aligned. The image builder (mk_patch_record.py), positive and negative images, a trigger program and a syzkaller-format syz_mount_image$ntfs3 reproducer (image embedded as zlib+base64, followed by openat + fallocate) are in the test bundle.
Available on request.
Tested on 7.3.0 (KASAN, ntfs3 built-in). mainline 2026-11-15 checked.
Thanks,
Guikun Yang