linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5.15] usb: gadget: u_ether: fix regression in setting fixed MAC address
@ 2022-06-22 20:18 Marian Postevca
  2022-06-23 15:52 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Marian Postevca @ 2022-06-22 20:18 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman
  Cc: Marian Postevca, Maximilian Senftleben, stable, linux-usb, linux-kernel

commit b337af3a4d6147000b7ca6b3438bf5c820849b37 upstream.

In systemd systems setting a fixed MAC address through
the "dev_addr" module argument fails systematically.
When checking the MAC address after the interface is created
it always has the same but different MAC address to the one
supplied as argument.

This is partially caused by systemd which by default will
set an internally generated permanent MAC address for interfaces
that are marked as having a randomly generated address.

Commit 890d5b40908bfd1a ("usb: gadget: u_ether: fix race in
setting MAC address in setup phase") didn't take into account
the fact that the interface must be marked as having a set
MAC address when it's set as module argument.

Fixed by marking the interface with NET_ADDR_SET when
the "dev_addr" module argument is supplied.

Reported-by: Maximilian Senftleben <kernel@mail.msdigital.de>
Cc: stable@vger.kernel.org
Fixes: 890d5b40908bfd1a ("usb: gadget: u_ether: fix race in setting MAC address in setup phase")
Signed-off-by: Marian Postevca <posteuca@mutex.one>
---
 drivers/usb/gadget/function/u_ether.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index d15a54f6c24b9..ef253599dcf96 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -774,9 +774,13 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g,
 	dev->qmult = qmult;
 	snprintf(net->name, sizeof(net->name), "%s%%d", netname);
 
-	if (get_ether_addr(dev_addr, net->dev_addr))
+	if (get_ether_addr(dev_addr, net->dev_addr)) {
+		net->addr_assign_type = NET_ADDR_RANDOM;
 		dev_warn(&g->dev,
 			"using random %s ethernet address\n", "self");
+	} else {
+		net->addr_assign_type = NET_ADDR_SET;
+	}
 	if (get_ether_addr(host_addr, dev->host_mac))
 		dev_warn(&g->dev,
 			"using random %s ethernet address\n", "host");
@@ -833,6 +837,9 @@ struct net_device *gether_setup_name_default(const char *netname)
 	INIT_LIST_HEAD(&dev->tx_reqs);
 	INIT_LIST_HEAD(&dev->rx_reqs);
 
+	/* by default we always have a random MAC address */
+	net->addr_assign_type = NET_ADDR_RANDOM;
+
 	skb_queue_head_init(&dev->rx_frames);
 
 	/* network device setup */
@@ -869,7 +876,6 @@ int gether_register_netdev(struct net_device *net)
 	dev = netdev_priv(net);
 	g = dev->gadget;
 
-	net->addr_assign_type = NET_ADDR_RANDOM;
 	eth_hw_addr_set(net, dev->dev_mac);
 
 	status = register_netdev(net);
@@ -910,6 +916,7 @@ int gether_set_dev_addr(struct net_device *net, const char *dev_addr)
 	if (get_ether_addr(dev_addr, new_addr))
 		return -EINVAL;
 	memcpy(dev->dev_mac, new_addr, ETH_ALEN);
+	net->addr_assign_type = NET_ADDR_SET;
 	return 0;
 }
 EXPORT_SYMBOL_GPL(gether_set_dev_addr);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 5.15] usb: gadget: u_ether: fix regression in setting fixed MAC address
  2022-06-22 20:18 [PATCH 5.15] usb: gadget: u_ether: fix regression in setting fixed MAC address Marian Postevca
@ 2022-06-23 15:52 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2022-06-23 15:52 UTC (permalink / raw)
  To: Marian Postevca
  Cc: Felipe Balbi, Maximilian Senftleben, stable, linux-usb, linux-kernel

On Wed, Jun 22, 2022 at 11:18:04PM +0300, Marian Postevca wrote:
> commit b337af3a4d6147000b7ca6b3438bf5c820849b37 upstream.
> 
> In systemd systems setting a fixed MAC address through
> the "dev_addr" module argument fails systematically.
> When checking the MAC address after the interface is created
> it always has the same but different MAC address to the one
> supplied as argument.
> 
> This is partially caused by systemd which by default will
> set an internally generated permanent MAC address for interfaces
> that are marked as having a randomly generated address.
> 
> Commit 890d5b40908bfd1a ("usb: gadget: u_ether: fix race in
> setting MAC address in setup phase") didn't take into account
> the fact that the interface must be marked as having a set
> MAC address when it's set as module argument.
> 
> Fixed by marking the interface with NET_ADDR_SET when
> the "dev_addr" module argument is supplied.
> 
> Reported-by: Maximilian Senftleben <kernel@mail.msdigital.de>
> Cc: stable@vger.kernel.org
> Fixes: 890d5b40908bfd1a ("usb: gadget: u_ether: fix race in setting MAC address in setup phase")
> Signed-off-by: Marian Postevca <posteuca@mutex.one>
> ---
>  drivers/usb/gadget/function/u_ether.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)

All now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-23 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22 20:18 [PATCH 5.15] usb: gadget: u_ether: fix regression in setting fixed MAC address Marian Postevca
2022-06-23 15:52 ` Greg Kroah-Hartman

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).