* [PATCH][next] RDMA/hns: fix potential integer overflow on left shift
@ 2019-06-24 21:46 Colin King
2019-06-25 13:19 ` Jason Gunthorpe
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2019-06-24 21:46 UTC (permalink / raw)
To: Lijun Ou, Wei Hu, Doug Ledford, Jason Gunthorpe, linux-rdma
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
There is a potential integer overflow when int i is left shifted
as this is evaluated using 32 bit arithmetic but is being used in
a context that expects an expression of type dma_addr_t. Fix this
by casting integer i to dma_addr_t before shifting to avoid the
overflow.
Addresses-Coverity: ("Unintentional integer overflow")
Fixes: 2ac0bc5e725e ("RDMA/hns: Add a group interfaces for optimizing buffers getting flow")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/infiniband/hw/hns/hns_roce_alloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_alloc.c b/drivers/infiniband/hw/hns/hns_roce_alloc.c
index 14fcc359599c..2c8defa94107 100644
--- a/drivers/infiniband/hw/hns/hns_roce_alloc.c
+++ b/drivers/infiniband/hw/hns/hns_roce_alloc.c
@@ -257,7 +257,7 @@ int hns_roce_get_kmem_bufs(struct hns_roce_dev *hr_dev, dma_addr_t *bufs,
for (i = start; i < end; i++)
if (buf->nbufs == 1)
bufs[total++] = buf->direct.map +
- (i << buf->page_shift);
+ ((dma_addr_t)i << buf->page_shift);
else
bufs[total++] = buf->page_list[i].map;
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] RDMA/hns: fix potential integer overflow on left shift
2019-06-24 21:46 [PATCH][next] RDMA/hns: fix potential integer overflow on left shift Colin King
@ 2019-06-25 13:19 ` Jason Gunthorpe
0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2019-06-25 13:19 UTC (permalink / raw)
To: Colin King
Cc: Lijun Ou, Wei Hu, Doug Ledford, linux-rdma, kernel-janitors,
linux-kernel
On Mon, Jun 24, 2019 at 10:46:08PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> There is a potential integer overflow when int i is left shifted
> as this is evaluated using 32 bit arithmetic but is being used in
> a context that expects an expression of type dma_addr_t. Fix this
> by casting integer i to dma_addr_t before shifting to avoid the
> overflow.
>
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 2ac0bc5e725e ("RDMA/hns: Add a group interfaces for optimizing buffers getting flow")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/infiniband/hw/hns/hns_roce_alloc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to for-next, thanks
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-25 13:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 21:46 [PATCH][next] RDMA/hns: fix potential integer overflow on left shift Colin King
2019-06-25 13:19 ` 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).