Re: [PATCH] ntfs: fix lost volume flag updates in set/clear helpers

From: Namjae Jeon

Date: Tue Sep 01 2026 - 21:07:19 EST


On Tue, Sep 1, 2026 at 11:46 AM Hongling Zeng <zenghongling@xxxxxxxxxx> wrote:
>
> ntfs_set_volume_flags() and ntfs_clear_volume_flags() both read
> vol->vol_flags outside any lock to compute the new value before handing
> it to ntfs_write_volume_flags(), which only takes ni->mrec_lock around
> the actual write. The read-modify-write is therefore not atomic, and two
> concurrent callers can lose an update: ntfs_sync_fs() may derive a
> "clean" value from vol->vol_flags while a writer concurrently records an
> error and sets VOLUME_IS_DIRTY; the locked write then silently
> overwrites the freshly-set dirty bit. The on-disk volume looks clean
> despite the recorded errors, so chkdsk will not run on the next mount
> and corrupted metadata can persist.
This patch description explicitly identifies ntfs_sync_fs() as the
problematic caller, but there still remains a racy issue after
applying this patch.

static int ntfs_sync_fs(struct super_block *sb, int wait)
{
...
if (!NVolErrors(vol) &&
ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) {
ntfs_warning(sb, "Failed to clear dirty bit in volume
information flags. Run chkdsk.");
err = -EIO;
}

Sync thread Writer thread
----------- -------------
1. NVolErrors() == false
2. Set VOLUME_IS_DIRTY
under mrec_lock
3. NVolSetErrors()
4. ntfs_clear_volume_flags()

The volume can be left marked clean on disk despite the recorded
error... Can you update this patch to fix this issue as well?