* [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
2026-12-03 0:43 ` Alistair Popple
0 siblings, 1 reply; 2+ 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, 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] 2+ messages in thread
* Re: [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers
2026-12-01 17:43 ` [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers Amit Prasad
@ 2026-12-03 0:43 ` Alistair Popple
0 siblings, 0 replies; 2+ messages in thread
From: Alistair Popple @ 2026-12-03 0:43 UTC (permalink / raw)
To: Amit Prasad
Cc: djbw, brauner, viro, jack, willy, djwong, alison.schofield,
nvdimm, linux-fsdevel, stable
On 2026-12-02 at 04:43 +1100, Amit Prasad <amit@modal.com> wrote...
> 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.
This does have a user visible side-effect - specifically a PMD sized
copy-on-write fault could now cause an application to crash with SIGBUS rather
than silently corrupting data.
Obviously that's a far better outcome, and it goes away once the second patch is
applied, but would be worth calling out in the commit message as only this patch
has been CC'd to stable.
Otherwise looks good.
> Authored with the use of an AI coding assistant (Claude Opus 5.5).
Just a nit for future - I don't think this is required as responsibility for the
patch lies with the author regardless of the tools used to generate it.
> 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 [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 0:44 UTC | newest]
Thread overview: 2+ messages (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
2026-12-03 0:43 ` Alistair Popple
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox