linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/irdma: prevent some integer underflows
@ 2022-03-07 12:59 Dan Carpenter
  2022-03-08 16:45 ` Saleem, Shiraz
  2022-03-14 23:44 ` Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-03-07 12:59 UTC (permalink / raw)
  To: Mustafa Ismail
  Cc: Shiraz Saleem, Jason Gunthorpe, linux-rdma, kernel-janitors

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: 3f49d6842569 ("RDMA/irdma: Implement HW Admin Queue OPs")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/infiniband/hw/irdma/ctrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/infiniband/hw/irdma/ctrl.c b/drivers/infiniband/hw/irdma/ctrl.c
index 01cf75e9fd48..58c0e181ca2b 100644
--- a/drivers/infiniband/hw/irdma/ctrl.c
+++ b/drivers/infiniband/hw/irdma/ctrl.c
@@ -454,7 +454,7 @@ int irdma_sc_qp_create(struct irdma_sc_qp *qp, struct irdma_create_qp_info *info
 
 	cqp = qp->dev->cqp;
 	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;
 
 	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,
 	int ret_code = 0;
 
 	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;
 
-	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;
 
 	ceq = cq->dev->ceq[cq->ceq_id];
@@ -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)
 		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;
 	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)
 	    info->num_elem > info->dev->hw_attrs.uk_attrs.max_hw_cq_size)
 		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;
 
 	pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] RDMA/irdma: prevent some integer underflows
  2022-03-07 12:59 [PATCH] RDMA/irdma: prevent some integer underflows Dan Carpenter
@ 2022-03-08 16:45 ` Saleem, Shiraz
  2022-03-14 23:44 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Saleem, Shiraz @ 2022-03-08 16:45 UTC (permalink / raw)
  To: Dan Carpenter, Ismail, Mustafa
  Cc: Jason Gunthorpe, linux-rdma, kernel-janitors

> Subject: [PATCH] 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: 3f49d6842569 ("RDMA/irdma: Implement HW Admin Queue OPs")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/infiniband/hw/irdma/ctrl.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 

Seems reasonable.

Acked-by: Shiraz Saleem <shiraz.saleem@intel.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/irdma: prevent some integer underflows
  2022-03-07 12:59 [PATCH] RDMA/irdma: prevent some integer underflows Dan Carpenter
  2022-03-08 16:45 ` Saleem, Shiraz
@ 2022-03-14 23:44 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2022-03-14 23:44 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Mustafa Ismail, Shiraz Saleem, linux-rdma, kernel-janitors

On Mon, Mar 07, 2022 at 03:59:28PM +0300, Dan Carpenter wrote:
> 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: 3f49d6842569 ("RDMA/irdma: Implement HW Admin Queue OPs")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Acked-by: Shiraz Saleem <shiraz.saleem@intel.com>
> ---
>  drivers/infiniband/hw/irdma/ctrl.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

Applied to for-next, thanks

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-14 23:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 12:59 [PATCH] RDMA/irdma: prevent some integer underflows Dan Carpenter
2022-03-08 16:45 ` Saleem, Shiraz
2022-03-14 23:44 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).