All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amit Prasad" <amit@modal.com>
Cc: nvdimm@lists.linux.dev
Subject: Re: [PATCH v2 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers
Date: Thu, 03 Dec 2026 02:41:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-247022@kernel.org> (raw)
In-Reply-To: <20261203022139.1022927-2-amit@modal.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] fsdax: uninitialized CoW extent committed on
  dax_iomap_copy_around() fault error
--

commit 8f94c2f57aa6785f8bab5e4a4dcfe7614a1a1370
Author: Amit Prasad <amit@modal.com>

fsdax: check the mapped length for all dax_iomap_direct_access() callers

This commit checks the mapped length returned by dax_direct_access() in
dax_iomap_direct_access() even when pfnp is NULL, and clamps the length
passed to dax_iomap_copy_around() in dax_iomap_iter() to the mapped
range.

> diff --git a/fs/dax.c b/fs/dax.c
> index 9d161d7ef3ef7..0bb029e6a1ebb 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;
> +	}

[Severity: High]
Can a PMD-sized copy-on-write fault with a short source map commit an
uninitialized 2MB CoW extent into the inode data fork when
dax_iomap_copy_around() fails?

In dax_fault_iter(), dax_insert_entry() associates the newly allocated
destination CoW PFN and installs it into mapping->i_pages before calling
dax_iomap_copy_around().  When srcmap maps less than PMD_SIZE (such as
across a device-mapper target boundary), dax_iomap_direct_access() now
returns -EINVAL, causing dax_iomap_copy_around() to fail with -EIO and
dax_fault_iter() to return VM_FAULT_SIGBUS without copying the source
data:

fs/dax.c:dax_fault_iter() {
    ...
	*entry = dax_insert_entry(xas, vmf, iter, *entry, pfn, entry_flags);

	if (write && iomap->flags & IOMAP_F_SHARED) {
		err = dax_iomap_copy_around(pos, size, size, srcmap, kaddr);
		if (err)
			return dax_fault_return(err);
	}
    ...
}

Because dax_iomap_pmd_fault() advances the iomap iterator whenever the
return value is not VM_FAULT_FALLBACK, it advances iter by PMD_SIZE on
VM_FAULT_SIGBUS:

fs/dax.c:dax_iomap_pmd_fault() {
    ...
		ret = dax_fault_iter(vmf, &iter, pfnp, &xas, &entry, true);
		if (ret != VM_FAULT_FALLBACK)
			iter.status = iomap_iter_advance(&iter, PMD_SIZE);
    ...
}

xfs_dax_write_iomap_end() then receives written == PMD_SIZE and calls
xfs_reflink_end_cow() instead of xfs_reflink_cancel_cow_range(),
remapping the uncopied CoW extent into the file and corrupting 2MB of
file data (while on a failed PTE CoW fault, written is 0 so
xfs_reflink_cancel_cow_range() frees the CoW block that dax_insert_entry()
already installed into mapping->i_pages).

The follow-up commit "fsdax: iterate over short dax_direct_access()
ranges" updates dax_iomap_copy_around() to iterate over short srcmap
mappings, but this commit is tagged for stable and leaves the fault error
path in dax_fault_iter() and dax_iomap_pmd_fault() broken whenever
dax_iomap_copy_around() fails.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203022139.1022927-1-amit@modal.com?part=1

  reply	other threads:[~2026-12-03  2:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  2:21 [PATCH v2 0/2] fsdax: handle short dax_direct_access() ranges Amit Prasad
2026-12-03  2:21 ` [PATCH v2 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers Amit Prasad
2026-12-03  2:41   ` sashiko-bot [this message]
2026-12-03  2:21 ` [PATCH v2 2/2] fsdax: iterate over short dax_direct_access() ranges 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=sashiko-outbox-247022@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amit@modal.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.