提交 a168a41c 编写于 作者: M Majd Dibbiny 提交者: Doug Ledford

IB/mlx5: Fix reqlen validation in mlx5_ib_alloc_ucontext

Older libraries that don't have all the new req_v2 fields
should be able to work as well. Today, if the library uses v2, it
will fail to allocate context since the size of reqlen is smaller
than the req_v2 size.

Fix the validation to be with the original req_v2 size and not
the current.

Fixes: f72300c5 ('IB/mlx5: Expose CQE version to user-space')
Signed-off-by: NMajd Dibbiny <majd@mellanox.com>
Signed-off-by: NDoug Ledford <dledford@redhat.com>
上级 d4584ddf
...@@ -844,6 +844,8 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev, ...@@ -844,6 +844,8 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
int err; int err;
int i; int i;
size_t reqlen; size_t reqlen;
size_t min_req_v2 = offsetof(struct mlx5_ib_alloc_ucontext_req_v2,
max_cqe_version);
if (!dev->ib_active) if (!dev->ib_active)
return ERR_PTR(-EAGAIN); return ERR_PTR(-EAGAIN);
...@@ -854,7 +856,7 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev, ...@@ -854,7 +856,7 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
reqlen = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr); reqlen = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr);
if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req)) if (reqlen == sizeof(struct mlx5_ib_alloc_ucontext_req))
ver = 0; ver = 0;
else if (reqlen >= sizeof(struct mlx5_ib_alloc_ucontext_req_v2)) else if (reqlen >= min_req_v2)
ver = 2; ver = 2;
else else
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册