From: Anna Schumaker <anna@kernel.org>
To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com
Cc: anna@kernel.org
Subject: [PATCH 1/3] NFS: Have decode_pnfs_layout_types() use XDR's decode_uint32_array()
Date: Mon, 12 Oct 2026 08:33:44 -0400 [thread overview]
Message-ID: <20261012123346.123126-2-anna@kernel.org> (raw)
In-Reply-To: <20261012123346.123126-1-anna@kernel.org>
From: Anna Schumaker <anna.schumaker@hammerspace.com>
Rather than hardcoding in an alternative that doesn't properly check for
32-bit overflow during decoding.
Signed-off-by: Anna Schumaker <anna.schumaker@hammerspace.com>
---
fs/nfs/nfs4xdr.c | 33 +++++++++------------------------
1 file changed, 9 insertions(+), 24 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 740f3bc4a19d..4d12b97f423e 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -4924,32 +4924,17 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
static int decode_pnfs_layout_types(struct xdr_stream *xdr,
struct nfs_fsinfo *fsinfo)
{
- __be32 *p;
- uint32_t i;
+ ssize_t nlayouttypes;
- p = xdr_inline_decode(xdr, 4);
- if (unlikely(!p))
- return -EIO;
- fsinfo->nlayouttypes = be32_to_cpup(p);
+ nlayouttypes = xdr_stream_decode_uint32_array(xdr,
+ fsinfo->layouttype,
+ NFS_MAX_LAYOUT_TYPES);
+ if (nlayouttypes == -EMSGSIZE)
+ nlayouttypes = NFS_MAX_LAYOUT_TYPES;
+ if (nlayouttypes < 0)
+ return nlayouttypes;
- /* pNFS is not supported by the underlying file system */
- if (fsinfo->nlayouttypes == 0)
- return 0;
-
- /* Decode and set first layout type, move xdr->p past unused types */
- p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
- if (unlikely(!p))
- return -EIO;
-
- /* If we get too many, then just cap it at the max */
- if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
- printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
- __func__, fsinfo->nlayouttypes);
- fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
- }
-
- for(i = 0; i < fsinfo->nlayouttypes; ++i)
- fsinfo->layouttype[i] = be32_to_cpup(p++);
+ fsinfo->nlayouttypes = nlayouttypes;
return 0;
}
--
2.56.0
next prev parent reply other threads:[~2026-10-12 12:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 12:33 [PATCH 0/3] NFS: Modernize decoding uint32 arrays Anna Schumaker
2026-10-12 12:33 ` Anna Schumaker [this message]
2026-10-12 12:33 ` [PATCH 2/3] NFS: Modernize the callback decode_bitmap() function Anna Schumaker
2026-10-12 13:13 ` Benjamin Coddington
2026-10-12 15:06 ` Anna Schumaker
2026-10-12 12:33 ` [PATCH 3/3] NFS: Modernize decode_getdevinfo() bitmap decoding Anna Schumaker
2026-10-12 13:14 ` [PATCH 0/3] NFS: Modernize decoding uint32 arrays Benjamin Coddington
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=20261012123346.123126-2-anna@kernel.org \
--to=anna@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@hammerspace.com \
/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