Skip to contentSkip to conversation

octeontx2-pf: Fix out-of-bounds read in otx2_get_fecparam()

PATCH Superseded Gustavo A. R. Silva 1 participant 1 message Feb 12, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 octeontx2-pf: Fix out-of-bounds read in otx2_get_fecparam()

Code at line 967 implies that rsp->fwdata.supported_fec may be up to 4:

967: if (rsp->fwdata.supported_fec <= FEC_MAX_INDEX)

If rsp->fwdata.supported_fec evaluates to 4, then there is an out-of-bounds read at line 971 because fec is an array with a maximum of 4 elements:

954 const int fec[] = {

 955                 ETHTOOL_FEC_OFF,
 956                 ETHTOOL_FEC_BASER,
 957                 ETHTOOL_FEC_RS,
 958                 ETHTOOL_FEC_BASER | ETHTOOL_FEC_RS};

959 #define FEC_MAX_INDEX 4

971: fecparam->fec = fec[rsp->fwdata.supported_fec];

Fix this by properly indexing fec[] with rsp->fwdata.supported_fec - 1. In this case the proper indexes 0 to 3 are used when rsp->fwdata.supported_fec evaluates to a range of 1 to 4, correspondingly.

Fixes d0cf9503e908 ("octeontx2-pf: ethtool fec mode support")

Addresses-Coverity-ID: 1501722 ("Out-of-bounds read")

---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +1 -1
index 237e5d3321d4..f7e8ada32a26 100644
@@ -968,7 +968,7 @@ static int otx2_get_fecparam(struct net_device *netdev,
 		if (!rsp->fwdata.supported_fec)
 			fecparam->fec = ETHTOOL_FEC_NONE;
 		else
-			fecparam->fec = fec[rsp->fwdata.supported_fec];
+			fecparam->fec = fec[rsp->fwdata.supported_fec - 1];
 	}
 	return 0;
 }
Signature · 1 line
2.27.0