Skip to content

Commit 2fcf868

Browse files
DanCh2020gregkh
authored andcommitted
RDMA/hns: Fix potential integer overflow in mhop hem cleanup
[ Upstream commit 9f0f2d2 ] In hns_roce_cleanup_mhop_hem_table(), the expression: obj = i * buf_chunk_size / table->obj_size; is evaluated using 32-bit unsigned arithmetic because 'buf_chunk_size' is u32 and the usual arithmetic conversions convert 'i' to unsigned int. The result is assigned to a u64 variable, but the multiplication may overflow before the assignment. For sufficiently large HEM tables, this produces an incorrect object index passed to hns_roce_table_mhop_put(). Cast 'i' to u64 before the multiplication so that the intermediate calculation is performed with 64-bit arithmetic. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: a25d13c ("RDMA/hns: Add the interfaces to support multi hop addressing for the contexts in hip08") Link: https://patch.msgid.link/r/20260627095951.51378-1-listdansp@mail.ru Signed-off-by: Danila Chernetsov <listdansp@mail.ru> Reviewed-by: Junxian Huang <huangjunxian6@hisilicon.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0e861c8 commit 2fcf868

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/infiniband/hw/hns/hns_roce_hem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ static void hns_roce_cleanup_mhop_hem_table(struct hns_roce_dev *hr_dev,
907907
mhop.bt_chunk_size;
908908

909909
for (i = 0; i < table->num_hem; ++i) {
910-
obj = i * buf_chunk_size / table->obj_size;
910+
obj = (u64)i * buf_chunk_size / table->obj_size;
911911
if (table->hem[i])
912912
hns_roce_table_mhop_put(hr_dev, table, obj, 0);
913913
}

0 commit comments

Comments
 (0)