From 97313bf06a99274e93b2d08976767a4d485bf0fc Mon Sep 17 00:00:00 2001 From: Akiva Goldberger Date: Wed, 22 May 2024 09:31:06 +0300 Subject: [PATCH] mlx5: Fail in create_cq if uar_page_index size is unsupported [ Upstream commit 4513613fc11fc407ee89d1c4fb09fd5eea983eda ] The mlx5_ib_create_cq struct only has a 16 bit field for the uar page index. Therefore, if the caller attempts to create a CQ with a uar page index greater than or equal to 2^16, the function will fail explicitly to avoid overflowing the struct field. Fixes: 0c7212c09ad7 ("mlx5: Support dyn UAR for CQ") Signed-off-by: Akiva Goldberger Reviewed-by: Patrisious Haddad Signed-off-by: Yishai Hadas Signed-off-by: Nicolas Morey --- providers/mlx5/verbs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 4019a4725..44bb80158 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -1068,6 +1068,12 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *context, } if (mctx->cq_uar) { + if (mctx->cq_uar->page_id >= (1ul << 16)) { + mlx5_dbg(fp, MLX5_DBG_CQ, + "UAR page index larger than 16 bits is not supported\n"); + errno = EINVAL; + goto err_db; + } cmd_drv->flags |= MLX5_IB_CREATE_CQ_FLAGS_UAR_PAGE_INDEX; cmd_drv->uar_page_index = mctx->cq_uar->page_id; }