]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
NFSD: fix LISTXATTRS returning more bytes than maxcount
authorJorge Mora <jmora1300@gmail.com>
Thu, 25 Jan 2024 14:42:23 +0000 (07:42 -0700)
committerChuck Lever <chuck.lever@oracle.com>
Fri, 1 Mar 2024 14:12:07 +0000 (09:12 -0500)
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>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4xdr.c

index 840ecd7eaf0713a674c3b877a84b7f71506e4de6..e3f761cd5ee78d2847efd8bc50d2feab5ee9f9f2 100644 (file)
@@ -5423,7 +5423,7 @@ nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr,
         */
        cookie_offset = xdr->buf->len;
        count_offset = cookie_offset + 8;
-       p = xdr_reserve_space(xdr, 12);
+       p = xdr_reserve_space(xdr, XDR_UNIT * 3);
        if (!p) {
                status = nfserr_resource;
                goto out;
@@ -5434,7 +5434,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 - XDR_UNIT * 3;
 
        while (left > 0 && xdrleft > 0) {
                slen = strlen(sp);