Skip to contentSkip to conversation

net: dsa: mv88e6xxx: hwtstamp: fix potential negative array index read

PATCH Superseded Gustavo A. R. Silva 1 participant 1 message Feb 15, 2018

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: mv88e6xxx: hwtstamp: fix potential negative array index read

_port_ is being used as index to array port_hwtstamp before verifying it is a non-negative number and a valid index at 209:

if (port < 0 || port >= mv88e6xxx_num_ports(chip))

Fix this by checking _port_ before using it as index to array port_hwtstamp.

Addresses-Coverity-ID: 1465287 ("Negative array index read")

Fixes c6fe0ad2c349 ("net: dsa: mv88e6xxx: add rx/tx timestamping support")
---
 drivers/net/dsa/mv88e6xxx/hwtstamp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/dsa/mv88e6xxx/hwtstamp.c +5 -2
index b251d53..761decc 100644
@@ -200,8 +200,8 @@ int mv88e6xxx_port_hwtstamp_get(struct dsa_switch *ds, int port,
 				struct ifreq *ifr)
 {
 	struct mv88e6xxx_chip *chip = ds->priv;
-	struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
-	struct hwtstamp_config *config = &ps->tstamp_config;
+	struct mv88e6xxx_port_hwtstamp *ps;
+	struct hwtstamp_config *config;
 
 	if (!chip->info->ptp_support)
 		return -EOPNOTSUPP;
@@ -209,6 +209,9 @@ int mv88e6xxx_port_hwtstamp_get(struct dsa_switch *ds, int port,
 	if (port < 0 || port >= mv88e6xxx_num_ports(chip))
 		return -EINVAL;
 
+	ps = &chip->port_hwtstamp[port];
+	config = &ps->tstamp_config;
+
 	return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ?
 		-EFAULT : 0;
 }
Signature · 1 line
2.7.4