Skip to contentSkip to conversation

davinci_emac: fix kernel oops when changing MAC address while interface is down

PATCH Applied Pablo Bitton 2 participants 2 messages Jul 7, 2009 – Jul 8, 2009

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

PATCH 1/1 davinci_emac: fix kernel oops when changing MAC address while interface is down

Check that network interface is running before changing its MAC address. Otherwise, rxch is accessed when it's NULL - causing a kernel oops. Moreover, check that the new MAC address is valid.

---
 drivers/net/davinci_emac.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/net/davinci_emac.c +10 -2
index cf689a0..dddb2b9 100644
@@ -1821,11 +1821,19 @@ static int emac_dev_setmac_addr(struct net_device *ndev, void *addr)
 	struct sockaddr *sa = addr;
 	DECLARE_MAC_BUF(mac);
 
+	if (!is_valid_ether_addr(sa->sa_data))
+		return -EINVAL;
+
 	/* Store mac addr in priv and rx channel and set it in EMAC hw */
 	memcpy(priv->mac_addr, sa->sa_data, ndev->addr_len);
-	memcpy(rxch->mac_addr, sa->sa_data, ndev->addr_len);
 	memcpy(ndev->dev_addr, sa->sa_data, ndev->addr_len);
-	emac_setmac(priv, EMAC_DEF_RX_CH, rxch->mac_addr);
+
+	/* If the interface is down - rxch is NULL. */
+	/* MAC address is configured only after the interface is enabled. */
+	if (netif_running(ndev)) {
+		memcpy(rxch->mac_addr, sa->sa_data, ndev->addr_len);
+		emac_setmac(priv, EMAC_DEF_RX_CH, rxch->mac_addr);
+	}
 
 	if (netif_msg_drv(priv))
 		dev_notice(emac_dev, "DaVinci EMAC: emac_dev_setmac_addr %s\n",
Signature · 1 line
1.5.4.3
maintainer Applied
#1 lore raw

From: Pablo Bitton <[email protected]>
Date: Tue, 07 Jul 2009 09:10:26 +0300

Quoted 8 lines

Check that network interface is running before changing its MAC address. Otherwise, rxch is accessed when it's NULL - causing a kernel oops. Moreover, check that the new MAC address is valid.

Applied to net-2.6, thanks.