Skip to contentSkip to conversation

nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo

PATCH In review Jeff Layton 2 participants 4 messages May 27 – May 28

Subsystems (2)
lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

PATCH 1/1 nfsd: fix XDR padding calculation in ff_encode_getdeviceinfo

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
---
 fs/nfsd/flexfilelayoutxdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/flexfilelayoutxdr.c +2 -1
index f9f7e38cba13..7f357dbd1bb1 100644
@@ -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,

Signature · 1 line
Jeff Layton <[email protected]>
maintainer
#1 lore raw
Quoted 38 lines · 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
---
 fs/nfsd/flexfilelayoutxdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/flexfilelayoutxdr.c +2 -2
index f9f7e38cba13..7f357dbd1bb1 100644
@@ -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

Quoted 3 lines

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>

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.

Signature · 1 line
Chuck Lever
author maintainer
#2 lore raw
Quoted 46 lines · Chuck Lever
Quoted 38 lines · 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
---
 fs/nfsd/flexfilelayoutxdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/flexfilelayoutxdr.c +2 -2
index f9f7e38cba13..7f357dbd1bb1 100644
@@ -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

Quoted 3 lines

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>

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

Quoted 7 lines

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,

Signature · 1 line
Jeff Layton <[email protected]>
maintainer
#3 lore raw
In reply to Jeff Layton

From: Chuck Lever <[email protected]>

Quoted 9 lines · 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.

[...]

Applied to nfsd-testing, thanks!

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

      commit: d53136757d4192934ad67d4c5c58eb9bc99daf4b

--
Chuck Lever <[email protected]>