Skip to contentSkip to conversation

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

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

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

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

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

which would cause an out-of-bounds read at line 971:

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

However, the range of values for rsp->fwdata.supported_fec is 0 to 3. Fix the if condition at line 967, accordingly.

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

---
Changes in v2:
- Fix if condition.

 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..f4962a97a075 100644
@@ -964,7 +964,7 @@ static int otx2_get_fecparam(struct net_device *netdev,
 	if (IS_ERR(rsp))
 		return PTR_ERR(rsp);
 
-	if (rsp->fwdata.supported_fec <= FEC_MAX_INDEX) {
+	if (rsp->fwdata.supported_fec < FEC_MAX_INDEX) {
 		if (!rsp->fwdata.supported_fec)
 			fecparam->fec = ETHTOOL_FEC_NONE;
 		else
Signature · 1 line
2.27.0