Re: [PATCH v5] fat: make rename recovery safe after metadata write errors
From: OGAWA Hirofumi
Date: Fri Nov 20 2026 - 07:36:32 EST
Krystian Kaniewski <krystianmkaniewski@xxxxxxxxx> writes:
> On 11/8/26 15:04, OGAWA Hirofumi wrote:
>>>
>>> fs/fat/namei_msdos.c | 18 ++++++++++++----
>>> fs/fat/namei_vfat.c | 50 +++++++++++++++++++++++++++++++-------------
>>> 2 files changed, 49 insertions(+), 19 deletions(-)
>>>
>>> diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c
>>> index d46d1a3851f25f..51d49a3ca93c14 100644
>>> --- a/fs/fat/namei_msdos.c
>>> +++ b/fs/fat/namei_msdos.c
>>> @@ -562,14 +562,20 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
>>> return err;
>>>
>>> error_dotdot:
>>> - /* data cluster is shared, serious corruption */
>>> + /*
>>> + * Complete the remaining rollback. Report corruption only if a
>>> + * recovery step cannot be completed.
>>> + */
>>> corrupt = 1;
>>>
>>> - if (update_dotdot) {
>>> + /* A failed sync write clears BH_Uptodate, leave that buffer alone. */
>>> + if (update_dotdot && buffer_uptodate(dotdot_bh)) {
>>> fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
>>> mmb_mark_buffer_dirty(dotdot_bh,
>>> &MSDOS_I(old_inode)->i_metadata_bhs);
>>> corrupt |= sync_dirty_buffer(dotdot_bh);
>>> + } else if (update_dotdot) {
>>> + corrupt = err;
>>> }
>>> error_inode:
>>> fat_detach(old_inode);
>>> @@ -577,11 +583,13 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
>>> MSDOS_I(old_inode)->i_attrs = old_attrs;
>>> if (new_inode) {
>>> fat_attach(new_inode, new_i_pos);
>>> - if (corrupt) {
>>> + if (corrupt && buffer_uptodate(sinfo.bh)) {
>>
>> This check is ok with sinfo.bh?
>>
>
> Yes. For an existing destination, msdos_lookup() reaches fat_scan()
> through msdos_find(), while do_msdos_rename() calls fat_scan() with
> the same normalized 8.3 name. Both identify the same directory entry,
> so sinfo.i_pos equals new_i_pos and sinfo.bh is the buffer containing
> that entry.
>
>>
>> I guess this check is needed for msdos too? If so, maybe we want the
>> helper function in fat module.
>>
>> Thanks.
>
> I agree that a common FAT helper would be the right shape if this check
> were still needed. I prepared that version, but before sending v6 I
> noticed that the buffer write-error contract changed in v7.4-rc1.
>
> Commit 9f08e58149dc ("buffer: stop touching BH_Uptodate on write
> completion") no longer clears BH_Uptodate after a failed write. The
> failure is recorded in BH_Write_EIO instead. The same series changed
> fat_sync_bhs() in 8417ab622ffc ("fat: check for a metadata write error
> with buffer_write_io_error()"). The 9f08e58149dc commit message calls
> out the mark_buffer_dirty() warning from this report as the reason for
> the series.
>
> I reran the original C and syz reproducers and targeted metadata write
> faults on current mainline without a FAT patch. The writes still failed,
> but the !buffer_uptodate warning did not occur.
>
> This also means that changing the v5 checks mechanically to
> buffer_write_io_error() would not be correct. The new buffer semantics
> deliberately preserve the in-memory data so that a failed write can be
> retried. In particular, suppressing the second dotdot rollback in
> vfat_rename_exchange() would now remove valid recovery.
>
> My current conclusion is that I should not send a FAT v6 for mainline.
> Would you agree that 9f08e58149dc should be reported to syzbot as the
> fix and that this FAT series should be dropped?
>
> Older kernels that do not contain these buffer changes may still hit
> the warning. Since the warning is now addressed in the buffer layer,
> backporting the relevant v7.4 buffer changes may be preferable to
> adding a separate FAT recovery change.
OK. If there is no WARN_ON() anymore, it sounds good.
Thanks.
--
OGAWA Hirofumi <hirofumi@xxxxxxxxxxxxxxxxxx>