* [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; 4+ 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] 4+ 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 2026-12-03 2:33 ` Amit Prasad 0 siblings, 1 reply; 4+ 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] 4+ messages in thread
* Re: [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers 2026-12-03 0:43 ` Alistair Popple @ 2026-12-03 2:33 ` Amit Prasad 2026-12-03 5:30 ` Alistair Popple 0 siblings, 1 reply; 4+ messages in thread From: Amit Prasad @ 2026-12-03 2:33 UTC (permalink / raw) To: Alistair Popple Cc: brauner, viro, jack, willy, djwong, alison.schofield, nvdimm, linux-fsdevel, stable > 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. Thanks for the prompt review! I've updated the message and submitted a v2: https://lore.kernel.org/nvdimm/20261203022139.1022927-1-amit@modal.com/ > 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. Makes sense; I wasn't sure what the disclosure policies/standards are (this is the first patch I've submitted upstream). Updated! Amit ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers 2026-12-03 2:33 ` Amit Prasad @ 2026-12-03 5:30 ` Alistair Popple 0 siblings, 0 replies; 4+ messages in thread From: Alistair Popple @ 2026-12-03 5:30 UTC (permalink / raw) To: Amit Prasad Cc: brauner, viro, jack, willy, djwong, alison.schofield, nvdimm, linux-fsdevel, stable On 2026-12-03 at 13:33 +1100, Amit Prasad <amit@modal.com> wrote... > > 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. > > Thanks for the prompt review! I've updated the message and submitted a v2: > > https://lore.kernel.org/nvdimm/20261203022139.1022927-1-amit@modal.com/ > > > 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. > > Makes sense; I wasn't sure what the disclosure policies/standards are (this is > the first patch I've submitted upstream). Updated! Welcome! The policies are here: https://docs.kernel.org/process/generated-content.html And actually I should have re-read them before making that comment (it's been a while) as it turns out my opinion doesn't match the recommendations there :) - Alistair > Amit ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 5:30 UTC | newest]
Thread overview: 4+ 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
2026-12-03 2:33 ` Amit Prasad
2026-12-03 5:30 ` Alistair Popple
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox