[DragonFlyBSD - Bug #3461] msdosfs: uiomovebp() makes sibling clusters read as zeros when the cluster size is smaller than a page
sigttou
bugtracker-admin at leaf.dragonflybsd.org
Fri Nov 6 05:02:49 PST 2026
Issue #3461 has been updated by sigttou.
File 0001-kern-add-uiomove_nofault_user.patch added
File 0002-msdosfs-read-through-the-buffer-without-the-whole-pa.patch added
File 0004-ntfs-read-through-the-buffer-without-the-whole-page-.patch added
File 0003-msdosfs-stage-write-data-before-extending-the-file.patch added
Series of four patches that replaces the workaround attached above and
extends it to ntfs.
The fix-up in @uiomovebp()@ is the root cause: it marks unread sibling
clusters of the same file valid-with-zeros. ntfs reads through the
same call shape and corrupts the same way for cluster sizes below a
page, and with the fix-up merely removed a read whose target is an
mmap of the same file panics ("lockmgr: locking against myself")
because the user copy faults into the pager while the buffer is held.
This series replaces the attached patch: it changes the same two msdosfs
call sites, keeps the fast path bounce-free (the bounce only happens
when the user copy would fault), stages write data before the file size
is raised, and covers ntfs.
----------------------------------------
Bug #3461: msdosfs: uiomovebp() makes sibling clusters read as zeros when the cluster size is smaller than a page
http://bugs.dragonflybsd.org/issues/3461#change-14938
* Author: sigttou
* Status: New
* Priority: Normal
* Category: Driver
* Target version: 6.6
* Start date: 2026-11-04
----------------------------------------
@uiomovebp()@ (@sys/kern/kern_subr.c@) fixes up the last VM page of a buffer when it is not fully valid: @vm_page_zero_invalid(m, TRUE)@ zero-fills every invalid @DEV_BSIZE@ chunk and marks the whole page valid. With clusters smaller than a page (FAT16 with 512-byte clusters: 8 clusters per page) the first cluster read of a page therefore marks the other chunks of that page valid with zeros. Reads of the sibling clusters then find the VM backed buffer valid and are served the zeros from the cache without any I/O, although the data on disk is correct. Writes through the same path are affected the same way.
Symptom: single all-zero 512-byte clusters inside files after umount/mount, stuck until the page is evicted. Reproduced on real hardware (USB stick on xHCI, FAT16, 512-byte clusters).
Fix: for clusters smaller than a page, msdosfs no longer uses @uiomovebp()@ for the user copy and never touches user memory while a buffer is held (a fault into an mmap of the same file would recurse into the pager on the held buffer, which is the reason the fix-up exists).
read: copy the cluster out of the buffer, @bqrelse()@, then @uiomove()@ from the bounce buffer.
write: @uiomove()@ into a bounce buffer before @getblk()@/@bread()@, then @bcopy()@ into the buffer. On the @NOOFFSET@ and bread failure paths the uio offset and resid are rewound and the bounce is freed.
Not covered: @UIO_NOCOPY@ writes still use @uiomovebp()@. other callers of @uiomovebp()@ are untouched, a UFS fragment case with the same pattern is a guess, not tested yet. The generic alternative (what the TODO in the uiomovebp() header comment sketches: copy through a system buffer without holding the buffer or vnode lock) would fix all callers but is a larger change.
---Files--------------------------------
old-0002-msdosfs-Do-not-use-uiomovebp-for-sub-page-clusters.patch (5.73 KB)
0002-msdosfs-read-through-the-buffer-without-the-whole-pa.patch (2.34 KB)
0001-kern-add-uiomove_nofault_user.patch (2.11 KB)
0004-ntfs-read-through-the-buffer-without-the-whole-page-.patch (2.15 KB)
0003-msdosfs-stage-write-data-before-extending-the-file.patch (4.73 KB)
--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account
More information about the Bugs
mailing list