mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Lijun Ou <oulijun@huawei.com>,
	"Wei Hu(Xavier)" <xavier.huwei@huawei.com>,
	Doug Ledford <dledford@redhat.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RDMA/hns: Use 64-bit arithmetic instead of 32-bit
Date: Mon, 22 Oct 2018 20:22:06 +0200	[thread overview]
Message-ID: <508a9428-53d3-2e2f-1e6a-44d9c67d31ed@embeddedor.com> (raw)
In-Reply-To: <20181022181523.GB30059@ziepe.ca>



On 10/22/18 8:15 PM, Jason Gunthorpe wrote:
> On Thu, Oct 18, 2018 at 10:02:58AM +0200, Gustavo A. R. Silva wrote:
>> Cast *max_num_sg* to u64 in order to give the compiler complete
>> information about the proper arithmetic to use.
>>
>> Notice that such variable is used in a context that expects an
>> expression of type u64 (64 bits, unsigned) and the following
>> expression is currently being evaluated using 32-bit
>> arithmetic:
>>
>> length = max_num_sg * page_size;
>>
>> Addresses-Coverity-ID: 1474517 ("Unintentional integer overflow")
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>>  drivers/infiniband/hw/hns/hns_roce_mr.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c
>> index 521ad2a..d479d5e 100644
>> +++ b/drivers/infiniband/hw/hns/hns_roce_mr.c
>> @@ -1219,7 +1219,7 @@ struct ib_mr *hns_roce_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
>>  	int ret;
>>  
>>  	page_size = 1 << (hr_dev->caps.pbl_buf_pg_sz + PAGE_SHIFT);
>> -	length = max_num_sg * page_size;
>> +	length = (u64)max_num_sg * page_size;
> 
> This should be done with check_mul_overflow() which will also force
> the input types to the correct thing.
> 

Yep, you're right. That's part of the new API for checking overflows.

I'll use that macro.

> alloc_mr is callable from userspace so the potential overflow here
> should not be ignored.
> 

Thanks for the feedback.
--
Gustavo


      reply	other threads:[~2018-10-22 18:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-18  8:02 Gustavo A. R. Silva
2018-10-18 11:01 ` Leon Romanovsky
2018-10-19  0:17   ` Doug Ledford
2018-10-29 10:07     ` Leon Romanovsky
2018-10-22 18:15 ` Jason Gunthorpe
2018-10-22 18:22   ` Gustavo A. R. Silva [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=508a9428-53d3-2e2f-1e6a-44d9c67d31ed@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=dledford@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=oulijun@huawei.com \
    --cc=xavier.huwei@huawei.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

all inboxes | Powered by JetHome®