From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-eopbgr730108.outbound.protection.outlook.com ([40.107.73.108]:57545 "EHLO NAM05-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728803AbeIQI0V (ORCPT ); Mon, 17 Sep 2018 04:26:21 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Tarick Bedeir , Jason Gunthorpe , Sasha Levin Subject: [PATCH AUTOSEL 4.18 035/136] IB/mlx4: Test port number before querying type. Date: Mon, 17 Sep 2018 03:00:34 +0000 Message-ID: <20180917030006.245495-35-alexander.levin@microsoft.com> References: <20180917030006.245495-1-alexander.levin@microsoft.com> In-Reply-To: <20180917030006.245495-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Tarick Bedeir [ Upstream commit f1228867adaf8890826f2b59e4caddb1c5cc2df7 ] rdma_ah_find_type() can reach into ib_device->port_immutable with a potentially out-of-bounds port number, so check that the port number is valid first. Fixes: 44c58487d51a ("IB/core: Define 'ib' and 'roce' rdma_ah_attr types") Signed-off-by: Tarick Bedeir Reviewed-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/mlx4/qp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/q= p.c index 3b8045fd23ed..b94e33a56e97 100644 --- a/drivers/infiniband/hw/mlx4/qp.c +++ b/drivers/infiniband/hw/mlx4/qp.c @@ -4047,9 +4047,9 @@ static void to_rdma_ah_attr(struct mlx4_ib_dev *ibdev= , u8 port_num =3D path->sched_queue & 0x40 ? 2 : 1; =20 memset(ah_attr, 0, sizeof(*ah_attr)); - ah_attr->type =3D rdma_ah_find_type(&ibdev->ib_dev, port_num); if (port_num =3D=3D 0 || port_num > dev->caps.num_ports) return; + ah_attr->type =3D rdma_ah_find_type(&ibdev->ib_dev, port_num); =20 if (ah_attr->type =3D=3D RDMA_AH_ATTR_TYPE_ROCE) rdma_ah_set_sl(ah_attr, ((path->sched_queue >> 3) & 0x7) | --=20 2.17.1