Commit d50b3c73 authored by Dan Carpenter's avatar Dan Carpenter Committed by Leon Romanovsky

RDMA/mlx4: Prevent shift wrapping in set_user_sq_size()

The ucmd->log_sq_bb_count variable is controlled by the user so this
shift can wrap.  Fix it by using check_shl_overflow() in the same way
that it was done in commit 515f6000 ("RDMA/hns: Prevent undefined
behavior in hns_roce_set_user_sq_size()").

Fixes: 83904132 ("IB/mlx4: Sanity check userspace send queue sizes")
Signed-off-by: default avatarDan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/r/a8dfbd1d-c019-4556-930b-bab1ded73b10@kili.mountainSigned-off-by: default avatarLeon Romanovsky <leon@kernel.org>
parent faa63656
...@@ -447,9 +447,13 @@ static int set_user_sq_size(struct mlx4_ib_dev *dev, ...@@ -447,9 +447,13 @@ static int set_user_sq_size(struct mlx4_ib_dev *dev,
struct mlx4_ib_qp *qp, struct mlx4_ib_qp *qp,
struct mlx4_ib_create_qp *ucmd) struct mlx4_ib_create_qp *ucmd)
{ {
u32 cnt;
/* Sanity check SQ size before proceeding */ /* Sanity check SQ size before proceeding */
if ((1 << ucmd->log_sq_bb_count) > dev->dev->caps.max_wqes || if (check_shl_overflow(1, ucmd->log_sq_bb_count, &cnt) ||
ucmd->log_sq_stride > cnt > dev->dev->caps.max_wqes)
return -EINVAL;
if (ucmd->log_sq_stride >
ilog2(roundup_pow_of_two(dev->dev->caps.max_sq_desc_sz)) || ilog2(roundup_pow_of_two(dev->dev->caps.max_sq_desc_sz)) ||
ucmd->log_sq_stride < MLX4_IB_MIN_SQ_STRIDE) ucmd->log_sq_stride < MLX4_IB_MIN_SQ_STRIDE)
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment