From: Christoph Hellwig Date: Thu, 21 Aug 2014 16:09:17 +0000 (-0500) Subject: nfs: cap request size to fit a kmalloced page array X-Git-Tag: v4.14-rc1~6630^2~61 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e11f8296d22134c4fca7eb022eea2b09facd307;p=platform%2Fkernel%2Flinux-rpi.git nfs: cap request size to fit a kmalloced page array 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 Signed-off-by: Trond Myklebust --- diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index be7cbce..94e16ec 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -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);