[PATCH v2 0/6] ntfs: synchronize the in-memory size handling
From: Hongling Zeng
Date: Sun Nov 29 2026 - 20:17:00 EST
The in-memory size fields of an ntfs inode - data_size,
initialized_size, allocated_size and the compressed size - are
meant to be protected by size_lock, but the iomap readers and the
runtime writers reach them without the lock in several paths, and
the mmap write fault path extends initialized_size without the MFT
record lock every other caller of ntfs_attr_set_initialized_size()
holds.
The first two patches fix bugs found while auditing those paths: a
resident write whose data can land in an extent record that is
never marked dirty, and a failed write that leaves the attribute
extended. The remaining four close the races: the iomap paths
take a coherent snapshot of initialized_size, the writers publish
the sizes under size_lock, the fault path is serialized with the
MFT record lock, and the mmap prepare path reads initialized_size
under the size lock.
Compile-tested on x86_64.
Changes in v2:
- 0002: a non-resident attribute rollback would have to truncate the
page cache beyond the old EOF under mrec_lock, which can deadlock
with writeback. Defer the rollback to ntfs_inode_attr_pwrite(),
which releases mrec_lock first and then follows ntfs_setattr_size():
truncate_setsize() outside the lock, __ntfs_attr_truncate_vfs()
under it.
- 0003: reuse the initialized_size snapshot taken for the unwritten
mapping decision in the length adjustment of
ntfs_read_iomap_begin_non_resident() instead of taking a second
snapshot, so the type and the length of a mapped extent cannot be
decided against different boundaries. Also take the
size_lock in ntfs_iomap_read_end_io(), whose unlocked
initialized_size read in the bio completion path can tear on 32-bit
builds (Hyunchul Lee).
- 0004: hold size_lock across the index root size updates in
ntfs_ir_reparent() so the reparent path publishes the sizes under
the lock like the other resident resize paths.
Hongling Zeng (6):
ntfs: mark the record dirtied by a resident write at iomap begin
ntfs: roll back the size update when the attribute lookup fails
ntfs: read initialized_size under size_lock in the iomap paths
ntfs: update the in-memory sizes under the size lock
ntfs: serialize the mmap write fault initialized size update
ntfs: read initialized_size under size_lock in the mmap prepare path
fs/ntfs/aops.c | 3 +
fs/ntfs/attrib.c | 49 ++++++++++++--
fs/ntfs/file.c | 11 +++-
fs/ntfs/index.c | 5 ++
fs/ntfs/inode.c | 163 +++++++++++++++++++++++++++++++++++++++++++----
fs/ntfs/iomap.c | 63 ++++++++++++++----
6 files changed, 264 insertions(+), 30 deletions(-)
--
2.25.1