Skip to content

Commit aa0de36

Browse files
Leon Romanovskydledford
authored andcommitted
RDMA/mlx5: Fix integer overflow while resizing CQ
The user can provide very large cqe_size which will cause to integer overflow as it can be seen in the following UBSAN warning: Signed-off-by: Doug Ledford <[email protected]>
1 parent 6a21dfc commit aa0de36

File tree

1 file changed

+6
-1
lines changed
  • drivers/infiniband/hw/mlx5

1 file changed

+6
-1
lines changed

drivers/infiniband/hw/mlx5/cq.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,12 @@ static int resize_user(struct mlx5_ib_dev *dev, struct mlx5_ib_cq *cq,
11781178
if (ucmd.reserved0 || ucmd.reserved1)
11791179
return -EINVAL;
11801180

1181-
umem = ib_umem_get(context, ucmd.buf_addr, entries * ucmd.cqe_size,
1181+
/* check multiplication overflow */
1182+
if (ucmd.cqe_size && SIZE_MAX / ucmd.cqe_size <= entries - 1)
1183+
return -EINVAL;
1184+
1185+
umem = ib_umem_get(context, ucmd.buf_addr,
1186+
(size_t)ucmd.cqe_size * entries,
11821187
IB_ACCESS_LOCAL_WRITE, 1);
11831188
if (IS_ERR(umem)) {
11841189
err = PTR_ERR(umem);

0 commit comments

Comments
 (0)