]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[PATCH] knfsd: fix an NFSD bug with full sized, non-page-aligned reads
authorNeilBrown <neilb@suse.de>
Fri, 26 Jan 2007 08:56:59 +0000 (00:56 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 26 Jan 2007 21:50:59 +0000 (13:50 -0800)
NFSd assumes that largest number of pages that will be needed for a
request+response is 2+N where N pages is the size of the largest permitted
read/write request.  The '2' are 1 for the non-data part of the request, and 1
for the non-data part of the reply.

However, when a read request is not page-aligned, and we choose to use
->sendfile to send it directly from the page cache, we may need N+1 pages to
hold the whole reply.  This can overflow and array and cause an Oops.

This patch increases size of the array for holding pages by one and makes sure
that entry is NULL when it is not in use.

Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/nfsd/vfs.c
include/linux/sunrpc/svc.h
net/sunrpc/svcsock.c

index 7a79c23aa6d4efe78bbfc03f6260ad64cf6ec589..ea855629a1c27e1a8018144db5b7d13542687d07 100644 (file)
@@ -822,7 +822,8 @@ nfsd_read_actor(read_descriptor_t *desc, struct page *page, unsigned long offset
                rqstp->rq_res.page_len = size;
        } else if (page != pp[-1]) {
                get_page(page);
-               put_page(*pp);
+               if (*pp)
+                       put_page(*pp);
                *pp = page;
                rqstp->rq_resused++;
                rqstp->rq_res.page_len += size;
index 965d6c20086ee2980ddee1f30e7d842df019a1df..64f3d60c72af2e918de63c2a28469176a1248dff 100644 (file)
@@ -144,8 +144,11 @@ extern u32 svc_max_payload(const struct svc_rqst *rqstp);
  *
  * Each request/reply pair can have at most one "payload", plus two pages,
  * one for the request, and one for the reply.
+ * We using ->sendfile to return read data, we might need one extra page
+ * if the request is not page-aligned.  So add another '1'.
  */
-#define RPCSVC_MAXPAGES                ((RPCSVC_MAXPAYLOAD+PAGE_SIZE-1)/PAGE_SIZE + 2)
+#define RPCSVC_MAXPAGES                ((RPCSVC_MAXPAYLOAD+PAGE_SIZE-1)/PAGE_SIZE \
+                               + 2 + 1)
 
 static inline u32 svc_getnl(struct kvec *iov)
 {
index 99f54fb6d66903ae9b9887c76e4138838f60a43a..45120f268d0366e17415702a244c46901bf634c7 100644 (file)
@@ -1278,6 +1278,8 @@ svc_recv(struct svc_rqst *rqstp, long timeout)
                                schedule_timeout_uninterruptible(msecs_to_jiffies(500));
                        rqstp->rq_pages[i] = p;
                }
+       rqstp->rq_pages[i++] = NULL; /* this might be seen in nfs_read_actor */
+       BUG_ON(pages >= RPCSVC_MAXPAGES);
 
        /* Make arg->head point to first page and arg->pages point to rest */
        arg = &rqstp->rq_arg;