Message ID | 20210622175232.439-3-tatyana.e.nikolova@intel.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Jason Gunthorpe |
Headers | show |
Series | irdma coverity fixes | expand |
On Tue, Jun 22, 2021 at 12:52:31PM -0500, Tatyana Nikolova wrote: > From: Shiraz Saleem <shiraz.saleem@intel.com> > > iwmr->page_size stores the return from ib_umem_find_best_pgsz > and maybe zero when used in ib_umem_num_dma_blocks thus causing > a divide by zero error. > > Fix this by erroring out of irdma_reg_user when 0 is returned > from ib_umem_find_best_pgsz. > > Reported-by: coverity-bot <keescook+coverity-bot@chromium.org> > Addresses-Coverity-ID: 1505149 ("Integer handling issues") > Fixes: b48c24c2d710 ("RDMA/irdma: Implement device supported verb APIs") > Signed-off-by: Shiraz Saleem <shiraz.saleem@intel.com> > Signed-off-by: Tatyana Nikolova <tatyana.e.nikolova@intel.com> > --- > drivers/infiniband/hw/irdma/verbs.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) This patch applied to for-next, thanks Jason
diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c index 8bd31656a83a..2c4f67fac360 100644 --- a/drivers/infiniband/hw/irdma/verbs.c +++ b/drivers/infiniband/hw/irdma/verbs.c @@ -2782,10 +2782,16 @@ static struct ib_mr *irdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 len, iwmr->ibmr.iova = virt; iwmr->page_size = PAGE_SIZE; - if (req.reg_type == IRDMA_MEMREG_TYPE_MEM) + if (req.reg_type == IRDMA_MEMREG_TYPE_MEM) { iwmr->page_size = ib_umem_find_best_pgsz(region, SZ_4K | SZ_2M | SZ_1G, virt); + if (unlikely(!iwmr->page_size)) { + kfree(iwmr); + ib_umem_release(region); + return ERR_PTR(-EOPNOTSUPP); + } + } iwmr->len = region->length; iwpbl->user_base = virt; palloc = &iwpbl->pble_alloc;