Skip to contentSkip to conversation

nfsd: clear XDR padding in GETXATTR replies

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: clear XDR padding in GETXATTR replies

nfsd4_vbuf_to_stream() uses a raw memcpy() for the first fragment of an attribute value. xdr_reserve_space() aligns the reservation but does not initialize the extra bytes. If the complete value fits in that fragment, the loop that clears padding for the final fragment is never entered.

A remote client reading an attribute whose length is not a multiple of four can therefore receive one to three stale bytes from the response page.

Encode the first fragment with xdr_encode_opaque_fixed(), matching the final-fragment path and ensuring that any XDR padding is zeroed.

Fixes 23e50fe3a5e6 ("nfsd: implement the xattr functions and en/decode logic")
---
 fs/nfsd/nfs4xdr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +1 -1
index e17488a911..51ab68ffdf 100644
@@ -5953,7 +5953,7 @@ nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen)
 	if (!p)
 		return nfserr_resource;
 
-	memcpy(p, buf, cplen);
+	xdr_encode_opaque_fixed(p, buf, cplen);
 	buf += cplen;
 	buflen -= cplen;
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Aldo Ariel Panzardo

nfsd4_vbuf_to_stream() uses a raw memcpy() for the first fragment of an attribute value. xdr_reserve_space() aligns the reservation but does not initialize the extra bytes. If the complete value fits in that fragment, the loop that clears padding for the final fragment is never entered.

A remote client reading an attribute whose length is not a multiple of four can therefore receive one to three stale bytes from the response page.

Encode the first fragment with xdr_encode_opaque_fixed(), matching the final-fragment path and ensuring that any XDR padding is zeroed.

Fixes 23e50fe3a5e6 ("nfsd: implement the xattr functions and en/decode logic")
---
 fs/nfsd/nfs4xdr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +0 -0
index e17488a911..51ab68ffdf 100644

fs/nfsd/nfs4xdr.c nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen) · line 5959

Quoted 8 lines
fs/nfsd/nfs4xdr.c +1 -1
@@ -5953,7 +5953,7 @@ nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen)
 	if (!p)
 		return nfserr_resource;
 
-	memcpy(p, buf, cplen);
+	xdr_encode_opaque_fixed(p, buf, cplen);
 	buf += cplen;
 	buflen -= cplen;
 

Looks good. There is another memcpy() inside the loop just after this that probably ought to be converted this way too, but it's not strictly required to fix this bug. Maybe send a follow-on patch if you're inclined?

maintainer
#2 lore raw
In reply to Aldo Ariel Panzardo
Quoted 10 lines · Aldo Ariel Panzardo

nfsd4_vbuf_to_stream() uses a raw memcpy() for the first fragment of an attribute value. xdr_reserve_space() aligns the reservation but does not initialize the extra bytes. If the complete value fits in that fragment, the loop that clears padding for the final fragment is never entered.

A remote client reading an attribute whose length is not a multiple of four can therefore receive one to three stale bytes from the response page.

[...]

Applied to nfsd-testing, thanks!

[1/1] nfsd: clear XDR padding in GETXATTR replies

      commit: 37f0c2bea92e2c37a3ea0bb93a357336883a84a4

--
Chuck Lever