All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: Amit Prasad <amit@modal.com>
Cc: djbw@kernel.org, brauner@kernel.org, viro@zeniv.linux.org.uk,
	 jack@suse.cz, willy@infradead.org, djwong@kernel.org,
	 alison.schofield@intel.com, nvdimm@lists.linux.dev,
	linux-fsdevel@vger.kernel.org,  stable@vger.kernel.org
Subject: Re: [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers
Date: Thu, 3 Dec 2026 11:43:50 +1100	[thread overview]
Message-ID: <axC4nR6158JWFbQ6@nvdebian.thelocal> (raw)
In-Reply-To: <20261201174324.5991-2-amit@modal.com>

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

  reply	other threads:[~2026-12-03  0:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-03  0:43   ` Alistair Popple [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axC4nR6158JWFbQ6@nvdebian.thelocal \
    --to=apopple@nvidia.com \
    --cc=alison.schofield@intel.com \
    --cc=amit@modal.com \
    --cc=brauner@kernel.org \
    --cc=djbw@kernel.org \
    --cc=djwong@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.