Skip to content

Commit d9e49e9

Browse files
weiny2gregkh
authored andcommitted
IB/hfi1: Fix SL array bounds check
commit 0dbfaa9 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fcbe49c commit d9e49e9

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
@@ -1573,6 +1573,7 @@ static int hfi1_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
15731573
struct hfi1_pportdata *ppd;
15741574
struct hfi1_devdata *dd;
15751575
u8 sc5;
1576+
u8 sl;
15761577

15771578
if (hfi1_check_mcast(rdma_ah_get_dlid(ah_attr)) &&
15781579
!(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH))
@@ -1581,8 +1582,13 @@ static int hfi1_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
15811582
/* test the mapping for validity */
15821583
ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr));
15831584
ppd = ppd_from_ibp(ibp);
1584-
sc5 = ibp->sl_to_sc[rdma_ah_get_sl(ah_attr)];
15851585
dd = dd_from_ppd(ppd);
1586+
1587+
sl = rdma_ah_get_sl(ah_attr);
1588+
if (sl >= ARRAY_SIZE(ibp->sl_to_sc))
1589+
return -EINVAL;
1590+
1591+
sc5 = ibp->sl_to_sc[sl];
15861592
if (sc_to_vlt(dd, sc5) > num_vls && sc_to_vlt(dd, sc5) != 0xf)
15871593
return -EINVAL;
15881594
return 0;

0 commit comments

Comments
 (0)