Skip to contentSkip to conversation

NFSD: fix nfsd4_listxattr_validate_cookie

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

Subsystems (2)
lore
Share & tools
lore

Jorge Mora

author
#0 lore raw

PATCH 1/1 NFSD: fix nfsd4_listxattr_validate_cookie

If LISTXATTRS is sent with a correct cookie but a small maxcount, this could lead function nfsd4_listxattr_validate_cookie to return NFS4ERR_BAD_COOKIE. If maxcount = 20, then second check on function gives RHS = 3 thus any cookie larger than 3 returns NFS4ERR_BAD_COOKIE.

There is no need to validate the cookie on the return XDR buffer since attribute referenced by cookie will be the first in the return buffer.

Fixes 23e50fe3a5e6 ("nfsd: implement the xattr functions and en/decode logic")
---
 fs/nfsd/nfs4xdr.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/nfsd/nfs4xdr.c +1 -6
index 913d566519bf..7f957061c4d5 100644
@@ -5116,16 +5116,11 @@ nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs *listxattrs,
 
 	/*
 	 * If the cookie is larger than the maximum number we can fit
-	 * in either the buffer we just got back from vfs_listxattr, or,
-	 * XDR-encoded, in the return buffer, it's invalid.
+	 * in the buffer we just got back from vfs_listxattr, it's invalid.
 	 */
 	if (cookie > (listxattrs->lsxa_len) / (XATTR_USER_PREFIX_LEN + 2))
 		return nfserr_badcookie;
 
-	if (cookie > (listxattrs->lsxa_maxcount /
-		      (XDR_QUADLEN(XATTR_USER_PREFIX_LEN + 2) + 4)))
-		return nfserr_badcookie;
-
 	*offsetp = (u32)cookie;
 	return 0;
 }
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Jorge Mora

If LISTXATTRS is sent with a correct cookie but a small maxcount, this could lead function nfsd4_listxattr_validate_cookie to return NFS4ERR_BAD_COOKIE. If maxcount = 20, then second check on function gives RHS = 3 thus any cookie larger than 3 returns NFS4ERR_BAD_COOKIE.

There is no need to validate the cookie on the return XDR buffer since attribute referenced by cookie will be the first in the return buffer.

Fixes 23e50fe3a5e6 ("nfsd: implement the xattr functions and en/decode logic")
---
 fs/nfsd/nfs4xdr.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/nfsd/nfs4xdr.c +1 -2
index 913d566519bf..7f957061c4d5 100644
@@ -5116,16 +5116,11 @@ nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs *listxattrs,
 
 	/*
 	 * If the cookie is larger than the maximum number we can fit
-	 * in either the buffer we just got back from vfs_listxattr, or,
-	 * XDR-encoded, in the return buffer, it's invalid.
+	 * in the buffer we just got back from vfs_listxattr, it's invalid.
 	 */

fs/nfsd/nfs4xdr.c nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs *listxattrs, · line 5126

Quoted 10 lines
fs/nfsd/nfs4xdr.c +0 -4
 	if (cookie > (listxattrs->lsxa_len) / (XATTR_USER_PREFIX_LEN + 2))
 		return nfserr_badcookie;
 
-	if (cookie > (listxattrs->lsxa_maxcount /
-		      (XDR_QUADLEN(XATTR_USER_PREFIX_LEN + 2) + 4)))
-		return nfserr_badcookie;
-
 	*offsetp = (u32)cookie;
 	return 0;
 }

The cookie is generated by the server, and the client generates the maxcount value. They don't really have anything to do with one another, so yeah, I agree that this check is nonsensical.