IB/mlx4: Test port number before querying type.
authorTarick Bedeir <tarick@google.com>
Mon, 2 Jul 2018 21:02:34 +0000 (14:02 -0700)
committerJason Gunthorpe <jgg@mellanox.com>
Wed, 4 Jul 2018 17:48:27 +0000 (11:48 -0600)
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 <tarick@google.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/mlx4/qp.c

index 984e9f0..408e720 100644 (file)
@@ -4047,9 +4047,9 @@ static void to_rdma_ah_attr(struct mlx4_ib_dev *ibdev,
        u8 port_num = path->sched_queue & 0x40 ? 2 : 1;
 
        memset(ah_attr, 0, sizeof(*ah_attr));
-       ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
        if (port_num == 0 || port_num > dev->caps.num_ports)
                return;
+       ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
 
        if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE)
                rdma_ah_set_sl(ah_attr, ((path->sched_queue >> 3) & 0x7) |