net: fix rds_iovec page count overflow
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Oct 2010 15:40:55 +0000 (15:40 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 22 Apr 2011 15:44:32 +0000 (08:44 -0700)
commit 1b1f693d7ad6d193862dcb1118540a030c5e761f upstream.

As reported by Thomas Pollet, the rdma page counting can overflow.  We
get the rdma sizes in 64-bit unsigned entities, but then limit it to
UINT_MAX bytes and shift them down to pages (so with a possible "+1" for
an unaligned address).

So each individual page count fits comfortably in an 'unsigned int' (not
even close to overflowing into signed), but as they are added up, they
might end up resulting in a signed return value. Which would be wrong.

Catch the case of tot_pages turning negative, and return the appropriate
error code.

Reported-by: Thomas Pollet <thomas.pollet@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andy Grover <andy.grover@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[v2: nr is unsigned in the old code]
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Tim Gardner <tim.gardner@canonical.com>
Acked-by: Brad Figg <brad.figg@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
net/rds/rdma.c

index 6b09b941d3a77b220d88f288844aa15b7efa3362..ff5e3c998f58b0591a4d16f5b665d9c7986c0ae3 100644 (file)
@@ -473,6 +473,17 @@ static struct rds_rdma_op *rds_rdma_prepare(struct rds_sock *rs,
 
                max_pages = max(nr, max_pages);
                nr_pages += nr;
+
+               /*
+                * nr for one entry in limited to (UINT_MAX>>PAGE_SHIFT)+1
+                * so nr_pages cannot overflow without becoming bigger than
+                * INT_MAX first. If nr cannot overflow then max_pages should
+                * be ok.
+                */
+               if (nr_pages > INT_MAX) {
+                       ret = -EINVAL;
+                       goto out;
+               }
        }
 
        pages = kcalloc(max_pages, sizeof(struct page *), GFP_KERNEL);