lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu, 16 Nov 2023 13:30:24 +0100
From: Oliver Neukum <oneukum@...e.com>
To: netdev@...r.kernel.org,
	bjorn@...k.no
Cc: Oliver Neukum <oneukum@...e.com>
Subject: [RFC] usbnet: assign unique random MAC

The old method had the bug of issuing the same
random MAC over and over even to every device.
This bug is as old as the driver.

This new method generates each device whose minidriver
does not provide its own MAC its own unique random
MAC.

A module parameter to go back to the old behavior
is included.

Signed-off-by: Oliver Neukum <oneukum@...e.com>
---
 drivers/net/usb/usbnet.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 2d14b0d78541..53cb3a8d48c3 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -61,8 +61,10 @@
 
 /*-------------------------------------------------------------------------*/
 
-// randomly generated ethernet address
-static u8	node_id [ETH_ALEN];
+/* for the legacy behavior */
+
+u8 legacyrandomid[ETH_ALEN];
+static bool legacymac = false;
 
 /* use ethtool to change the level for any given device */
 static int msg_level = -1;
@@ -1731,7 +1733,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
 
 	dev->net = net;
 	strscpy(net->name, "usb%d", sizeof(net->name));
-	eth_hw_addr_set(net, node_id);
 
 	/* rx and tx sides can use different message sizes;
 	 * bind() should set rx_urb_size in that case.
@@ -1805,9 +1806,19 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
 		goto out4;
 	}
 
-	/* let userspace know we have a random address */
-	if (ether_addr_equal(net->dev_addr, node_id))
-		net->addr_assign_type = NET_ADDR_RANDOM;
+	/*
+	 * if the device does not come with a MAC
+	 * we ask the network core to generate us one
+	 * and flag the device accordingly
+	 */
+	if (!is_valid_ether_addr(net->dev_addr)) {
+		if (legacymac) {
+			eth_hw_addr_set(net, legacyrandomid);
+			net->addr_assign_type = NET_ADDR_RANDOM;
+		} else {
+			eth_hw_addr_random(net);
+		}
+	}
 
 	if ((dev->driver_info->flags & FLAG_WLAN) != 0)
 		SET_NETDEV_DEVTYPE(net, &wlan_type);
@@ -2217,7 +2228,7 @@ static int __init usbnet_init(void)
 	BUILD_BUG_ON(
 		sizeof_field(struct sk_buff, cb) < sizeof(struct skb_data));
 
-	eth_random_addr(node_id);
+	eth_random_addr(legacyrandomid);
 	return 0;
 }
 module_init(usbnet_init);
@@ -2227,6 +2238,8 @@ static void __exit usbnet_exit(void)
 }
 module_exit(usbnet_exit);
 
+module_param(legacymac, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(legacymac, "Use a legacy style common MAC if device need a random MAC");
 MODULE_AUTHOR("David Brownell");
 MODULE_DESCRIPTION("USB network driver framework");
 MODULE_LICENSE("GPL");
-- 
2.42.1


Powered by blists - more mailing lists