Commit 04f16db0 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Greg Kroah-Hartman

IB/mlx5: Fix out-of-bound access

commit 0fd27a88 upstream.

When we initialize buffer to create SRQ in kernel,
the number of pages was less than actually used in
following mlx5_fill_page_array().

Fixes: e126ba97 ("mlx5: Add driver for Mellanox Connect-IB adapters")
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Reviewed-by: default avatarEli Cohen <eli@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2e539fa4
...@@ -165,8 +165,6 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq, ...@@ -165,8 +165,6 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq,
int err; int err;
int i; int i;
struct mlx5_wqe_srq_next_seg *next; struct mlx5_wqe_srq_next_seg *next;
int page_shift;
int npages;
err = mlx5_db_alloc(dev->mdev, &srq->db); err = mlx5_db_alloc(dev->mdev, &srq->db);
if (err) { if (err) {
...@@ -179,7 +177,6 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq, ...@@ -179,7 +177,6 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq,
err = -ENOMEM; err = -ENOMEM;
goto err_db; goto err_db;
} }
page_shift = srq->buf.page_shift;
srq->head = 0; srq->head = 0;
srq->tail = srq->msrq.max - 1; srq->tail = srq->msrq.max - 1;
...@@ -191,10 +188,8 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq, ...@@ -191,10 +188,8 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq,
cpu_to_be16((i + 1) & (srq->msrq.max - 1)); cpu_to_be16((i + 1) & (srq->msrq.max - 1));
} }
npages = DIV_ROUND_UP(srq->buf.npages, 1 << (page_shift - PAGE_SHIFT)); mlx5_ib_dbg(dev, "srq->buf.page_shift = %d\n", srq->buf.page_shift);
mlx5_ib_dbg(dev, "buf_size %d, page_shift %d, npages %d, calc npages %d\n", in->pas = mlx5_vzalloc(sizeof(*in->pas) * srq->buf.npages);
buf_size, page_shift, srq->buf.npages, npages);
in->pas = mlx5_vzalloc(sizeof(*in->pas) * npages);
if (!in->pas) { if (!in->pas) {
err = -ENOMEM; err = -ENOMEM;
goto err_buf; goto err_buf;
...@@ -210,7 +205,7 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq, ...@@ -210,7 +205,7 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq,
} }
srq->wq_sig = !!srq_signature; srq->wq_sig = !!srq_signature;
in->log_page_size = page_shift - MLX5_ADAPTER_PAGE_SHIFT; in->log_page_size = srq->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT;
if (MLX5_CAP_GEN(dev->mdev, cqe_version) == MLX5_CQE_VERSION_V1 && if (MLX5_CAP_GEN(dev->mdev, cqe_version) == MLX5_CQE_VERSION_V1 &&
in->type == IB_SRQT_XRC) in->type == IB_SRQT_XRC)
in->user_index = MLX5_IB_DEFAULT_UIDX; in->user_index = MLX5_IB_DEFAULT_UIDX;
......
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