Skip to content

Commit 36ab7ad

Browse files
PatrisiousHaddadjgunthorpe
authored andcommitted
RDMA/mlx5: Add check for srq max_sge attribute
max_sge attribute is passed by the user, and is inserted and used unchecked, so verify that the value doesn't exceed maximum allowed value before using it. Fixes: e126ba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") Signed-off-by: Patrisious Haddad <phaddad@nvidia.com> Link: https://lore.kernel.org/r/277ccc29e8d57bfd53ddeb2ac633f2760cf8cdd0.1716900410.git.leon@kernel.org Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 81497c1 commit 36ab7ad

File tree

1 file changed

+8
-5
lines changed
  • drivers/infiniband/hw/mlx5

1 file changed

+8
-5
lines changed

drivers/infiniband/hw/mlx5/srq.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,20 @@ int mlx5_ib_create_srq(struct ib_srq *ib_srq,
199199
int err;
200200
struct mlx5_srq_attr in = {};
201201
__u32 max_srq_wqes = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz);
202+
__u32 max_sge_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq) /
203+
sizeof(struct mlx5_wqe_data_seg);
202204

203205
if (init_attr->srq_type != IB_SRQT_BASIC &&
204206
init_attr->srq_type != IB_SRQT_XRC &&
205207
init_attr->srq_type != IB_SRQT_TM)
206208
return -EOPNOTSUPP;
207209

208-
/* Sanity check SRQ size before proceeding */
209-
if (init_attr->attr.max_wr >= max_srq_wqes) {
210-
mlx5_ib_dbg(dev, "max_wr %d, cap %d\n",
211-
init_attr->attr.max_wr,
212-
max_srq_wqes);
210+
/* Sanity check SRQ and sge size before proceeding */
211+
if (init_attr->attr.max_wr >= max_srq_wqes ||
212+
init_attr->attr.max_sge > max_sge_sz) {
213+
mlx5_ib_dbg(dev, "max_wr %d,wr_cap %d,max_sge %d, sge_cap:%d\n",
214+
init_attr->attr.max_wr, max_srq_wqes,
215+
init_attr->attr.max_sge, max_sge_sz);
213216
return -EINVAL;
214217
}
215218

0 commit comments

Comments
 (0)