fsdax: handle short dax_direct_access() ranges
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest2 patches 2 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | fsdax: check the mapped length for all dax_iomap_direct_access() callersfs/ | +10 | 0 replies | |
| 2/2 | fsdax: iterate over short dax_direct_access() rangesfs/ | +75 | 1 reply |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/2] fsdax: handle short dax_direct_access() ranges
dax_direct_access() can map fewer pages than asked for. Earlier changes caused fsdax's copy-on-write, unshare, and dedupe paths to skip a check of the returned length, which can result in reads and writes outside the mapped range.
For example, dm-stripe ends each range at a chunk boundary, so dax_direct_access() returns a shorter length than requested. On a filesystem with both DAX and reflinks (e.g. XFS) mounted on the striped device, fsdax doesn't respect the size of the mapped range, and can read/write outside of it.
The first patch minimally fixes this and explicitly returns an error. The second patch makes the above scenario work properly across such short device boundaries.
Tested against v7.4-rc5 in a VM with two pmem devices, beneath a dm-stripe target with 64 KiB chunks, XFS with reflink=1 and dax=always:
- unpatched: funshare of a reflinked file corrupts it, and a dedupe of two identical files reports them as different.
- patch 1: funshare fails with EINVAL without corrupting the file.
- patches 1-2: funshare succeeds and dedupe returns a valid result.
Reproducer (needs a 1 GiB pmem device, e.g. memmap=1G!4G):
dmsetup create stripe \
--table "0 2097152 striped 2 128 /dev/pmem0 0 /dev/pmem0 1048576"
mkfs.xfs -f -m reflink=1 /dev/mapper/stripe
mount -o dax=always /dev/mapper/stripe /mnt
head -c 1M /dev/urandom > /mnt/a
cp --reflink=always /mnt/a /mnt/b
xfs_io -c "funshare 0 1m" /mnt/b
cmp /mnt/a /mnt/bCreates a dm-stripe across two chunks of a pmem device. Unpatched, cmp reports differences. With patch 1, funshare fails with EINVAL, and with both patches cmp shows the files are identical.
The patch was reproduced and fixed with the help of an AI coding assistant (Claude Opus 5.5).
Amit Prasad (2):
fsdax: check the mapped length for all dax_iomap_direct_access()
callers
fsdax: iterate over short dax_direct_access() ranges
fs/dax.c | 118 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 33 deletions(-)
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
Signature · 1 line
2.54.0