public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Tatyana Nikolova <tatyana.e.nikolova@intel.com>
Cc: dledford@redhat.com, linux-rdma@vger.kernel.org,
	shiraz.saleem@intel.com, mustafa.ismail@intel.com,
	coverity-bot <keescook+coverity-bot@chromium.org>
Subject: Re: [PATCH rdma-next 3/3] RDMA/irdma: Fix potential overflow expression in irdma_prm_get_pbles
Date: Tue, 22 Jun 2021 15:07:14 -0300	[thread overview]
Message-ID: <20210622180714.GF2371267@nvidia.com> (raw)
In-Reply-To: <20210622175232.439-4-tatyana.e.nikolova@intel.com>

On Tue, Jun 22, 2021 at 12:52:32PM -0500, Tatyana Nikolova wrote:
> From: Shiraz Saleem <shiraz.saleem@intel.com>
> 
> Coverity reports a signed 32-bit overflow on "1 << pprm->pble_shift" when
> used expression to compute bits_needed that expects 64bit, unsigned.
> 
> Fix this by using the 1ULL in the left shift operator and convert
> mem_size to u64.
> 
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1505157 ("Integer handling issues")
> Fixes: 915cc7ac0f8e ("RDMA/irdma: Add miscellaneous utility definitions")
> Signed-off-by: Shiraz Saleem <shiraz.saleem@intel.com>
> Signed-off-by: Tatyana Nikolova <tatyana.e.nikolova@intel.com>
>  drivers/infiniband/hw/irdma/pble.h  | 2 +-
>  drivers/infiniband/hw/irdma/utils.c | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/irdma/pble.h b/drivers/infiniband/hw/irdma/pble.h
> index e4e635dc4fd9..e1b3b8118a2c 100644
> +++ b/drivers/infiniband/hw/irdma/pble.h
> @@ -121,7 +121,7 @@ enum irdma_status_code irdma_prm_add_pble_mem(struct irdma_pble_prm *pprm,
>  					      struct irdma_chunk *pchunk);
>  enum irdma_status_code
>  irdma_prm_get_pbles(struct irdma_pble_prm *pprm,
> -		    struct irdma_pble_chunkinfo *chunkinfo, u32 mem_size,
> +		    struct irdma_pble_chunkinfo *chunkinfo, u64 mem_size,
>  		    u64 **vaddr, u64 *fpm_addr);
>  void irdma_prm_return_pbles(struct irdma_pble_prm *pprm,
>  			    struct irdma_pble_chunkinfo *chunkinfo);
> diff --git a/drivers/infiniband/hw/irdma/utils.c b/drivers/infiniband/hw/irdma/utils.c
> index ea1df5918c11..e50b6f89b37e 100644
> +++ b/drivers/infiniband/hw/irdma/utils.c
> @@ -2314,7 +2314,7 @@ enum irdma_status_code irdma_prm_add_pble_mem(struct irdma_pble_prm *pprm,
>   */
>  enum irdma_status_code
>  irdma_prm_get_pbles(struct irdma_pble_prm *pprm,
> -		    struct irdma_pble_chunkinfo *chunkinfo, u32 mem_size,
> +		    struct irdma_pble_chunkinfo *chunkinfo, u64 mem_size,
>  		    u64 **vaddr, u64 *fpm_addr)
>  {
>  	u64 bits_needed;
> @@ -2326,7 +2326,7 @@ irdma_prm_get_pbles(struct irdma_pble_prm *pprm,
>  	*vaddr = NULL;
>  	*fpm_addr = 0;
>  
> -	bits_needed = (mem_size + (1 << pprm->pble_shift) - 1) >> pprm->pble_shift;
> +	bits_needed = (mem_size + BIT_ULL(pprm->pble_shift) - 1) >> pprm->pble_shift;

Isn't this just DIV_ROUND_UP_ULL() ?

Jason

      reply	other threads:[~2021-06-22 18:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 17:52 [PATCH rdma-next 0/3] irdma coverity fixes Tatyana Nikolova
2021-06-22 17:52 ` [PATCH rdma-next 1/3] RDMA/irdma: Check contents of user-space irdma_mem_reg_req object Tatyana Nikolova
2021-06-22 17:58   ` Jason Gunthorpe
2021-06-22 21:56     ` Nikolova, Tatyana E
2021-06-22 23:33       ` Jason Gunthorpe
2021-06-22 17:52 ` [PATCH rdma-next 2/3] RDMA/irdma: Check return value from ib_umem_find_best_pgsz Tatyana Nikolova
2021-06-22 18:28   ` Jason Gunthorpe
2021-06-22 17:52 ` [PATCH rdma-next 3/3] RDMA/irdma: Fix potential overflow expression in irdma_prm_get_pbles Tatyana Nikolova
2021-06-22 18:07   ` Jason Gunthorpe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210622180714.GF2371267@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=dledford@redhat.com \
    --cc=keescook+coverity-bot@chromium.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mustafa.ismail@intel.com \
    --cc=shiraz.saleem@intel.com \
    --cc=tatyana.e.nikolova@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox