diff mbox series

usbnet: use each random address only once

Message ID 20220629142149.1298-1-oneukum@suse.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series usbnet: use each random address only once | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: pabeni@redhat.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Oliver Neukum June 29, 2022, 2:21 p.m. UTC
Even random MACs should be unique to a device.
Get a new one each time it is used.

This bug is as old as the driver.

Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/net/usb/usbnet.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jakub Kicinski June 30, 2022, 3:50 a.m. UTC | #1
On Wed, 29 Jun 2022 16:21:49 +0200 Oliver Neukum wrote:
> Even random MACs should be unique to a device.
> Get a new one each time it is used.
> 
> This bug is as old as the driver.
> 
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> ---
>  drivers/net/usb/usbnet.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> index 02b915b1e142..a90aece93f4a 100644
> --- a/drivers/net/usb/usbnet.c
> +++ b/drivers/net/usb/usbnet.c
> @@ -1797,8 +1797,11 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
>  	}
>  
>  	/* let userspace know we have a random address */
> -	if (ether_addr_equal(net->dev_addr, node_id))
> +	if (ether_addr_equal(net->dev_addr, node_id)) {
>  		net->addr_assign_type = NET_ADDR_RANDOM;
> +		/* next device needs a new one*/
> +		eth_random_addr(node_id);
> +	}
>  
>  	if ((dev->driver_info->flags & FLAG_WLAN) != 0)
>  		SET_NETDEV_DEVTYPE(net, &wlan_type);

Why is that node_id thing even there, can we just delete it?

Leave the address as all-zero and check if driver filled it in with:

	if (!is_valid_ether_addr(net->dev_addr))
		eth_hw_addr_random(net->dev_addr);
diff mbox series

Patch

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 02b915b1e142..a90aece93f4a 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1797,8 +1797,11 @@  usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
 	}
 
 	/* let userspace know we have a random address */
-	if (ether_addr_equal(net->dev_addr, node_id))
+	if (ether_addr_equal(net->dev_addr, node_id)) {
 		net->addr_assign_type = NET_ADDR_RANDOM;
+		/* next device needs a new one*/
+		eth_random_addr(node_id);
+	}
 
 	if ((dev->driver_info->flags & FLAG_WLAN) != 0)
 		SET_NETDEV_DEVTYPE(net, &wlan_type);