linux/drivers/usb
Marian Postevca d91ed251fd usb: gadget: u_ether: fix race in setting MAC address in setup phase
commit 890d5b4090 upstream.

When listening for notifications through netlink of a new interface being
registered, sporadically, it is possible for the MAC to be read as zero.
The zero MAC address lasts a short period of time and then switches to a
valid random MAC address.

This causes problems for netd in Android, which assumes that the interface
is malfunctioning and will not use it.

In the good case we get this log:
InterfaceController::getCfg() ifName usb0
 hwAddr 92:a8:f0:73:79:5b ipv4Addr 0.0.0.0 flags 0x1002

In the error case we get these logs:
InterfaceController::getCfg() ifName usb0
 hwAddr 00:00:00:00:00:00 ipv4Addr 0.0.0.0 flags 0x1002

netd : interfaceGetCfg("usb0")
netd : interfaceSetCfg() -> ServiceSpecificException
 (99, "[Cannot assign requested address] : ioctl() failed")

The reason for the issue is the order in which the interface is setup,
it is first registered through register_netdev() and after the MAC
address is set.

Fixed by first setting the MAC address of the net_device and after that
calling register_netdev().

Fixes: bcd4a1c40b ("usb: gadget: u_ether: construct with default values and add setters/getters")
Cc: stable@vger.kernel.org
Signed-off-by: Marian Postevca <posteuca@mutex.one>
Link: https://lore.kernel.org/r/20211204214912.17627-1-posteuca@mutex.one
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-12-29 12:26:05 +01:00
..
atm
c67x00
cdns3 usb: cdns3: fix race condition before setting doorbell 2021-10-06 15:55:46 +02:00
chipidea usb: chipidea: ci_hdrc_imx: fix potential error pointer dereference in probe 2021-12-01 09:18:59 +01:00
class USB: cdc-acm: fix break reporting 2021-10-13 10:04:23 +02:00
common Partially revert "usb: Kconfig: using select for USB_COMMON dependency" 2021-10-13 10:04:22 +02:00
core USB: NO_LPM quirk Lenovo USB-C to Ethernet Adapher(RTL8153-04) 2021-12-22 09:30:56 +01:00
dwc2 usb: dwc2: fix STM ID/VBUS detection startup delay in dwc2_driver_probe 2021-12-22 09:30:56 +01:00
dwc3 usb: dwc3: gadget: Fix null pointer exception 2021-12-01 09:18:59 +01:00
early Revert "usb: early: convert to readl_poll_timeout_atomic()" 2021-12-22 09:30:56 +01:00
gadget usb: gadget: u_ether: fix race in setting MAC address in setup phase 2021-12-29 12:26:05 +01:00
host usb: xhci: Extend support for runtime power management for AMD's Yellow carp. 2021-12-22 09:30:57 +01:00
image
isp1760
misc USB: iowarrior: fix control-message timeouts 2021-11-18 14:03:51 +01:00
mon
mtu3 usb: mtu3: fix the wrong HS mult value 2021-09-12 08:58:28 +02:00
musb usb: musb: tusb6010: check return value after calling platform_get_resource() 2021-11-26 10:39:08 +01:00
phy usb: phy: tahvo: add IRQ check 2021-09-15 09:50:40 +02:00
renesas_usbhs usb: renesas_usbhs: Fix superfluous irqs happen after usb_pkt_pop() 2021-07-28 14:35:44 +02:00
roles usb: roles: Call try_module_get() from usb_role_switch_find_by_fwnode() 2021-05-14 09:49:55 +02:00
serial USB: serial: option: add Telit FN990 compositions 2021-12-22 09:30:57 +01:00
storage usb-storage: Add compatibility quirk flags for iODD 2531/2541 2021-11-12 14:58:32 +01:00
typec usb: typec: tcpm: Wait in SNK_DEBOUNCED until disconnect 2021-12-08 09:03:28 +01:00
usbip usbip:vhci_hcd USB port can get stuck in the disabled state 2021-09-18 13:40:33 +02:00
Kconfig
Makefile
usb-skeleton.c