Skip to content

Commit 0dbfaa9

Browse files
weiny2jgunthorpe
authored andcommitted
IB/hfi1: Fix SL array bounds check
The SL specified by a user needs to be a valid SL. Add a range check to the user specified SL value which protects from running off the end of the SL to SC table. CC: [email protected] Fixes: 7724105 ("IB/hfi1: add driver files") Signed-off-by: Ira Weiny <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 4eeed36 commit 0dbfaa9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/infiniband/hw/hfi1/verbs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,7 @@ static int hfi1_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
15821582
struct hfi1_pportdata *ppd;
15831583
struct hfi1_devdata *dd;
15841584
u8 sc5;
1585+
u8 sl;
15851586

15861587
if (hfi1_check_mcast(rdma_ah_get_dlid(ah_attr)) &&
15871588
!(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH))
@@ -1590,8 +1591,13 @@ static int hfi1_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
15901591
/* test the mapping for validity */
15911592
ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr));
15921593
ppd = ppd_from_ibp(ibp);
1593-
sc5 = ibp->sl_to_sc[rdma_ah_get_sl(ah_attr)];
15941594
dd = dd_from_ppd(ppd);
1595+
1596+
sl = rdma_ah_get_sl(ah_attr);
1597+
if (sl >= ARRAY_SIZE(ibp->sl_to_sc))
1598+
return -EINVAL;
1599+
1600+
sc5 = ibp->sl_to_sc[sl];
15951601
if (sc_to_vlt(dd, sc5) > num_vls && sc_to_vlt(dd, sc5) != 0xf)
15961602
return -EINVAL;
15971603
return 0;

0 commit comments

Comments
 (0)