Commit 6f6dbb81 authored by Dan Carpenter's avatar Dan Carpenter Committed by Jason Gunthorpe

RDMA/irdma: Prevent some integer underflows

My static checker complains that:

    drivers/infiniband/hw/irdma/ctrl.c:3605 irdma_sc_ceq_init()
    warn: can subtract underflow 'info->dev->hmc_fpm_misc.max_ceqs'?

It appears that "info->dev->hmc_fpm_misc.max_ceqs" comes from the firmware
in irdma_sc_parse_fpm_query_buf() so, yes, there is a chance that it could
be zero.  Even if we trust the firmware, it's easy enough to change the
condition just as a hardenning measure.

Fixes: 3f49d684 ("RDMA/irdma: Implement HW Admin Queue OPs")
Link: https://lore.kernel.org/r/20220307125928.GE16710@kiliSigned-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Acked-by: default avatarShiraz Saleem <shiraz.saleem@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 73f7e056
...@@ -454,7 +454,7 @@ int irdma_sc_qp_create(struct irdma_sc_qp *qp, struct irdma_create_qp_info *info ...@@ -454,7 +454,7 @@ int irdma_sc_qp_create(struct irdma_sc_qp *qp, struct irdma_create_qp_info *info
cqp = qp->dev->cqp; cqp = qp->dev->cqp;
if (qp->qp_uk.qp_id < cqp->dev->hw_attrs.min_hw_qp_id || if (qp->qp_uk.qp_id < cqp->dev->hw_attrs.min_hw_qp_id ||
qp->qp_uk.qp_id > (cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_QP].max_cnt - 1)) qp->qp_uk.qp_id >= cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_QP].max_cnt)
return -EINVAL; return -EINVAL;
wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch); wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
...@@ -2504,10 +2504,10 @@ static int irdma_sc_cq_create(struct irdma_sc_cq *cq, u64 scratch, ...@@ -2504,10 +2504,10 @@ static int irdma_sc_cq_create(struct irdma_sc_cq *cq, u64 scratch,
int ret_code = 0; int ret_code = 0;
cqp = cq->dev->cqp; cqp = cq->dev->cqp;
if (cq->cq_uk.cq_id > (cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_CQ].max_cnt - 1)) if (cq->cq_uk.cq_id >= cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_CQ].max_cnt)
return -EINVAL; return -EINVAL;
if (cq->ceq_id > (cq->dev->hmc_fpm_misc.max_ceqs - 1)) if (cq->ceq_id >= cq->dev->hmc_fpm_misc.max_ceqs)
return -EINVAL; return -EINVAL;
ceq = cq->dev->ceq[cq->ceq_id]; ceq = cq->dev->ceq[cq->ceq_id];
...@@ -3602,7 +3602,7 @@ int irdma_sc_ceq_init(struct irdma_sc_ceq *ceq, ...@@ -3602,7 +3602,7 @@ int irdma_sc_ceq_init(struct irdma_sc_ceq *ceq,
info->elem_cnt > info->dev->hw_attrs.max_hw_ceq_size) info->elem_cnt > info->dev->hw_attrs.max_hw_ceq_size)
return -EINVAL; return -EINVAL;
if (info->ceq_id > (info->dev->hmc_fpm_misc.max_ceqs - 1)) if (info->ceq_id >= info->dev->hmc_fpm_misc.max_ceqs)
return -EINVAL; return -EINVAL;
pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt; pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
...@@ -4148,7 +4148,7 @@ int irdma_sc_ccq_init(struct irdma_sc_cq *cq, struct irdma_ccq_init_info *info) ...@@ -4148,7 +4148,7 @@ int irdma_sc_ccq_init(struct irdma_sc_cq *cq, struct irdma_ccq_init_info *info)
info->num_elem > info->dev->hw_attrs.uk_attrs.max_hw_cq_size) info->num_elem > info->dev->hw_attrs.uk_attrs.max_hw_cq_size)
return -EINVAL; return -EINVAL;
if (info->ceq_id > (info->dev->hmc_fpm_misc.max_ceqs - 1)) if (info->ceq_id >= info->dev->hmc_fpm_misc.max_ceqs)
return -EINVAL; return -EINVAL;
pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt; pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment