Skip to contentSkip to conversation

NFSD: fix LISTXATTRS returning more bytes than maxcount

PATCH In review Jorge Mora 3 participants 3 messages Jan 25, 2024

Subsystems (2)
lore
Share & tools
lore

Jorge Mora

author
#0 lore raw

PATCH 1/1 NFSD: fix LISTXATTRS returning more bytes than maxcount

The maxcount is the maximum number of bytes for the LISTXATTRS4resok result. This includes the cookie and the count for the name array, thus subtract 12 bytes from the maxcount: 8 (cookie) + 4 (array count) when filling up the name array.

Fixes 23e50fe3a5e6 ("nfsd: implement the xattr functions and en/decode logic")
---
 fs/nfsd/nfs4xdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +2 -1
index 92c7dde148a4..17e6404f4296 100644
@@ -5168,7 +5168,8 @@ nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr,
 	sp = listxattrs->lsxa_buf;
 	nuser = 0;
 
-	xdrleft = listxattrs->lsxa_maxcount;
+	/* Bytes left is maxcount - 8 (cookie) - 4 (array count) */
+	xdrleft = listxattrs->lsxa_maxcount - 12;
 
 	while (left > 0 && xdrleft > 0) {
 		slen = strlen(sp);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Jorge Mora

The maxcount is the maximum number of bytes for the LISTXATTRS4resok result. This includes the cookie and the count for the name array, thus subtract 12 bytes from the maxcount: 8 (cookie) + 4 (array count) when filling up the name array.

Fixes 23e50fe3a5e6 ("nfsd: implement the xattr functions and en/decode logic")
---
 fs/nfsd/nfs4xdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +0 -0
index 92c7dde148a4..17e6404f4296 100644

fs/nfsd/nfs4xdr.c nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr, · line 5175

Quoted 9 lines
fs/nfsd/nfs4xdr.c +2 -1
@@ -5168,7 +5168,8 @@ nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr,
 	sp = listxattrs->lsxa_buf;
 	nuser = 0;
 
-	xdrleft = listxattrs->lsxa_maxcount;
+	/* Bytes left is maxcount - 8 (cookie) - 4 (array count) */
+	xdrleft = listxattrs->lsxa_maxcount - 12;
 
 	while (left > 0 && xdrleft > 0) {
 		slen = strlen(sp);

Nice catch!

#2 lore raw
In reply to Jorge Mora
Quoted 28 lines · Jorge Mora

The maxcount is the maximum number of bytes for the LISTXATTRS4resok result. This includes the cookie and the count for the name array, thus subtract 12 bytes from the maxcount: 8 (cookie) + 4 (array count) when filling up the name array.

Fixes 23e50fe3a5e6 ("nfsd: implement the xattr functions and en/decode logic")
---
 fs/nfsd/nfs4xdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +2 -1
index 92c7dde148a4..17e6404f4296 100644
@@ -5168,7 +5168,8 @@ nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr,
 	sp = listxattrs->lsxa_buf;
 	nuser = 0;
 
-	xdrleft = listxattrs->lsxa_maxcount;
+	/* Bytes left is maxcount - 8 (cookie) - 4 (array count) */
+	xdrleft = listxattrs->lsxa_maxcount - 12;
 
 	while (left > 0 && xdrleft > 0) {
 		slen = strlen(sp);
Signature · 1 line
2.43.0

All four applied to nfsd-next.

Note this checkpatch complaint:

WARNING: From:/Signed-off-by: email address mismatch:
'From: Jorge Mora <[email protected]>' != 'Signed-off-by: Jorge Mora <[email protected]>'

I'm not sure whether that mismatch is a critical problem. These look like good fixes and b4 says your DKIM is good, so I applied them anyway.

Signature · 1 line
Chuck Lever