diff mbox series

NFSD: fix LISTXATTRS returning more bytes than maxcount

Message ID 20240125144223.12725-1-mora@netapp.com (mailing list archive)
State New, archived
Headers show
Series NFSD: fix LISTXATTRS returning more bytes than maxcount | expand

Commit Message

Jorge Mora Jan. 25, 2024, 2:42 p.m. UTC
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")
Signed-off-by: Jorge Mora <mora@netapp.com>
---
 fs/nfsd/nfs4xdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Jeff Layton Jan. 25, 2024, 5:02 p.m. UTC | #1
On Thu, 2024-01-25 at 07:42 -0700, Jorge Mora wrote:
> 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")
> Signed-off-by: Jorge Mora <mora@netapp.com>
> ---
>  fs/nfsd/nfs4xdr.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> index 92c7dde148a4..17e6404f4296 100644
> --- a/fs/nfsd/nfs4xdr.c
> +++ b/fs/nfsd/nfs4xdr.c
> @@ -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!

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Chuck Lever Jan. 25, 2024, 6:03 p.m. UTC | #2
On Thu, Jan 25, 2024 at 07:42:23AM -0700, Jorge Mora wrote:
> 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")
> Signed-off-by: Jorge Mora <mora@netapp.com>
> ---
>  fs/nfsd/nfs4xdr.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> index 92c7dde148a4..17e6404f4296 100644
> --- a/fs/nfsd/nfs4xdr.c
> +++ b/fs/nfsd/nfs4xdr.c
> @@ -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);
> -- 
> 2.43.0
> 

All four applied to nfsd-next.

Note this checkpatch complaint:

WARNING: From:/Signed-off-by: email address mismatch:
  'From: Jorge Mora <jmora1300@gmail.com>' != 'Signed-off-by: Jorge Mora <mora@netapp.com>'

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.
diff mbox series

Patch

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 92c7dde148a4..17e6404f4296 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -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);