NFSD: fix LISTXATTRS returning a short list with eof=TRUE
authorJorge Mora <jmora1300@gmail.com>
Thu, 25 Jan 2024 14:45:28 +0000 (07:45 -0700)
committerChuck Lever <chuck.lever@oracle.com>
Fri, 1 Mar 2024 14:12:07 +0000 (09:12 -0500)
If the XDR buffer is not large enough to fit all attributes
and the remaining bytes left in the XDR buffer (xdrleft) is
equal to the number of bytes for the current attribute, then
the loop will prematurely exit without setting eof to FALSE.
Also in this case, adding the eof flag to the buffer will
make the reply 4 bytes larger than lsxa_maxcount.

Need to check if there are enough bytes to fit not only the
next attribute name but also the eof as well.

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 5649076df4b4f7b9f5bc647e1ed5c28539200aa7..840ecd7eaf0713a674c3b877a84b7f71506e4de6 100644 (file)
@@ -5447,7 +5447,8 @@ nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr,
 
                slen -= XATTR_USER_PREFIX_LEN;
                xdrlen = 4 + ((slen + 3) & ~3);
-               if (xdrlen > xdrleft) {
+               /* Check if both entry and eof can fit in the XDR buffer */
+               if (xdrlen + XDR_UNIT > xdrleft) {
                        if (count == 0) {
                                /*
                                 * Can't even fit the first attribute name.