IB/core: Avoid unsigned int overflow in sg_alloc_table
authorMark Bloch <markb@mellanox.com>
Thu, 27 Oct 2016 13:36:31 +0000 (16:36 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 26 Nov 2016 08:54:54 +0000 (09:54 +0100)
commit 3c7ba5760ab8eedec01159b267bb9bfcffe522ac upstream.

sg_alloc_table gets unsigned int as parameter while the driver
returns it as size_t. Check npages isn't greater than maximum
unsigned int.

Fixes: eeb8461e36c9 ("IB: Refactor umem to use linear SG table")
Signed-off-by: Mark Bloch <markb@mellanox.com>
Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/infiniband/core/umem.c

index 38acb3cfc545f91658f0d465b69914de99f281b2..04f3c0db912654c1cff4aac76d7103bf90c1beb7 100644 (file)
@@ -175,7 +175,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
 
        cur_base = addr & PAGE_MASK;
 
-       if (npages == 0) {
+       if (npages == 0 || npages > UINT_MAX) {
                ret = -EINVAL;
                goto out;
        }