Skip to contentSkip to conversation

nfsd: use xdr_encode_opaque_fixed for all GETXATTR fragments

PATCH In review Aldo Ariel Panzardo 3 participants 3 messages Sep 15

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfsd: use xdr_encode_opaque_fixed for all GETXATTR fragments

nfsd4_vbuf_to_stream() already uses xdr_encode_opaque_fixed() when the final fragment is shorter than a page, but the preceding memcpy() in the loop body does not clear XDR padding.

When the last fragment happens to be exactly PAGE_SIZE the short-fragment branch is never entered, and the loop exits through the normal buflen path. If that final page-sized reservation is not word-aligned within the XDR stream, its padding bytes are left stale.

Convert the loop memcpy to xdr_encode_opaque_fixed() and drop the now redundant short-fragment padding block, matching the first-fragment fix.

---
 fs/nfsd/nfs4xdr.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
fs/nfsd/nfs4xdr.c +3 -11
index XXXXXXX..XXXXXXX 100644
@@ -5963,15 +5963,7 @@ nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen)
 		if (!p)
 			return nfserr_resource;
 
-		memcpy(p, buf, cplen);
-
-		if (cplen < PAGE_SIZE) {
-			/*
-			 * We're done, with a length that wasn't page
-			 * aligned, so possibly not word aligned. Pad
-			 * any trailing bytes with 0.
-			 */
-			xdr_encode_opaque_fixed(p, NULL, cplen);
-			break;
-		}
+		xdr_encode_opaque_fixed(p, buf, cplen);
+		if (cplen < PAGE_SIZE)
+			break;
 

buflen -= PAGE_SIZE;
buf += PAGE_SIZE;

--
2.43.0

maintainer
#1 lore raw
Quoted 10 lines · Aldo Ariel Panzardo

nfsd4_vbuf_to_stream() already uses xdr_encode_opaque_fixed() when the final fragment is shorter than a page, but the preceding memcpy() in the loop body does not clear XDR padding.

When the last fragment happens to be exactly PAGE_SIZE the short-fragment branch is never entered, and the loop exits through the normal buflen path. If that final page-sized reservation is not word-aligned within the XDR stream, its padding bytes are left stale.

[...]

Applied to nfsd-testing, thanks!

[1/1] nfsd: use xdr_encode_opaque_fixed for all GETXATTR fragments

      commit: 802e78a4db687ee132ae9c71992490c201fdc39e

--
Chuck Lever

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Aldo Ariel Panzardo
Quoted 46 lines · Aldo Ariel Panzardo

nfsd4_vbuf_to_stream() already uses xdr_encode_opaque_fixed() when the final fragment is shorter than a page, but the preceding memcpy() in the loop body does not clear XDR padding.

When the last fragment happens to be exactly PAGE_SIZE the short-fragment branch is never entered, and the loop exits through the normal buflen path. If that final page-sized reservation is not word-aligned within the XDR stream, its padding bytes are left stale.

Convert the loop memcpy to xdr_encode_opaque_fixed() and drop the now redundant short-fragment padding block, matching the first-fragment fix.

---
 fs/nfsd/nfs4xdr.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
fs/nfsd/nfs4xdr.c +3 -11
index XXXXXXX..XXXXXXX 100644
@@ -5963,15 +5963,7 @@ nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen)
 		if (!p)
 			return nfserr_resource;
 
-		memcpy(p, buf, cplen);
-
-		if (cplen < PAGE_SIZE) {
-			/*
-			 * We're done, with a length that wasn't page
-			 * aligned, so possibly not word aligned. Pad
-			 * any trailing bytes with 0.
-			 */
-			xdr_encode_opaque_fixed(p, NULL, cplen);
-			break;
-		}
+		xdr_encode_opaque_fixed(p, buf, cplen);
+		if (cplen < PAGE_SIZE)
+			break;
 
fs/nfsd/nfs4xdr.c +0 -1
 		buflen -= PAGE_SIZE;
 		buf += PAGE_SIZE;
 
--
Quoted 1 line

2.43.0