Skip to content

Commit f45a424

Browse files
thazhemadamdavem330
authored andcommitted
net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
When get_registers() fails in set_ethernet_addr(),the uninitialized value of node_id gets copied over as the address. So, check the return value of get_registers(). If get_registers() executed successfully (i.e., it returns sizeof(node_id)), copy over the MAC address using ether_addr_copy() (instead of using memcpy()). Else, if get_registers() failed instead, a randomly generated MAC address is set as the MAC address instead. Reported-by: syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com Tested-by: syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com Acked-by: Petko Manolov <petkan@nucleusys.com> Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 017512a commit f45a424

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

drivers/net/usb/rtl8150.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,20 @@ static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
274274
return 1;
275275
}
276276

277-
static inline void set_ethernet_addr(rtl8150_t * dev)
277+
static void set_ethernet_addr(rtl8150_t *dev)
278278
{
279-
u8 node_id[6];
279+
u8 node_id[ETH_ALEN];
280+
int ret;
281+
282+
ret = get_registers(dev, IDR, sizeof(node_id), node_id);
280283

281-
get_registers(dev, IDR, sizeof(node_id), node_id);
282-
memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
284+
if (ret == sizeof(node_id)) {
285+
ether_addr_copy(dev->netdev->dev_addr, node_id);
286+
} else {
287+
eth_hw_addr_random(dev->netdev);
288+
netdev_notice(dev->netdev, "Assigned a random MAC address: %pM\n",
289+
dev->netdev->dev_addr);
290+
}
283291
}
284292

285293
static int rtl8150_set_mac_address(struct net_device *netdev, void *p)

0 commit comments

Comments
 (0)