* [PATCH 1/4] NFSD: Reject layoutupdate extent counts that wrap the length check
2026-11-19 18:33 [PATCH 0/4] NFSD: More minor XDR restructuring Chuck Lever
@ 2026-11-19 18:33 ` Chuck Lever
2026-11-20 16:12 ` Christoph Hellwig
2026-11-19 18:33 ` [PATCH 2/4] NFSD: Allocate the layoutupdate extent array with kvzalloc_objs() Chuck Lever
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Chuck Lever @ 2026-11-19 18:33 UTC (permalink / raw)
To: Chuck Lever, Christoph Hellwig, Jeff Layton, NeilBrown,
Olga Kornievskaia, Dai Ngo, Tom Talpey, Sergey Bashirov,
Konstantin Evtushenko
Cc: linux-nfs
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
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/4] NFSD: Allocate the layoutupdate extent array with kvzalloc_objs()
2026-11-19 18:33 [PATCH 0/4] NFSD: More minor XDR restructuring Chuck Lever
2026-11-19 18:33 ` [PATCH 1/4] NFSD: Reject layoutupdate extent counts that wrap the length check Chuck Lever
@ 2026-11-19 18:33 ` 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-19 18:33 ` [PATCH 4/4] NFSD: Remove the svc_rqst argument from proc_layoutcommit Chuck Lever
3 siblings, 1 reply; 8+ messages in thread
From: Chuck Lever @ 2026-11-19 18:33 UTC (permalink / raw)
To: Chuck Lever, Christoph Hellwig, Jeff Layton, NeilBrown,
Olga Kornievskaia, Dai Ngo, Tom Talpey, Sergey Bashirov,
Konstantin Evtushenko
Cc: linux-nfs
The block and SCSI layoutupdate decoders allocate one struct iomap
per extent with kzalloc_objs(). A struct iomap is larger than a
44-byte block extent or a 16-byte SCSI range, so a lou_body that
fits in the maximum request size can still need an array larger
than KMALLOC_MAX_SIZE. kmalloc() then warns that the request exceeds
KMALLOC_MAX_SIZE, and the decoder returns nfserr_delay. A client that
retries after NFS4ERR_DELAY resends a LAYOUTCOMMIT that NFSD can never
decode. Found by inspection.
The session's ca_maxrequestsize still bounds the size of the array.
Fixes: 8650b8a05850 ("nfsd: pNFS block layout driver")
Fixes: f99d4fbdae67 ("nfsd: add SCSI layout support")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
fs/nfsd/blocklayout.c | 2 +-
fs/nfsd/blocklayoutxdr.c | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/fs/nfsd/blocklayout.c b/fs/nfsd/blocklayout.c
index b3bb2831cff3..06564f247795 100644
--- a/fs/nfsd/blocklayout.c
+++ b/fs/nfsd/blocklayout.c
@@ -228,7 +228,7 @@ nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp,
error = inode->i_sb->s_export_op->block_ops->commit_blocks(inode,
iomaps, nr_iomaps,
lcp->lc_size_chg ? lcp->lc_newsize : 0);
- kfree(iomaps);
+ kvfree(iomaps);
return nfserrno(error);
}
diff --git a/fs/nfsd/blocklayoutxdr.c b/fs/nfsd/blocklayoutxdr.c
index ea9a3f04a560..90ccc07801ca 100644
--- a/fs/nfsd/blocklayoutxdr.c
+++ b/fs/nfsd/blocklayoutxdr.c
@@ -175,7 +175,7 @@ nfsd4_block_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp,
nr_iomaps != len / PNFS_BLOCK_EXTENT_SIZE)
return nfserr_bad_xdr;
- iomaps = kzalloc_objs(*iomaps, nr_iomaps);
+ iomaps = kvzalloc_objs(*iomaps, nr_iomaps);
if (!iomaps)
return nfserr_delay;
@@ -231,7 +231,7 @@ nfsd4_block_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp,
*nr_iomapsp = nr_iomaps;
return nfs_ok;
fail:
- kfree(iomaps);
+ kvfree(iomaps);
return nfserr;
}
@@ -269,7 +269,7 @@ nfsd4_scsi_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp,
nr_iomaps != len / PNFS_SCSI_RANGE_SIZE)
return nfserr_bad_xdr;
- iomaps = kzalloc_objs(*iomaps, nr_iomaps);
+ iomaps = kvzalloc_objs(*iomaps, nr_iomaps);
if (!iomaps)
return nfserr_delay;
@@ -301,6 +301,6 @@ nfsd4_scsi_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp,
*nr_iomapsp = nr_iomaps;
return nfs_ok;
fail:
- kfree(iomaps);
+ kvfree(iomaps);
return nfserr;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/4] NFSD: Decode block and SCSI layoutupdates from a local xdr_stream
2026-11-19 18:33 [PATCH 0/4] NFSD: More minor XDR restructuring Chuck Lever
2026-11-19 18:33 ` [PATCH 1/4] NFSD: Reject layoutupdate extent counts that wrap the length check Chuck Lever
2026-11-19 18:33 ` [PATCH 2/4] NFSD: Allocate the layoutupdate extent array with kvzalloc_objs() Chuck Lever
@ 2026-11-19 18:33 ` 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
3 siblings, 1 reply; 8+ messages in thread
From: Chuck Lever @ 2026-11-19 18:33 UTC (permalink / raw)
To: Chuck Lever, Christoph Hellwig, Jeff Layton, NeilBrown,
Olga Kornievskaia, Dai Ngo, Tom Talpey, Sergey Bashirov,
Konstantin Evtushenko
Cc: linux-nfs
nfsd4_decode_layoutupdate4() leaves the body of a layoutupdate4
undecoded in lc_up_layout. nfsd4_block_proc_layoutcommit() and
nfsd4_scsi_proc_layoutcommit() decode that body during the pc_func
step by overwriting rqstp->rq_arg and re-initializing
rq_arg_stream. Nothing reads those fields after pc_decode today,
but the svc_rqst should be free to keep state in them until the
request completes.
Decode the layoutupdate4 body from an xdr_stream and scratch
buffer on the stack instead, leaving rq_arg and rq_arg_stream
untouched. Decoding layoutupdate4 during the pc_decode step would
be a better design, but that larger change is outside the scope
of this patch.
Signed-off-by: Chuck Lever <cel@kernel.org>
---
fs/nfsd/blocklayout.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/fs/nfsd/blocklayout.c b/fs/nfsd/blocklayout.c
index 06564f247795..c3b614b25278 100644
--- a/fs/nfsd/blocklayout.c
+++ b/fs/nfsd/blocklayout.c
@@ -269,15 +269,18 @@ static __be32
nfsd4_block_proc_layoutcommit(struct inode *inode, struct svc_rqst *rqstp,
struct nfsd4_layoutcommit *lcp)
{
+ __be32 scratch[XDR_QUADLEN(NFS4_DEVICEID4_SIZE)];
+ struct xdr_stream xdr;
struct iomap *iomaps;
int nr_iomaps;
__be32 nfserr;
- rqstp->rq_arg = lcp->lc_up_layout;
- svcxdr_init_decode(rqstp);
+ xdr_init_decode(&xdr, &lcp->lc_up_layout, NULL, NULL);
+ xdr_set_scratch_buffer(&xdr, scratch, sizeof(scratch));
- nfserr = nfsd4_block_decode_layoutupdate(&rqstp->rq_arg_stream,
- &iomaps, &nr_iomaps, i_blocksize(inode));
+ nfserr = nfsd4_block_decode_layoutupdate(&xdr, &iomaps, &nr_iomaps,
+ i_blocksize(inode));
+ xdr_finish_decode(&xdr);
if (nfserr != nfs_ok)
return nfserr;
@@ -461,15 +464,18 @@ static __be32
nfsd4_scsi_proc_layoutcommit(struct inode *inode, struct svc_rqst *rqstp,
struct nfsd4_layoutcommit *lcp)
{
+ __be32 scratch[XDR_QUADLEN(NFS4_DEVICEID4_SIZE)];
+ struct xdr_stream xdr;
struct iomap *iomaps;
int nr_iomaps;
__be32 nfserr;
- rqstp->rq_arg = lcp->lc_up_layout;
- svcxdr_init_decode(rqstp);
+ xdr_init_decode(&xdr, &lcp->lc_up_layout, NULL, NULL);
+ xdr_set_scratch_buffer(&xdr, scratch, sizeof(scratch));
- nfserr = nfsd4_scsi_decode_layoutupdate(&rqstp->rq_arg_stream,
- &iomaps, &nr_iomaps, i_blocksize(inode));
+ nfserr = nfsd4_scsi_decode_layoutupdate(&xdr, &iomaps, &nr_iomaps,
+ i_blocksize(inode));
+ xdr_finish_decode(&xdr);
if (nfserr != nfs_ok)
return nfserr;
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 3/4] NFSD: Decode block and SCSI layoutupdates from a local xdr_stream
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
0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-11-20 16:14 UTC (permalink / raw)
To: Chuck Lever
Cc: Christoph Hellwig, Jeff Layton, NeilBrown, Olga Kornievskaia,
Dai Ngo, Tom Talpey, Sergey Bashirov, Konstantin Evtushenko,
linux-nfs
On Thu, Nov 19, 2026 at 01:33:53PM -0500, Chuck Lever wrote:
>
> - nfserr = nfsd4_block_decode_layoutupdate(&rqstp->rq_arg_stream,
> - &iomaps, &nr_iomaps, i_blocksize(inode));
> + nfserr = nfsd4_block_decode_layoutupdate(&xdr, &iomaps, &nr_iomaps,
> + i_blocksize(inode));
Can we please keep the sane tab-based alignment instead of the stupid
after pening brace one that creates nothing but constant churn for
every change in the function signature while also massively reducing
readability?
The rest looks good.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/4] NFSD: Remove the svc_rqst argument from proc_layoutcommit
2026-11-19 18:33 [PATCH 0/4] NFSD: More minor XDR restructuring Chuck Lever
` (2 preceding siblings ...)
2026-11-19 18:33 ` [PATCH 3/4] NFSD: Decode block and SCSI layoutupdates from a local xdr_stream Chuck Lever
@ 2026-11-19 18:33 ` Chuck Lever
3 siblings, 0 replies; 8+ messages in thread
From: Chuck Lever @ 2026-11-19 18:33 UTC (permalink / raw)
To: Chuck Lever, Christoph Hellwig, Jeff Layton, NeilBrown,
Olga Kornievskaia, Dai Ngo, Tom Talpey, Sergey Bashirov,
Konstantin Evtushenko
Cc: linux-nfs
Commit f963cf2b91a3 ("NFSD: Implement large extent array support in
pNFS") added an svc_rqst argument to the proc_layoutcommit layout
operation so the block and SCSI layout drivers could decode the
layoutupdate4 body with rq_arg_stream. Those drivers decode from a
local xdr_stream, and no proc_layoutcommit implementation reads the
svc_rqst. Leaving the argument in place invites a layout driver to
borrow rq_arg again.
Remove the svc_rqst argument from the operation and from its three
implementations.
Signed-off-by: Chuck Lever <cel@kernel.org>
---
fs/nfsd/blocklayout.c | 8 ++++----
fs/nfsd/flexfilelayout.c | 4 ++--
fs/nfsd/nfs4proc.c | 2 +-
fs/nfsd/pnfs.h | 3 +--
4 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/fs/nfsd/blocklayout.c b/fs/nfsd/blocklayout.c
index c3b614b25278..23f2365787eb 100644
--- a/fs/nfsd/blocklayout.c
+++ b/fs/nfsd/blocklayout.c
@@ -266,8 +266,8 @@ nfsd4_block_proc_getdeviceinfo(struct super_block *sb,
}
static __be32
-nfsd4_block_proc_layoutcommit(struct inode *inode, struct svc_rqst *rqstp,
- struct nfsd4_layoutcommit *lcp)
+nfsd4_block_proc_layoutcommit(struct inode *inode,
+ struct nfsd4_layoutcommit *lcp)
{
__be32 scratch[XDR_QUADLEN(NFS4_DEVICEID4_SIZE)];
struct xdr_stream xdr;
@@ -461,8 +461,8 @@ nfsd4_scsi_proc_getdeviceinfo(struct super_block *sb,
return nfserrno(nfsd4_block_get_device_info_scsi(sb, clp, gdp));
}
static __be32
-nfsd4_scsi_proc_layoutcommit(struct inode *inode, struct svc_rqst *rqstp,
- struct nfsd4_layoutcommit *lcp)
+nfsd4_scsi_proc_layoutcommit(struct inode *inode,
+ struct nfsd4_layoutcommit *lcp)
{
__be32 scratch[XDR_QUADLEN(NFS4_DEVICEID4_SIZE)];
struct xdr_stream xdr;
diff --git a/fs/nfsd/flexfilelayout.c b/fs/nfsd/flexfilelayout.c
index 0deb913493a3..c97caeec4024 100644
--- a/fs/nfsd/flexfilelayout.c
+++ b/fs/nfsd/flexfilelayout.c
@@ -130,8 +130,8 @@ nfsd4_ff_proc_getdeviceinfo(struct super_block *sb, struct svc_rqst *rqstp,
}
static __be32
-nfsd4_ff_proc_layoutcommit(struct inode *inode, struct svc_rqst *rqstp,
- struct nfsd4_layoutcommit *lcp)
+nfsd4_ff_proc_layoutcommit(struct inode *inode,
+ struct nfsd4_layoutcommit *lcp)
{
return nfs_ok;
}
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 71d6a473c1bc..2f25acb1ac92 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -3119,7 +3119,7 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,
mutex_unlock(&ls->ls_mutex);
}
- nfserr = ops->proc_layoutcommit(inode, rqstp, lcp);
+ nfserr = ops->proc_layoutcommit(inode, lcp);
if (!lcp->lc_reclaim) {
nfsd4_file_mark_deleg_written(ls->ls_stid.sc_file);
diff --git a/fs/nfsd/pnfs.h b/fs/nfsd/pnfs.h
index e5f2e11c880a..a3d558ccdbdf 100644
--- a/fs/nfsd/pnfs.h
+++ b/fs/nfsd/pnfs.h
@@ -38,8 +38,7 @@ struct nfsd4_layout_ops {
const struct nfsd4_layoutget *lgp);
__be32 (*proc_layoutcommit)(struct inode *inode,
- struct svc_rqst *rqstp,
- struct nfsd4_layoutcommit *lcp);
+ struct nfsd4_layoutcommit *lcp);
bool (*fence_client)(struct nfs4_layout_stateid *ls,
struct nfsd_file *file);
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread