From: Mark Bloch Date: Thu, 27 Oct 2016 13:36:31 +0000 (+0300) Subject: IB/core: Avoid unsigned int overflow in sg_alloc_table X-Git-Tag: microblaze-4.13-rc1~1259^2~2^2~12 X-Git-Url: http://git.monstr.eu/?a=commitdiff_plain;h=3c7ba5760ab8eedec01159b267bb9bfcffe522ac;p=linux-2.6-microblaze.git IB/core: Avoid unsigned int overflow in sg_alloc_table 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 Signed-off-by: Maor Gottlieb Signed-off-by: Leon Romanovsky Signed-off-by: Doug Ledford --- diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 224ad274ea0b..84b4eff90395 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -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; }