Skip to content

Commit 2cd221f

Browse files
Alexander Chesnokovgregkh
authored andcommitted
RDMA/hns: Fix arithmetic overflow in calc_hem_config()
[ Upstream commit a38e441 ] If bt_num is 3 or 2, then the expressions like l0_idx * chunk_ba_num + l1_idx are computed in 32-bit arithmetic before being assigned to a u64 index field, which can lead to overflow. Cast the first operand to u64 to ensure the arithmetic is performed in 64-bit. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 2f49de2 ("RDMA/hns: Optimize mhop get flow for multi-hop addressing") Signed-off-by: Alexander Chesnokov <Alexander.Chesnokov@kaspersky.com> Link: https://patch.msgid.link/20260413091527.39990-1-Alexander.Chesnokov@kaspersky.com Signed-off-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 65e3449 commit 2cd221f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/infiniband/hw/hns/hns_roce_hem.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,14 @@ static int calc_hem_config(struct hns_roce_dev *hr_dev,
314314
bt_num = hns_roce_get_bt_num(table->type, mhop->hop_num);
315315
switch (bt_num) {
316316
case 3:
317-
index->l1 = l0_idx * chunk_ba_num + l1_idx;
317+
index->l1 = (u64)l0_idx * chunk_ba_num + l1_idx;
318318
index->l0 = l0_idx;
319-
index->buf = l0_idx * chunk_ba_num * chunk_ba_num +
320-
l1_idx * chunk_ba_num + l2_idx;
319+
index->buf = (u64)l0_idx * chunk_ba_num * chunk_ba_num +
320+
(u64)l1_idx * chunk_ba_num + l2_idx;
321321
break;
322322
case 2:
323323
index->l0 = l0_idx;
324-
index->buf = l0_idx * chunk_ba_num + l1_idx;
324+
index->buf = (u64)l0_idx * chunk_ba_num + l1_idx;
325325
break;
326326
case 1:
327327
index->buf = l0_idx;

0 commit comments

Comments
 (0)