* [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers
[not found] <20261201174324.5991-1-amit@modal.com>
@ 2026-12-01 17:43 ` Amit Prasad
0 siblings, 0 replies; only message 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, stable
dax_direct_access() may map fewer pages than asked for, e.g. when a
device-mapper target ends the range early. dax_iomap_direct_access()
checks the length only for callers that also ask for a pfn, so the
dax_iomap_copy_around(), dax_unshare_iter(), and
dax_range_compare_iter() methods may use memory outside the device's
returned range. Additionally, dax_iomap_iter() passes
dax_iomap_copy_around() the remaining length of the write instead of the
length the device mapped.
Thus, unshare, dedupe, and copy-on-write writes which cross these
boundaries can read/write to out-of-range data and corrupt it.
Check the length in dax_iomap_direct_access() for every caller, and
limit the length that dax_iomap_iter() passes to dax_iomap_copy_around()
to the mapped range, so that these out-of-range operations fail with an
error instead.
Authored with the use of an AI coding assistant (Claude Opus 5.5).
Fixes: e28cd3e50f30 ("fsdax: output address in dax_iomap_pfn() and rename it")
Fixes: ff17b8df224b ("fsdax: introduce dax_iomap_cow_copy()")
Cc: stable@vger.kernel.org
Signed-off-by: Amit Prasad <amit@modal.com>
---
fs/dax.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/fs/dax.c b/fs/dax.c
index 9d161d7ef3ef..0bb029e6a1eb 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -1281,11 +1281,13 @@ static int dax_iomap_direct_access(const struct iomap *iomap, loff_t pos,
rc = length;
goto out;
}
- if (!pfnp)
- goto out_check_addr;
rc = -EINVAL;
if (PFN_PHYS(length) < size)
goto out;
+ if (!pfnp) {
+ rc = 0;
+ goto out_check_addr;
+ }
if (*pfnp & (PHYS_PFN(size)-1))
goto out;
@@ -1688,18 +1690,19 @@ static int dax_iomap_iter(struct iomap_iter *iomi, struct iov_iter *iter)
break;
}
+ map_len = PFN_PHYS(map_len);
+ map_len -= offset;
+ if (map_len > end - pos)
+ map_len = end - pos;
+
if (cow) {
- ret = dax_iomap_copy_around(pos, length, PAGE_SIZE,
+ ret = dax_iomap_copy_around(pos, map_len, PAGE_SIZE,
srcmap, kaddr);
if (ret)
break;
}
- map_len = PFN_PHYS(map_len);
kaddr += offset;
- map_len -= offset;
- if (map_len > end - pos)
- map_len = end - pos;
if (recovery)
xfer = dax_recovery_write(dax_dev, pgoff, kaddr,
--
2.54.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-01 17:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261201174324.5991-1-amit@modal.com>
2026-12-01 17:43 ` [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers Amit Prasad
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox