nfs: cap request size to fit a kmalloced page array
authorChristoph Hellwig <hch@lst.de>
Thu, 21 Aug 2014 16:09:17 +0000 (11:09 -0500)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Wed, 10 Sep 2014 19:47:01 +0000 (12:47 -0700)
pNFS servers may return arbitrarily large layouts.  Trim back the I/O size
to one that we can at least allocate the page array for.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/pagelist.c

index be7cbce6e4c7a71c0fbd22a03193e20c9fec55ce..94e16ec88312a3c82857bbcf49815b66a3d5b14c 100644 (file)
@@ -481,6 +481,14 @@ size_t nfs_generic_pg_test(struct nfs_pageio_descriptor *desc,
                return 0;
        }
 
+       /*
+        * Limit the request size so that we can still allocate a page array
+        * for it without upsetting the slab allocator.
+        */
+       if (((desc->pg_count + req->wb_bytes) >> PAGE_SHIFT) *
+                       sizeof(struct page) > PAGE_SIZE)
+               return 0;
+
        return min(desc->pg_bsize - desc->pg_count, (size_t)req->wb_bytes);
 }
 EXPORT_SYMBOL_GPL(nfs_generic_pg_test);