[PATCH rdma-next v2 2/3] RDMA/mlx5: Fix DEVX UMEM mailbox size truncation
From: Edward Srouji
Date: Wed Nov 11 2026 - 09:08:25 EST
From: Uri Dar <udar@xxxxxxxxxx>
devx_umem_reg_cmd_alloc() stores the CREATE_UMEM mailbox size, a header
plus 8 bytes per MTT, in the u32 cmd->inlen. The number of MTTs is
derived from the user-supplied length and pgsz_bitmap, so a UMEM of about
2TB registered with 4KB pages wraps the size, the mailbox is
under-allocated and mlx5_ib_populate_pas() writes past its end.
Compute the size with the saturating size_mul() and size_add() helpers
and reject a UMEM whose mailbox exceeds INT_MAX, the largest in_size
mlx5_cmd_exec() accepts.
Mailbox sizes within 512 bytes of INT_MAX still overflow the block count
in mlx5_calc_cmd_blocks(), but the command then fails with -ENOMEM
before reaching firmware. This predates the change.
Fixes: aeae94579caf ("IB/mlx5: Add DEVX support for memory registration")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Uri Dar <udar@xxxxxxxxxx>
Reviewed-by: Michael Gur <michaelgur@xxxxxxxxxx>
Signed-off-by: Edward Srouji <edwards@xxxxxxxxxx>
---
drivers/infiniband/hw/mlx5/devx.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
index 6c34f2c2a91d0be26352100c243f24789feab3db..030aa2cbdc2a7a5d0148de6af1bcd929ac7e444f 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -2338,6 +2338,8 @@ static int devx_umem_reg_cmd_alloc(struct mlx5_ib_dev *dev,
{
unsigned long pgsz_bitmap;
unsigned int page_size;
+ size_t num_mtt;
+ size_t inlen;
__be64 *mtt;
void *umem;
int ret;
@@ -2365,9 +2367,13 @@ static int devx_umem_reg_cmd_alloc(struct mlx5_ib_dev *dev,
if (!page_size)
return -EINVAL;
- cmd->inlen = MLX5_ST_SZ_BYTES(create_umem_in) +
- (MLX5_ST_SZ_BYTES(mtt) *
- ib_umem_num_dma_blocks(obj->umem, page_size));
+ num_mtt = ib_umem_num_dma_blocks(obj->umem, page_size);
+ inlen = size_add(MLX5_ST_SZ_BYTES(create_umem_in),
+ size_mul(MLX5_ST_SZ_BYTES(mtt), num_mtt));
+ if (inlen > INT_MAX)
+ return -EINVAL;
+
+ cmd->inlen = inlen;
cmd->in = uverbs_zalloc(attrs, cmd->inlen);
if (IS_ERR(cmd->in))
return PTR_ERR(cmd->in);
@@ -2376,8 +2382,7 @@ static int devx_umem_reg_cmd_alloc(struct mlx5_ib_dev *dev,
mtt = (__be64 *)MLX5_ADDR_OF(umem, umem, mtt);
MLX5_SET(create_umem_in, cmd->in, opcode, MLX5_CMD_OP_CREATE_UMEM);
- MLX5_SET64(umem, umem, num_of_mtt,
- ib_umem_num_dma_blocks(obj->umem, page_size));
+ MLX5_SET64(umem, umem, num_of_mtt, num_mtt);
MLX5_SET(umem, umem, log_page_size,
order_base_2(page_size) - MLX5_ADAPTER_PAGE_SHIFT);
MLX5_SET(umem, umem, page_offset,
--
2.49.0