linux/drivers/infiniband
Aleksandrova Alyona 3cda0dfe8c RDMA/irdma: Prevent overflows in memory contiguity checks
irdma_check_mem_contiguous() and irdma_check_mr_contiguous() verify that
PBL entries describe physically contiguous memory ranges.

Both functions calculate byte offsets using 32-bit operands. For example,
with 4 KiB pages, pg_size * pg_idx overflows 32-bit arithmetic when
pg_idx reaches 1048576. In the level-2 check, PBLE_PER_PAGE is 512, so
i * pg_size * PBLE_PER_PAGE overflows when i reaches 2048.

These values are reachable in the driver. For MRs, palloc->total_cnt
comes from iwmr->page_cnt, which is calculated by
ib_umem_num_dma_blocks(). The MR size is limited by IRDMA_MAX_MR_SIZE,
so a 4 GiB MR with 4 KiB pages can reach page_cnt of 1048576. PBLE
resources do not exclude this value either: for gen3, the limit is based
on avail_sds * MAX_PBLE_PER_SD, and MAX_PBLE_PER_SD is 0x40000, so 4 SDs
are enough for 1048576 PBLEs.

Cast one operand to u64 before the multiplications so that the offset
calculations are performed in 64-bit arithmetic.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: b48c24c2d7 ("RDMA/irdma: Implement device supported verb APIs")
Signed-off-by: Aleksandrova Alyona <aga@itb.spb.ru>
Link: https://patch.msgid.link/20260624144846.61242-1-aga@itb.spb.ru
Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-07-05 07:02:35 -04:00
..
core RDMA/core: Fix memory leak in __ib_create_cq() on invalid cqe 2026-07-02 14:19:33 -03:00
hw RDMA/irdma: Prevent overflows in memory contiguity checks 2026-07-05 07:02:35 -04:00
sw RDMA/siw: publish QP after initialization 2026-07-02 14:37:03 -03:00
ulp RDMA v7.2 merge window 2026-06-18 08:16:21 -07:00
Kconfig RDMA/core: Do not compile ib_core_uverbs without USER_ACCESS 2026-05-26 10:07:25 -03:00
Makefile treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00