Re: [PATCH] exfat: clean stale bdev buffers of newly allocated clusters

From: Namjae Jeon

Date: Sun Oct 11 2026 - 18:21:45 EST


On Sun, Oct 11, 2026 at 4:15 AM Nicolas Falesy
<nicolas@xxxxxxxxxxxxxxxxx> wrote:
>
> Directory entries are read and written through buffer_heads of the
> block device. Removing the entries of a directory dirties such a
> buffer. If the directory is then removed and its cluster is reused for
> file data before writeback, the stale buffer stays dirty in the block
> device mapping, and the next flush of the block device (fsync, syncfs
> or umount) writes it over the new file data. The file silently reads
> back with one sector replaced by the deleted directory entries.
>
> This was harmless while file data went through exfat_get_block(), as
> __block_write_begin_int() and do_direct_IO() call clean_bdev_aliases()
> for newly allocated blocks. Since data I/O moved to iomap, nothing
> drops these buffers any more.
>
> Clean the aliases in exfat_alloc_cluster(), once per contiguous run of
> allocated clusters. Doing it at allocation time covers every path that
> allocates clusters: buffered and direct writes, and also fallocate()
> and an extending truncate(), which allocate clusters before the data is
> written, so the later iomap mapping does not see them as new.
>
> Tested on the exfat dev branch in a KVM guest with a reproducer that
> removes the entries of a directory, removes the directory and writes a
> file over its freed cluster: buffered with and without fsync, O_DIRECT,
> after fallocate(), after an extending ftruncate(), and with the freed
> cluster in the middle of a fragmented allocation. Without this patch
> every run corrupted the file (55/55); with it, none did (0/55). A churn
> test that creates, removes, preallocates and truncates directories and
> files, then runs fsck.exfat, is clean with and without the patch.
>
> Fixes: 82a81a7352bc ("exfat: add iomap buffered I/O support")
> Fixes: 867b9c96dc83 ("exfat: add iomap direct I/O support")
> Link: https://lore.kernel.org/all/010001a1222f66ba-0c745f29-d4fe-4862-93ff-1db2055b05fc-000000@xxxxxxxxxxxxxxxxxxx/
> Suggested-by: Namjae Jeon <linkinjeon@xxxxxxxxxx>
> Assisted-by: Claude-Opus-5.5
> Signed-off-by: Nicolas Falesy <nicolas@xxxxxxxxxxxxxxxxx>
Applied it to #dev.
Thanks!