sqrq_state_to_qp_state() indexes the 5x5 sqrq_trans[] table with the RQ and SQ states returned by QUERY_RQ and QUERY_SQ. The state fields are 4 bits wide, so an untrusted NIC can return a state above 4 and the lookup reads past the table. Reject out of range states with -EIO before the lookup. Signed-off-by: Yishai Hadas --- drivers/infiniband/hw/mlx5/qp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c index 19cbf6b2b979..05e8e75d734f 100644 --- a/drivers/infiniband/hw/mlx5/qp.c +++ b/drivers/infiniband/hw/mlx5/qp.c @@ -5081,6 +5081,9 @@ static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, }, }; + if (sq_state >= MLX5_SQ_NUM_STATE || rq_state >= MLX5_RQ_NUM_STATE) + return -EIO; + *qp_state = sqrq_trans[rq_state][sq_state]; if (*qp_state == MLX5_QP_STATE_BAD) { -- 2.18.1