Skip to content

Commit 0ccf70e

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 2c3b266 commit 0ccf70e

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
@@ -355,14 +355,14 @@ static int calc_hem_config(struct hns_roce_dev *hr_dev,
355355
bt_num = hns_roce_get_bt_num(table->type, mhop->hop_num);
356356
switch (bt_num) {
357357
case 3:
358-
index->l1 = l0_idx * chunk_ba_num + l1_idx;
358+
index->l1 = (u64)l0_idx * chunk_ba_num + l1_idx;
359359
index->l0 = l0_idx;
360-
index->buf = l0_idx * chunk_ba_num * chunk_ba_num +
361-
l1_idx * chunk_ba_num + l2_idx;
360+
index->buf = (u64)l0_idx * chunk_ba_num * chunk_ba_num +
361+
(u64)l1_idx * chunk_ba_num + l2_idx;
362362
break;
363363
case 2:
364364
index->l0 = l0_idx;
365-
index->buf = l0_idx * chunk_ba_num + l1_idx;
365+
index->buf = (u64)l0_idx * chunk_ba_num + l1_idx;
366366
break;
367367
case 1:
368368
index->buf = l0_idx;

0 commit comments

Comments
 (0)