]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/hns: Fix potential integer overflow in mhop hem cleanup
authorDanila Chernetsov <listdansp@mail.ru>
Sat, 27 Jun 2026 09:59:51 +0000 (09:59 +0000)
committerJason Gunthorpe <jgg@nvidia.com>
Thu, 2 Jul 2026 17:24:15 +0000 (14:24 -0300)
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: a25d13cbe816 ("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>
drivers/infiniband/hw/hns/hns_roce_hem.c

index 7041a8e9134b220b428d37a51bd444a87d25610e..92edec4fa61b6c144b78af5b1dccd8a8e6d9e8fc 100644 (file)
@@ -836,7 +836,7 @@ static void hns_roce_cleanup_mhop_hem_table(struct hns_roce_dev *hr_dev,
                                        mhop.bt_chunk_size;
 
        for (i = 0; i < table->num_hem; ++i) {
-               obj = i * buf_chunk_size / table->obj_size;
+               obj = (u64)i * buf_chunk_size / table->obj_size;
                if (table->hem[i])
                        hns_roce_table_mhop_put(hr_dev, table, obj, 0);
        }