Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Amit Prasad <amit@modal.com>
To: djbw@kernel.org, brauner@kernel.org, viro@zeniv.linux.org.uk
Cc: jack@suse.cz, willy@infradead.org, djwong@kernel.org,
	alison.schofield@intel.com, nvdimm@lists.linux.dev,
	linux-fsdevel@vger.kernel.org, Amit Prasad <amit@modal.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers
Date: Tue,  1 Dec 2026 17:43:23 +0000	[thread overview]
Message-ID: <20261201174324.5991-2-amit@modal.com> (raw)
In-Reply-To: <20261201174324.5991-1-amit@modal.com>

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


           reply	other threads:[~2026-12-01 17:43 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20261201174324.5991-1-amit@modal.com>]

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=20261201174324.5991-2-amit@modal.com \
    --to=amit@modal.com \
    --cc=alison.schofield@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox