Re: [PATCH v12] ntfs: trim the sizes after a short write
From: Namjae Jeon
Date: Tue Dec 01 2026 - 04:34:40 EST
On Fri, Nov 27, 2026 at 12:11 PM Zhan Xusheng <zhanxusheng1024@xxxxxxxxx> wrote:
>
> From: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
>
> ntfs_file_write_iter() moves the data size and, for a non-resident
> uncompressed file, the initialized size to pos + count before the copy.
> __ntfs_extend_initialized_size() only zeroes [old initialized size, pos),
> so the range [pos, pos + count) is initialized only by the copy itself.
> When iomap_file_buffered_write() copies less than count, it returns a
> positive short count and the error rollback at out: does not run. The
> file keeps the size pos + count, and [pos + ret, pos + count) reads back
> whatever the freed clusters held before, also after a remount. A local
> user can read the old contents of freed clusters this way.
>
> Run the existing rollback for a short write as well, and roll the data
> size back to the end of what was written, keeping the clusters that were
> allocated on disk before the write, such as space reserved with
> FALLOC_FL_KEEP_SIZE. Keep the initialized size, as a page fault through
> a shared mapping may rely on it while the write is stalled on its
> source, and zero what the write did not reach, up to the end of the
> block holding pos + count. Only if that fails, take the initialized
> size back to where the zeroing started, if it is above that. A writer
> killed during the copy also leaves a short write, but iomap_zero_range()
> then fails with -EINTR, so zero from a worker when a fatal signal is
> pending.
>
> An asynchronous direct write that fails after submitting bios returns
> -EIOCBQUEUED, and the rollback does not run for it either. Wait for a
> direct write that moves the initialized size, and fail a non-blocking
> one with -EAGAIN so that it is retried blocking, as ext4 does.
>
> Fixes: b041ca562526 ("ntfs: update iomap and address space operations")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Ernest Borowski <ernest.borowski.git@xxxxxxxxx>
> Signed-off-by: Ernest Borowski <ernest.borowski.git@xxxxxxxxx>
> Signed-off-by: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
Applied it to #ntfs-next.
Thanks!