Skip to content

Commit 42800fc

Browse files
rleongregkh
authored andcommitted
RDMA/core: Sanitize WQ state received from the userspace
[ Upstream commit f974428 ] The mlx4 and mlx5 implemented differently the WQ input checks. Instead of duplicating mlx4 logic in the mlx5, let's prepare the input in the central place. The mlx5 implementation didn't check for validity of state input. It is not real bug because our FW checked that, but still worth to fix. Fixes: f213c05 ("IB/uverbs: Add WQ support") Link: https://lore.kernel.org/r/ac41ad6a81b095b1a8ad453dcf62cf8d3c5da779.1621413310.git.leonro@nvidia.com Reported-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c470dd3 commit 42800fc

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎drivers/infiniband/core/uverbs_cmd.c‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,12 +3000,29 @@ static int ib_uverbs_ex_modify_wq(struct uverbs_attr_bundle *attrs)
30003000
if (!wq)
30013001
return -EINVAL;
30023002

3003-
wq_attr.curr_wq_state = cmd.curr_wq_state;
3004-
wq_attr.wq_state = cmd.wq_state;
30053003
if (cmd.attr_mask & IB_WQ_FLAGS) {
30063004
wq_attr.flags = cmd.flags;
30073005
wq_attr.flags_mask = cmd.flags_mask;
30083006
}
3007+
3008+
if (cmd.attr_mask & IB_WQ_CUR_STATE) {
3009+
if (cmd.curr_wq_state > IB_WQS_ERR)
3010+
return -EINVAL;
3011+
3012+
wq_attr.curr_wq_state = cmd.curr_wq_state;
3013+
} else {
3014+
wq_attr.curr_wq_state = wq->state;
3015+
}
3016+
3017+
if (cmd.attr_mask & IB_WQ_STATE) {
3018+
if (cmd.wq_state > IB_WQS_ERR)
3019+
return -EINVAL;
3020+
3021+
wq_attr.wq_state = cmd.wq_state;
3022+
} else {
3023+
wq_attr.wq_state = wq_attr.curr_wq_state;
3024+
}
3025+
30093026
ret = wq->device->ops.modify_wq(wq, &wq_attr, cmd.attr_mask,
30103027
&attrs->driver_udata);
30113028
rdma_lookup_put_uobject(&wq->uobject->uevent.uobject,

‎drivers/infiniband/hw/mlx4/qp.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4244,13 +4244,8 @@ int mlx4_ib_modify_wq(struct ib_wq *ibwq, struct ib_wq_attr *wq_attr,
42444244
if (wq_attr_mask & IB_WQ_FLAGS)
42454245
return -EOPNOTSUPP;
42464246

4247-
cur_state = wq_attr_mask & IB_WQ_CUR_STATE ? wq_attr->curr_wq_state :
4248-
ibwq->state;
4249-
new_state = wq_attr_mask & IB_WQ_STATE ? wq_attr->wq_state : cur_state;
4250-
4251-
if (cur_state < IB_WQS_RESET || cur_state > IB_WQS_ERR ||
4252-
new_state < IB_WQS_RESET || new_state > IB_WQS_ERR)
4253-
return -EINVAL;
4247+
cur_state = wq_attr->curr_wq_state;
4248+
new_state = wq_attr->wq_state;
42544249

42554250
if ((new_state == IB_WQS_RDY) && (cur_state == IB_WQS_ERR))
42564251
return -EINVAL;

‎drivers/infiniband/hw/mlx5/qp.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,10 +5236,8 @@ int mlx5_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr,
52365236

52375237
rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx);
52385238

5239-
curr_wq_state = (wq_attr_mask & IB_WQ_CUR_STATE) ?
5240-
wq_attr->curr_wq_state : wq->state;
5241-
wq_state = (wq_attr_mask & IB_WQ_STATE) ?
5242-
wq_attr->wq_state : curr_wq_state;
5239+
curr_wq_state = wq_attr->curr_wq_state;
5240+
wq_state = wq_attr->wq_state;
52435241
if (curr_wq_state == IB_WQS_ERR)
52445242
curr_wq_state = MLX5_RQC_STATE_ERR;
52455243
if (wq_state == IB_WQS_ERR)

0 commit comments

Comments
 (0)