mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo
@ 2026-05-27 18:30 Jeff Layton
  2026-05-27 19:25 ` Chuck Lever
  2026-05-28 15:14 ` Chuck Lever
  0 siblings, 2 replies; 4+ messages in thread
From: Jeff Layton @ 2026-05-27 18:30 UTC (permalink / raw)
  To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
	Sasha Levin
  Cc: linux-nfs, linux-kernel, Jeff Layton

nfsd4_ff_encode_getdeviceinfo() computes the da_addr_body reservation
as 16 + netid_len + addr_len, but the subsequent xdr_encode_opaque()
calls emit 8 + round_up(netid_len, 4) + round_up(addr_len, 4) bytes.
The mismatch means the declared da_addr_body length exceeds the actual
encoded data by 2-8 bytes on every flexfile GETDEVICEINFO reply,
leaking stale reply-page content to the client and mis-aligning the
subsequent version list decode.

Use xdr_align_size() for each string length to match what
xdr_encode_opaque() actually writes.

Fixes: efcae97fa425 ("NFSD: da_addr_body field missing in some GETDEVICEINFO replies")
Assisted-by: kres:claude-opus-4-6
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/nfsd/flexfilelayoutxdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/flexfilelayoutxdr.c b/fs/nfsd/flexfilelayoutxdr.c
index f9f7e38cba13..7f357dbd1bb1 100644
--- a/fs/nfsd/flexfilelayoutxdr.c
+++ b/fs/nfsd/flexfilelayoutxdr.c
@@ -94,7 +94,8 @@ nfsd4_ff_encode_getdeviceinfo(struct xdr_stream *xdr,
 	}
 
 	/* len + padding for two strings */
-	addr_len = 16 + da->netaddr.netid_len + da->netaddr.addr_len;
+	addr_len = 8 + xdr_align_size(da->netaddr.netid_len) +
+		   xdr_align_size(da->netaddr.addr_len);
 	ver_len = 20;
 
 	len = 4 + ver_len + 4 + addr_len;

---
base-commit: b69fc3eaa867d0caa904634ea7a1b4569411b163
change-id: 20260527-pnfs-fixes-23451bb03d57

Best regards,
-- 
Jeff Layton <jlayton@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo
  2026-05-27 18:30 [PATCH] nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo Jeff Layton
@ 2026-05-27 19:25 ` Chuck Lever
  2026-05-27 19:27   ` Jeff Layton
  2026-05-28 15:14 ` Chuck Lever
  1 sibling, 1 reply; 4+ messages in thread
From: Chuck Lever @ 2026-05-27 19:25 UTC (permalink / raw)
  To: Jeff Layton, Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey, Sasha Levin
  Cc: linux-nfs, linux-kernel



On Wed, May 27, 2026, at 2:30 PM, Jeff Layton wrote:
> nfsd4_ff_encode_getdeviceinfo() computes the da_addr_body reservation
> as 16 + netid_len + addr_len, but the subsequent xdr_encode_opaque()
> calls emit 8 + round_up(netid_len, 4) + round_up(addr_len, 4) bytes.
> The mismatch means the declared da_addr_body length exceeds the actual
> encoded data by 2-8 bytes on every flexfile GETDEVICEINFO reply,
> leaking stale reply-page content to the client and mis-aligning the
> subsequent version list decode.
>
> Use xdr_align_size() for each string length to match what
> xdr_encode_opaque() actually writes.
>
> Fixes: efcae97fa425 ("NFSD: da_addr_body field missing in some 
> GETDEVICEINFO replies")
> Assisted-by: kres:claude-opus-4-6
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
>  fs/nfsd/flexfilelayoutxdr.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/nfsd/flexfilelayoutxdr.c b/fs/nfsd/flexfilelayoutxdr.c
> index f9f7e38cba13..7f357dbd1bb1 100644
> --- a/fs/nfsd/flexfilelayoutxdr.c
> +++ b/fs/nfsd/flexfilelayoutxdr.c
> @@ -94,7 +94,8 @@ nfsd4_ff_encode_getdeviceinfo(struct xdr_stream *xdr,
>  	}
> 
>  	/* len + padding for two strings */
> -	addr_len = 16 + da->netaddr.netid_len + da->netaddr.addr_len;
> +	addr_len = 8 + xdr_align_size(da->netaddr.netid_len) +
> +		   xdr_align_size(da->netaddr.addr_len);
>  	ver_len = 20;
> 
>  	len = 4 + ver_len + 4 + addr_len;
>
> ---
> base-commit: b69fc3eaa867d0caa904634ea7a1b4569411b163
> change-id: 20260527-pnfs-fixes-23451bb03d57
>
> Best regards,
> -- 
> Jeff Layton <jlayton@kernel.org>

Fixes tag might/should be 9b9960a0ca47 ? LLM reviews vary on this.

nfsd4_ff_encode_layoutget at fs/nfsd/flexfilelayoutxdr.c:40-41 has the
same unaligned pattern for UID/GID strings: 8 + uid.len + 8 + gid.len.
Do you intend to address that calculation as well?

My preference here is to convert to xdrgen instead, but that's a much
bigger and less back-portable change.


-- 
Chuck Lever

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo
  2026-05-27 19:25 ` Chuck Lever
@ 2026-05-27 19:27   ` Jeff Layton
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff Layton @ 2026-05-27 19:27 UTC (permalink / raw)
  To: Chuck Lever, Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey, Sasha Levin
  Cc: linux-nfs, linux-kernel

On Wed, 2026-05-27 at 15:25 -0400, Chuck Lever wrote:
> 
> On Wed, May 27, 2026, at 2:30 PM, Jeff Layton wrote:
> > nfsd4_ff_encode_getdeviceinfo() computes the da_addr_body reservation
> > as 16 + netid_len + addr_len, but the subsequent xdr_encode_opaque()
> > calls emit 8 + round_up(netid_len, 4) + round_up(addr_len, 4) bytes.
> > The mismatch means the declared da_addr_body length exceeds the actual
> > encoded data by 2-8 bytes on every flexfile GETDEVICEINFO reply,
> > leaking stale reply-page content to the client and mis-aligning the
> > subsequent version list decode.
> > 
> > Use xdr_align_size() for each string length to match what
> > xdr_encode_opaque() actually writes.
> > 
> > Fixes: efcae97fa425 ("NFSD: da_addr_body field missing in some 
> > GETDEVICEINFO replies")
> > Assisted-by: kres:claude-opus-4-6
> > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> > ---
> >  fs/nfsd/flexfilelayoutxdr.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/nfsd/flexfilelayoutxdr.c b/fs/nfsd/flexfilelayoutxdr.c
> > index f9f7e38cba13..7f357dbd1bb1 100644
> > --- a/fs/nfsd/flexfilelayoutxdr.c
> > +++ b/fs/nfsd/flexfilelayoutxdr.c
> > @@ -94,7 +94,8 @@ nfsd4_ff_encode_getdeviceinfo(struct xdr_stream *xdr,
> >  	}
> > 
> >  	/* len + padding for two strings */
> > -	addr_len = 16 + da->netaddr.netid_len + da->netaddr.addr_len;
> > +	addr_len = 8 + xdr_align_size(da->netaddr.netid_len) +
> > +		   xdr_align_size(da->netaddr.addr_len);
> >  	ver_len = 20;
> > 
> >  	len = 4 + ver_len + 4 + addr_len;
> > 
> > ---
> > base-commit: b69fc3eaa867d0caa904634ea7a1b4569411b163
> > change-id: 20260527-pnfs-fixes-23451bb03d57
> > 
> > Best regards,
> > -- 
> > Jeff Layton <jlayton@kernel.org>
> 
> Fixes tag might/should be 9b9960a0ca47 ? LLM reviews vary on this.
> 
> nfsd4_ff_encode_layoutget at fs/nfsd/flexfilelayoutxdr.c:40-41 has the
> same unaligned pattern for UID/GID strings: 8 + uid.len + 8 + gid.len.
> Do you intend to address that calculation as well?
> 
> My preference here is to convert to xdrgen instead, but that's a much
> bigger and less back-portable change.
> 

Yep, I just saw the Sashiko review for it. I'll fix that one up in a
separate patch.

Cheers,
-- 
Jeff Layton <jlayton@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo
  2026-05-27 18:30 [PATCH] nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo Jeff Layton
  2026-05-27 19:25 ` Chuck Lever
@ 2026-05-28 15:14 ` Chuck Lever
  1 sibling, 0 replies; 4+ messages in thread
From: Chuck Lever @ 2026-05-28 15:14 UTC (permalink / raw)
  To: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, Sasha Levin,
	Jeff Layton
  Cc: Chuck Lever, linux-nfs, linux-kernel

From: Chuck Lever <chuck.lever@oracle.com>

On Wed, 27 May 2026 14:30:41 -0400, Jeff Layton wrote:
> nfsd4_ff_encode_getdeviceinfo() computes the da_addr_body reservation
> as 16 + netid_len + addr_len, but the subsequent xdr_encode_opaque()
> calls emit 8 + round_up(netid_len, 4) + round_up(addr_len, 4) bytes.
> The mismatch means the declared da_addr_body length exceeds the actual
> encoded data by 2-8 bytes on every flexfile GETDEVICEINFO reply,
> leaking stale reply-page content to the client and mis-aligning the
> subsequent version list decode.
> 
> [...]

Applied to nfsd-testing, thanks!

[1/1] nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo
      commit: d53136757d4192934ad67d4c5c58eb9bc99daf4b

--
Chuck Lever <chuck.lever@oracle.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-28 15:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-27 18:30 [PATCH] nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo Jeff Layton
2026-05-27 19:25 ` Chuck Lever
2026-05-27 19:27   ` Jeff Layton
2026-05-28 15:14 ` Chuck Lever

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome