Issue #3461 has been updated by sigttou.

File 0004-vm-refuse-mmap-of-files-on-msdosfs-and-ntfs-with-sma.patch added

Patch 0004 for the series above (on top of 0001-0003): refuse mmap() of
files on msdosfs and ntfs mounts with clusters smaller than a page.

msdosfs and ntfs with clusters smaller than @PAGE_SIZE@ read a file
through separate cluster buffers, so one page covers several clusters and
cannot back a coherent mapping of the file.  The patch adds the internal
mount flag @MNTK_NOMMAP@, sets it in msdosfs and ntfs at mount time when
the cluster size is below a page, and makes @vm_mmap()@ fail a
regular-file mapping on such a mount with @EOPNOTSUPP@.  @vm_mmap()@ is
where mmap(2) (through @kern_mmap()@) and @fp_mmap()@ both end up.

Not covered: exec.  @imgact_elf@ inserts the vnode object itself, so a
binary stored on such a mount is still mapped while it runs.  0001-0003
keep read() and write() correct there.  A variant with plain copies
instead of the bounce and the same mmap refusal panicked ("lockmgr:
locking against myself") on NTFS 512 B with a program that, run from the
mount, reads its own file into its own data page.

Side effects on such mounts: @tail@ and @md5@/@sha256@ with offsets
use @mmap()@ and fail with "Operation not supported". @cat@, @cp@, @cmp@
and @md5@/@sha256@ of whole files work. A shared library stored there
cannot be loaded by rtld.

----------------------------------------
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-14948

* 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--------------------------------
0001-msdosfs-bounce-reads-of-clusters-smaller-than-a-page.patch (2.24 KB)
0002-msdosfs-stage-write-data-before-raising-the-file-siz.patch (5.07 KB)
0003-ntfs-bounce-reads-of-clusters-smaller-than-a-page.patch (2.23 KB)
0004-vm-refuse-mmap-of-files-on-msdosfs-and-ntfs-with-sma.patch (3.29 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

Reply via email to