]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
nfsd4: fix oops on unusual readlike compound
authorJ. Bruce Fields <bfields@redhat.com>
Tue, 4 Dec 2012 23:25:10 +0000 (18:25 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Jan 2013 17:18:37 +0000 (09:18 -0800)
commit d5f50b0c290431c65377c4afa1c764e2c3fe5305 upstream.

If the argument and reply together exceed the maximum payload size, then
a reply with a read-like operation can overlow the rq_pages array.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nfsd/nfs4xdr.c

index fd548d1550882a78abb7cbe3e632bff6021f6030..ac6850f689430bf8f7917a86cbe14d803d36d898 100644 (file)
@@ -2946,11 +2946,16 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
        len = maxcount;
        v = 0;
        while (len > 0) {
-               pn = resp->rqstp->rq_resused++;
+               pn = resp->rqstp->rq_resused;
+               if (!resp->rqstp->rq_respages[pn]) { /* ran out of pages */
+                       maxcount -= len;
+                       break;
+               }
                resp->rqstp->rq_vec[v].iov_base =
                        page_address(resp->rqstp->rq_respages[pn]);
                resp->rqstp->rq_vec[v].iov_len =
                        len < PAGE_SIZE ? len : PAGE_SIZE;
+               resp->rqstp->rq_resused++;
                v++;
                len -= PAGE_SIZE;
        }
@@ -2996,6 +3001,8 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
                return nfserr;
        if (resp->xbuf->page_len)
                return nfserr_resource;
+       if (!resp->rqstp->rq_respages[resp->rqstp->rq_resused])
+               return nfserr_resource;
 
        page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]);
 
@@ -3045,6 +3052,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
                return nfserr;
        if (resp->xbuf->page_len)
                return nfserr_resource;
+       if (!resp->rqstp->rq_respages[resp->rqstp->rq_resused])
+               return nfserr_resource;
 
        RESERVE_SPACE(NFS4_VERIFIER_SIZE);
        savep = p;