Linux NFS development
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: Chuck Lever <cel@kernel.org>, Christoph Hellwig <hch@lst.de>,
	 Jeff Layton <jlayton@kernel.org>, NeilBrown <neil@brown.name>,
	 Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>,  Tom Talpey <tom@talpey.com>,
	Sergey Bashirov <sergeybashirov@gmail.com>,
	 Konstantin Evtushenko <koevtushenko@yandex.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 1/4] NFSD: Reject layoutupdate extent counts that wrap the length check
Date: Thu, 19 Nov 2026 13:33:51 -0500	[thread overview]
Message-ID: <20261119-blocklayout-decode-stream-v1-1-d71322f42c28@kernel.org> (raw)
In-Reply-To: <20261119-blocklayout-decode-stream-v1-0-d71322f42c28@kernel.org>

nfsd4_block_decode_layoutupdate() and nfsd4_scsi_decode_layoutupdate()
validate the extent count in a layoutupdate4 body by multiplying the
count by the size of one extent and comparing the product to the
length of the body. The product is stored in a u32, so a count of
0x40000000 block extents or 0x10000000 SCSI ranges wraps to zero and
matches a body that carries no extents at all. Both decoders then
pass the count to kzalloc_objs(). The request exceeds
KMALLOC_MAX_SIZE, so the allocation fails with a warning. NFSD then
returns NFS4ERR_DELAY for a LAYOUTCOMMIT it should reject with
NFS4ERR_BADXDR.

Fixes: f963cf2b91a3 ("NFSD: Implement large extent array support in pNFS")
Fixes: f99d4fbdae67 ("nfsd: add SCSI layout support")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
 fs/nfsd/blocklayoutxdr.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/nfsd/blocklayoutxdr.c b/fs/nfsd/blocklayoutxdr.c
index a6589f5c878a..ea9a3f04a560 100644
--- a/fs/nfsd/blocklayoutxdr.c
+++ b/fs/nfsd/blocklayoutxdr.c
@@ -164,15 +164,15 @@ nfsd4_block_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp,
 		int *nr_iomapsp, u32 block_size)
 {
 	struct iomap *iomaps;
-	u32 nr_iomaps, expected, len, i;
+	u32 nr_iomaps, len, i;
 	__be32 nfserr;
 
 	if (xdr_stream_decode_u32(xdr, &nr_iomaps))
 		return nfserr_bad_xdr;
 
-	len = sizeof(__be32) + xdr_stream_remaining(xdr);
-	expected = sizeof(__be32) + nr_iomaps * PNFS_BLOCK_EXTENT_SIZE;
-	if (len != expected)
+	len = xdr_stream_remaining(xdr);
+	if (len % PNFS_BLOCK_EXTENT_SIZE ||
+	    nr_iomaps != len / PNFS_BLOCK_EXTENT_SIZE)
 		return nfserr_bad_xdr;
 
 	iomaps = kzalloc_objs(*iomaps, nr_iomaps);
@@ -258,15 +258,15 @@ nfsd4_scsi_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp,
 		int *nr_iomapsp, u32 block_size)
 {
 	struct iomap *iomaps;
-	u32 nr_iomaps, expected, len, i;
+	u32 nr_iomaps, len, i;
 	__be32 nfserr;
 
 	if (xdr_stream_decode_u32(xdr, &nr_iomaps))
 		return nfserr_bad_xdr;
 
-	len = sizeof(__be32) + xdr_stream_remaining(xdr);
-	expected = sizeof(__be32) + nr_iomaps * PNFS_SCSI_RANGE_SIZE;
-	if (len != expected)
+	len = xdr_stream_remaining(xdr);
+	if (len % PNFS_SCSI_RANGE_SIZE ||
+	    nr_iomaps != len / PNFS_SCSI_RANGE_SIZE)
 		return nfserr_bad_xdr;
 
 	iomaps = kzalloc_objs(*iomaps, nr_iomaps);

-- 
2.56.0


  reply	other threads:[~2026-11-19 18:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 18:33 [PATCH 0/4] NFSD: More minor XDR restructuring Chuck Lever
2026-11-19 18:33 ` Chuck Lever [this message]
2026-11-20 16:12   ` [PATCH 1/4] NFSD: Reject layoutupdate extent counts that wrap the length check Christoph Hellwig
2026-11-19 18:33 ` [PATCH 2/4] NFSD: Allocate the layoutupdate extent array with kvzalloc_objs() Chuck Lever
2026-11-20 16:13   ` Christoph Hellwig
2026-11-19 18:33 ` [PATCH 3/4] NFSD: Decode block and SCSI layoutupdates from a local xdr_stream Chuck Lever
2026-11-20 16:14   ` Christoph Hellwig
2026-11-19 18:33 ` [PATCH 4/4] NFSD: Remove the svc_rqst argument from proc_layoutcommit Chuck Lever

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=20261119-blocklayout-decode-stream-v1-1-d71322f42c28@kernel.org \
    --to=cel@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=hch@lst.de \
    --cc=jlayton@kernel.org \
    --cc=koevtushenko@yandex.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=sergeybashirov@gmail.com \
    --cc=tom@talpey.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