From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796264558; b=ORh8k5LQdo3BLUNEJDzkkh4kcgA/8y6llg8BGQNRSkNl2jJHWBqVg7UzrFN4DkHcNbB1 CgflGvnOLHTIuw5Q+mIYAvIYAvBS+8rr0B5HZtMeFdEvEBDXEE6tI23BZqWV54eiw0dty BzPKhbrrpu1GQU2z8Y81zbBFE4vuzkZNeEeO4bATf3NtrnOJXCrX70MncyL6FrdUvjeeZ 6d4NXp9tZnfK6MCjfzZoWKKYRbuKivZHLt7csl87ZwesHIQo6IH8HDsITPOX85bpEyOwP Uh69YAgvJVBB53CXaiMpGG99z1adoR/pV43ZzGmcOhl+YSykfOExi4joXLQae/OZR6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796264558; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=Nf9B5rCzKwz3WUSOD7YGwv5Qsox3KwOQb7Qhe6YzPNs=; b=Td+ftzb1Zf3TW53krl+M+KDEdGWMJDAYlALaJ1L6u9/pr/cKVLJ36oyAeBVykVBja952 LhiZrQw7XWSoq/TmsbU4TjODrfZByjMHR6hde0fWs9HpzJjcsV2+rtBzOmceJGvM2ENTK so7uzKTk/K5HlDE5szPo68OEyKX8QQZr05vHYod7S7/WMrISQtNdgEZ4yo46p4ulNtQGK CCdZGTgnVjHjv2vOPfG4knmMY5b6HL/17ZDjBMwUR6N1pSc6VjMfwbBNDu0Gwl8RwBjBg iJaogKJPPPRApoEcassxJsNbgWYSTUA4xhZ53BLkFnDeGa+jmkHEVnfq4oLWWrebM4A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=modal.com; spf=pass smtp.mailfrom=modal.com; dkim=pass header.d=modal.com header.i=@modal.com header.a=rsa-sha256 header.s=google header.b=RKA4ttxF; arc=none smtp.remote-ip=209.85.219.49 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C1DF606A334 for ; Thu, 3 Dec 2026 02:22:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6C1DF606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=modal.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=modal.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=modal.com header.i=@modal.com header.a=rsa-sha256 header.s=google header.b=RKA4ttxF Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-9213fddb596so112327276d6.2 for ; Wed, 02 Dec 2026 18:22:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=modal.com; s=google; t=1796264556; x=1796869356; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Nf9B5rCzKwz3WUSOD7YGwv5Qsox3KwOQb7Qhe6YzPNs=; b=RKA4ttxFmaLxmj7PMTMnoVDHsNhddowOeU6I2F8fEJ95X8d+muXY43TpzWexPZOD8v +0S2lbQ+rcMQfrQ0P5w8IIa7GTPgY3X0dvaOMvSa0v/aklfguIN2AsQOS7QKzKuHaPrC u85LpEP5poYuT6x1QC/byebwpEDGYkEm0BoVvTJ0Aue97vaxT+rSp3pqcqV4cv+/FqKg r9D8DIMZSN33McqrD5VKApmZhZ6W5C354nfeuPrtMha3C2/8oGLy3GOywXNGVbEUvMlU Pyjkg7wa/7Ng9BPHrnenzowIHjUls82QqFUPIXiyjog9p0G8F7296ygSloUkB8RkECwW 8diw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796264556; x=1796869356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Nf9B5rCzKwz3WUSOD7YGwv5Qsox3KwOQb7Qhe6YzPNs=; b=DjtBfMJFN1ShHo5YgWExmofk1fYDURyAI6Ex+U77EAJ6IR9Dw/v9y5ayikELzj36Fw j3O6ZvxF3upksWa6r/wKbPElV8TIP+CYZATPttBa5OT0Wv8dvlYVSYTOXJlshMTy7h1S YECjOc+HGeTXJZn2VewYOHPCHzVtqcsJgJdCffWkifX42fCMsF399/P12NLilFSK9u2s PvQGwz2VKN8Gf+kcnMgs7VH4zaOg2b2dEicYzRfJUaJhPI7qPsTsAeoh3VTVjPbPkLY0 65qNiC3Y2mEKTWKtDSC/H/7pGqJBXLzO5BKWYALZDrnUF2HQMBOMdckHh4ulP1+tTe26 jAKQ== X-Forwarded-Encrypted: i=1; AL+hErGVGPif8IHVuhQfUQvzNysI7HcQ52Y70Fe4QWYG8U9H5GKFS1ZdWW4HorfHWXhUU8Guzn3rxxo=@lists.linux.dev X-Gm-Message-State: APuU4Z+d9W828cEe7chkhyaK5mkLK+Hm0yl9LhA8L2a9wOJRkiDvmcY8 eFNZPkGq9FiLGkYSRecmNZvZZngua6vM+upqp4IlAkY92apRYV0K4q00KnvUgjt2cdO64PkuboV JJ63qmTY= X-Gm-Gg: AZFdTZcug01h0ZQqlKrKKkI14EMSBDCYfGEmSjE6H2l8EZ7ydt0gaiVDo2e0RpGSFzp clKlpyAd4ui3vzcdlAHjZwdeKyHYADQjKD1nmpy9H4BxajYumCLTkJa8vEPxS6fhuQHcg8pbn8Z hCFYaql6r3WH9BW0i8SLgC4HJh/BsYP8nLYAPw77VM75NP74qS8NwjTvS0bLOcuRRJshqcz/4QE zFjSo/j9LsHP9aFQ03gqMPQBLGXZN/BiGuosS9hYxBtr0SadynVO58ThrJVaZUlqV4xPI4MItff S0E0aMe/y4LJpTu6bKiBmVI7E7JFu7XzCovZz5DI+7bSc3MxmMwQEa4/nV/Xl6XUJdeqfbEaTnu L8k9N2dQiEXwydzrgQcF1+KuzlENoX7pZc5X4mmrBHzgq8jM5g9ArOXg8eP4sXUxXZLLvbJM0ZD +jgdibg+pJ97DlymqSmk4MuRcLFL/ryVP4IO2JvkTnVjVGlQ0zqcyEX8wdT2FXKV3+SjZ6lFbOD +NVrJShO0iDx5Z/3mW+zO5KngVxZGroRlprCB6GAIrjcrt7OMA/7xUrOHGpezws2hX18crra4fS 1e+67K/yTiB6sRIUGy30PcJopIvVMMAZ7Pge1nUXF52mpv/1foJj7EAsyKLP3QHfrDB+LA+aL9O BQ2Onbg0p1EyYm9KPzA== X-Received: by 2002:a05:6214:41a0:b0:921:b98f:7b7e with SMTP id 6a1803df08f44-921b98f7ba6mr162115816d6.36.1796264556259; Wed, 02 Dec 2026 18:22:36 -0800 (PST) Received: from devbox-amit-63ec.ec2.internal (ec2-44-214-141-241.compute-1.amazonaws.com. [44.214.141.241]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9217fd18b2asm211195766d6.21.2026.12.02.18.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 18:22:35 -0800 (PST) From: Amit Prasad To: apopple@nvidia.com, 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 , stable@vger.kernel.org Subject: [PATCH v2 1/2] fsdax: check the mapped length for all dax_iomap_direct_access() callers Date: Thu, 3 Dec 2026 02:21:38 +0000 Message-ID: <20261203022139.1022927-2-amit@modal.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261203022139.1022927-1-amit@modal.com> References: <20261203022139.1022927-1-amit@modal.com> X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. A PMD-sized copy-on-write fault with a short source now fails with SIGBUS instead of silently copying out-of-range data. 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 --- 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