Skip to content

Commit bada339

Browse files
Jeff GarzikDavid S. Miller
authored andcommitted
[NET]: Validate device addr prior to interface-up
Signed-off-by: Jeff Garzik <jgarzik@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c9927c2 commit bada339

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

include/linux/netdevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ struct net_device
669669
#define HAVE_SET_MAC_ADDR
670670
int (*set_mac_address)(struct net_device *dev,
671671
void *addr);
672+
#define HAVE_VALIDATE_ADDR
673+
int (*validate_addr)(struct net_device *dev);
672674
#define HAVE_PRIVATE_IOCTL
673675
int (*do_ioctl)(struct net_device *dev,
674676
struct ifreq *ifr, int cmd);

net/core/dev.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,17 +1007,20 @@ int dev_open(struct net_device *dev)
10071007
* Call device private open method
10081008
*/
10091009
set_bit(__LINK_STATE_START, &dev->state);
1010-
if (dev->open) {
1010+
1011+
if (dev->validate_addr)
1012+
ret = dev->validate_addr(dev);
1013+
1014+
if (!ret && dev->open)
10111015
ret = dev->open(dev);
1012-
if (ret)
1013-
clear_bit(__LINK_STATE_START, &dev->state);
1014-
}
10151016

10161017
/*
10171018
* If it went open OK then:
10181019
*/
10191020

1020-
if (!ret) {
1021+
if (ret)
1022+
clear_bit(__LINK_STATE_START, &dev->state);
1023+
else {
10211024
/*
10221025
* Set the flags.
10231026
*/
@@ -1038,6 +1041,7 @@ int dev_open(struct net_device *dev)
10381041
*/
10391042
call_netdevice_notifiers(NETDEV_UP, dev);
10401043
}
1044+
10411045
return ret;
10421046
}
10431047

net/ethernet/eth.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ static int eth_change_mtu(struct net_device *dev, int new_mtu)
298298
return 0;
299299
}
300300

301+
static int eth_validate_addr(struct net_device *dev)
302+
{
303+
if (!is_valid_ether_addr(dev->dev_addr))
304+
return -EINVAL;
305+
306+
return 0;
307+
}
308+
301309
const struct header_ops eth_header_ops ____cacheline_aligned = {
302310
.create = eth_header,
303311
.parse = eth_header_parse,
@@ -317,6 +325,7 @@ void ether_setup(struct net_device *dev)
317325

318326
dev->change_mtu = eth_change_mtu;
319327
dev->set_mac_address = eth_mac_addr;
328+
dev->validate_addr = eth_validate_addr;
320329

321330
dev->type = ARPHRD_ETHER;
322331
dev->hard_header_len = ETH_HLEN;

0 commit comments

Comments
 (0)