* [Linux-kernel-mentees] [PATCH v4] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
@ 2020-10-05 13:29 Anant Thazhemadam
2020-10-06 13:10 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Anant Thazhemadam @ 2020-10-05 13:29 UTC (permalink / raw)
Cc: Anant Thazhemadam, Petko Manolov, syzbot+abbc768b560c84d92fd3,
netdev, linux-usb, linux-kernel, joe, Jakub Kicinski,
linux-kernel-mentees, David S. Miller
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>
---
Changes in v4:
* Use netdev_notice() instead of dev_warn() and update the
logged message to show the new random MAC as well
(Suggested by Joe Perches <joe@perches.com>)
* Convert set_ethernet_addr()'s return type back to void.
Since we're not treating get_registers() (and thus
set_ethernet_addr()) failing as an erroneous condition,
we can perform the error handling (setting a random
ethernet address) that was being done in v3 within
set_ethernet_addr() itself.
(Suggested by Petko Manolov <petkan@nucleusys.com>)
Changes in v3:
* Set a random MAC address to the device rather than making
the device not work at all in the even set_ethernet_addr()
fails. (Suggested by David Miller <davem@davemloft.net>)
* Update set_ethernet_addr() to use ether_addr_copy() to copy
the MAC Address (instead of using memcpy() for that same).
(Suggested by Joe Perches <joe@perches.com>)
Changes in v2:
* Modified condition checking get_registers()'s return value to
ret == sizeof(node_id)
for stricter checking in compliance with the new
usb_control_msg_recv() API
(Suggested by Petko Manolov <petkan@nucleusys.com>)
* Added Acked-by: Petko Manolov
drivers/net/usb/rtl8150.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index 733f120c852b..9d079dc2a535 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -274,12 +274,20 @@ static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
return 1;
}
-static inline void set_ethernet_addr(rtl8150_t * dev)
+static void set_ethernet_addr(rtl8150_t *dev)
{
- u8 node_id[6];
+ u8 node_id[ETH_ALEN];
+ int ret;
+
+ ret = get_registers(dev, IDR, sizeof(node_id), node_id);
- get_registers(dev, IDR, sizeof(node_id), node_id);
- memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
+ if (ret == sizeof(node_id)) {
+ ether_addr_copy(dev->netdev->dev_addr, node_id);
+ } else {
+ eth_hw_addr_random(dev->netdev);
+ netdev_notice(dev->netdev, "Assigned a random MAC address: %pM\n",
+ dev->netdev->dev_addr);
+ }
}
static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
--
2.25.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH v4] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
2020-10-05 13:29 [Linux-kernel-mentees] [PATCH v4] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails Anant Thazhemadam
@ 2020-10-06 13:10 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-10-06 13:10 UTC (permalink / raw)
To: anant.thazhemadam
Cc: petkan, syzbot+abbc768b560c84d92fd3, netdev, linux-usb,
linux-kernel, joe, kuba, linux-kernel-mentees
From: Anant Thazhemadam <anant.thazhemadam@gmail.com>
Date: Mon, 5 Oct 2020 18:59:58 +0530
> 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>
Applied, thank you.
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-06 13:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05 13:29 [Linux-kernel-mentees] [PATCH v4] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails Anant Thazhemadam
2020-10-06 13:10 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).