Skip to contentSkip to conversation

net: check dev->addr_len for dev_set_mac_address()

PATCH Applied Cong Wang 2 participants 2 messages Jul 26, 2017 – Jul 29, 2017

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH v2 1/1 net: check dev->addr_len for dev_set_mac_address()

Historically, dev_ifsioc() uses struct sockaddr as mac address definition, this is why dev_set_mac_address() accepts a struct sockaddr pointer as input but now we have various types of mac addresse whose lengths are up to MAX_ADDR_LEN, longer than struct sockaddr, and saved in dev->addr_len.

It is too late to fix dev_ifsioc() due to API compatibility, so just reject those larger than sizeof(struct sockaddr), otherwise we would read and use some random bytes from kernel stack.

Fortunately, only a few IPv6 tunnel devices have addr_len larger than sizeof(struct sockaddr) and they don't support ndo_set_mac_addr(). But with team driver, in lb mode, they can still be enslaved to a team master and make its mac addr length as the same.

---
 net/core/dev_ioctl.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/dev_ioctl.c +2 -0
index 06b147d7d9e2..709a4e6fb447 100644
@@ -263,6 +263,8 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
 		return dev_set_mtu(dev, ifr->ifr_mtu);
 
 	case SIOCSIFHWADDR:
+		if (dev->addr_len > sizeof(struct sockaddr))
+			return -EINVAL;
 		return dev_set_mac_address(dev, &ifr->ifr_hwaddr);
 
 	case SIOCSIFHWBROADCAST:
Signature · 1 line
2.13.0
maintainer Applied
#1 lore raw

From: Cong Wang <[email protected]>
Date: Wed, 26 Jul 2017 15:22:06 -0700

Quoted 12 lines

Historically, dev_ifsioc() uses struct sockaddr as mac address definition, this is why dev_set_mac_address() accepts a struct sockaddr pointer as input but now we have various types of mac addresse whose lengths are up to MAX_ADDR_LEN, longer than struct sockaddr, and saved in dev->addr_len.

It is too late to fix dev_ifsioc() due to API compatibility, so just reject those larger than sizeof(struct sockaddr), otherwise we would read and use some random bytes from kernel stack.

Quoted 8 lines

Fortunately, only a few IPv6 tunnel devices have addr_len larger than sizeof(struct sockaddr) and they don't support ndo_set_mac_addr(). But with team driver, in lb mode, they can still be enslaved to a team master and make its mac addr length as the same.

Applied.