fat: validate VFAT dotdot buffers before dirtying
syzbot
syzbotDuring directory rename operations with synchronous directory updates enabled, vfat_update_dotdot_de() writes the ".." directory entry via sync_dirty_buffer(). If this write fails due to an I/O error, the block layer clears the BH_Uptodate flag. When rename enters its error rollback path, it calls vfat_update_dotdot_de() again with the same buffer head, which calls mmb_mark_buffer_dirty() and triggers a "!buffer_uptodate(bh)" warning in mark_buffer_dirty().
Fix this by locking the buffer head in vfat_update_dotdot_de() and checking buffer_uptodate() before modifying the entry. If the buffer is not uptodate, unlock it and return -EIO, preventing mmb_mark_buffer_dirty() from being called on a non-uptodate buffer.
To: "OGAWA Hirofumi" <[email protected]>
To: <[email protected]>
To: "Linus Torvalds" <[email protected]>
---
v2:
- Lock the buffer head and return -EIO if it is not uptodate instead of calling set_buffer_uptodate().
- Update the patch subject to reflect buffer validation.
- Shorten the commit description and remove the stack trace.
v1:
https://lore.kernel.org/all/[email protected]/T/
---
fs/fat/namei_vfat.c +6 -0
@@ -913,8 +913,14 @@ static int vfat_update_dotdot_de(struct inode *dir, struct inode *inode,struct buffer_head *dotdot_bh, struct msdos_dir_entry *dotdot_de) { +lock_buffer (dotdot_bh ); +if (!buffer_uptodate (dotdot_bh)) { +unlock_buffer (dotdot_bh); +return -EIO ; + }fat_set_start (dotdot_de,MSDOS_I (dir)->i_logstart);mmb_mark_buffer_dirty (dotdot_bh, &MSDOS_I (inode)->i_metadata_bhs); +unlock_buffer (dotdot_bh);if (IS_DIRSYNC (dir))return sync_dirty_buffer (dotdot_bh);return 0 ;
base-commit: 93f51579e7df248780214094418f205253383cc5
Signature · 9 lines
This is an AI-generated patch subject to moderation.
Reply with '#syz upstream' to Sign-off the patch as a human author
and send it to the upstream kernel mailing lists.
Reply with '#syz reject' to reject it ('#syz unreject' to undo).
See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
You can comment on the patch as usual, syzbot will try to address
the comments and send a new version of the patch if necessary.
syzbot engineers can be reached at [email protected].Quoted 52 lines · syzbot
During directory rename operations with synchronous directory updates enabled,
vfat_update_dotdot_de()writes the ".." directory entry viasync_dirty_buffer(). If this write fails due to an I/O error, the block layer clears theBH_Uptodateflag. When rename enters its error rollback path, it callsvfat_update_dotdot_de()again with the same buffer head, which callsmmb_mark_buffer_dirty()and triggers a "!buffer_uptodate(bh)" warning inmark_buffer_dirty().Fix this by locking the buffer head in
vfat_update_dotdot_de()and checkingbuffer_uptodate()before modifying the entry. If the buffer is not uptodate, unlock it and return-EIO, preventingmmb_mark_buffer_dirty()from being called on a non-uptodate buffer.Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Assisted-by Gemini:gemini-3.8-flash syzbotReported-by [email protected]To: "OGAWA Hirofumi" <[email protected]>
To: <[email protected]>
To: "Linus Torvalds" <[email protected]>---
v2:
- Lock the buffer head and return-EIOif it is not uptodate instead of callingset_buffer_uptodate().
- Update the patch subject to reflect buffer validation.
- Shorten the commit description and remove the stack trace.v1:
https://lore.kernel.org/all/[email protected]/T/
---fs/fat/namei_vfat.c +6
-0@@ -913,8 +913,14 @@ static int vfat_update_dotdot_de(struct inode *dir, struct inode *inode,struct buffer_head *dotdot_bh, struct msdos_dir_entry *dotdot_de) { +lock_buffer (dotdot_bh ); +if (!buffer_uptodate (dotdot_bh)) { +unlock_buffer (dotdot_bh); +return -EIO ; + }fat_set_start (dotdot_de,MSDOS_I (dir)->i_logstart);mmb_mark_buffer_dirty (dotdot_bh, &MSDOS_I (inode)->i_metadata_bhs); +unlock_buffer (dotdot_bh);if (IS_DIRSYNC (dir))return sync_dirty_buffer (dotdot_bh);return 0 ;
Quoted 1 line
base-commit:
93f51579e7df248780214094418f205253383cc5
Please extend the BH_Uptodate guard to MSDOS cross-directory rename and its rollback. A failed synchronous write of the .. entry clears BH_Uptodate. do_msdos_rename() then changes and dirties the same retained buffer during rollback, so mark_buffer_dirty() can still warn. The current VFAT-only change leaves that sibling path exposed.
Put the locked state check, parent-cluster update, and dirty mark in one shared FAT .. update operation used by VFAT and MSDOS. Return -EIO before modifying a non-uptodate buffer. Keep the buffer lock through the dirty mark and release it before sync_dirty_buffer(). Preserve the current VFAT check, each caller's existing synchronous-write choice, rename cleanup, original error precedence, and filesystem-corruption reporting.
Update the subject and short commit description to cover both VFAT and MSDOS. Keep the supported Fixes: tag and existing syzbot provenance and report tags. No other behavior change is requested.