All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] fsdax: handle short dax_direct_access() ranges
@ 2026-12-01 17:43 Amit Prasad
  2026-12-01 17:43 ` [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers Amit Prasad
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Amit Prasad @ 2026-12-01 17:43 UTC (permalink / raw)
  To: djbw, brauner, viro
  Cc: jack, willy, djwong, alison.schofield, nvdimm, linux-fsdevel,
	Amit Prasad

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/b

Creates 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
-- 
2.54.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-01 18:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 17:43 [PATCH 0/2] fsdax: handle short dax_direct_access() ranges Amit Prasad
2026-12-01 17:43 ` [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers Amit Prasad
2026-12-01 17:43 ` [PATCH 2/2] fsdax: iterate over short dax_direct_access() ranges Amit Prasad
2026-12-01 18:00   ` sashiko-bot
2026-12-01 18:37     ` Amit Prasad
2026-12-01 18:33 ` [PATCH 0/2] fsdax: handle " Amit Prasad

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.