From: Michael Bommarito <michael.bommarito@gmail.com>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: Jeff Layton <jlayton@kernel.org>,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] NFSv4.1/pnfs: bound layout-type count in decode_pnfs_layout_types
Date: Mon, 22 Jun 2026 08:48:36 -0400 [thread overview]
Message-ID: <20260622124836.1696330-1-michael.bommarito@gmail.com> (raw)
decode_pnfs_layout_types() reads a server-controlled u32 count and then
reserves 4 * count bytes:
fsinfo->nlayouttypes = be32_to_cpup(p);
...
p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
The multiplication is u32, so any count >= 0x40000000 wraps to a small
value and xdr_inline_decode() reserves too few bytes. The NFS_MAX_LAYOUT
cap is applied only afterwards, so the subsequent reads run past the
short reservation. array_size() is not a safe guard here either:
xdr_inline_decode() runs its nbytes argument through
XDR_QUADLEN(((l) + 3) >> 2), which wraps SIZE_MAX to a zero-word
reservation instead of failing.
Reject counts that cannot fit in the u32 multiplication before the
reservation, and use sizeof(__be32) so the size arithmetic is explicit.
A malicious NFSv4.1+ server returning a crafted FATTR4_FS_LAYOUT_TYPES
attribute triggers this on the client during FSINFO decode.
This is the decode_pnfs_layout_types companion to the same XDR-wrap class
fixed in decode_getdeviceinfo (NFSv4.1/pnfs: bound notification bitmap
length in decode_getdeviceinfo).
Fixes: ca440c383a58 ("pnfs: add a new mechanism to select a layout driver according to an ordered list")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
---
Reproduced on a UML KASAN build with a KUnit case that feeds
decode_pnfs_layout_types() an xdr buffer whose nlayouttypes is 0x40000001:
nlayouttypes * 4 wraps, xdr_inline_decode() reserves a short buffer, and
the decode reads past xdr->end (KASAN slab-out-of-bounds read). With this
patch the count is rejected (-EIO) before the reservation. Benign control:
a small nlayouttypes decodes correctly on both stock and patched. The
KUnit test can ride as a separate patch (matching the decode_getdeviceinfo
series). Before/after logs available on request.
fs/nfs/nfs4xdr.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index c23c2eee1b5c4..8b7994f61d303 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -4903,8 +4903,16 @@ static int decode_pnfs_layout_types(struct xdr_stream *xdr,
if (fsinfo->nlayouttypes == 0)
return 0;
+ /* Reject counts that would overflow the u32 multiplication below.
+ * array_size() is not sufficient here: xdr_inline_decode() passes
+ * nbytes through XDR_QUADLEN(((l)+3)>>2), which wraps SIZE_MAX to
+ * a zero-word reservation rather than failing.
+ */
+ if (fsinfo->nlayouttypes > U32_MAX / sizeof(__be32))
+ return -EIO;
+
/* Decode and set first layout type, move xdr->p past unused types */
- p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
+ p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * sizeof(__be32));
if (unlikely(!p))
return -EIO;
base-commit: ef0c9f75a19532d7675384708fc8621e10850104
--
2.53.0
next reply other threads:[~2026-06-22 12:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 12:48 Michael Bommarito [this message]
2026-06-22 14:20 ` [PATCH] NFSv4.1/pnfs: bound layout-type count in decode_pnfs_layout_types Trond Myklebust
2026-06-26 11:18 ` [PATCH v2] " Michael Bommarito
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=20260622124836.1696330-1-michael.bommarito@gmail.com \
--to=michael.bommarito@gmail.com \
--cc=anna@kernel.org \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@kernel.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