linux-stable/drivers/usb/gadget
Marian Postevca 890d5b4090 usb: gadget: u_ether: fix race in setting MAC address in setup phase
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-13 15:22:23 +01:00
..
function usb: gadget: u_ether: fix race in setting MAC address in setup phase 2021-12-13 15:22:23 +01:00
legacy USB: gadget: zero allocate endpoint 0 buffers 2021-12-12 13:05:10 +01:00
udc usb: gadget: udc-xilinx: Fix an error handling path in 'xudc_probe()' 2021-11-17 15:02:34 +01:00
composite.c USB: gadget: zero allocate endpoint 0 buffers 2021-12-12 13:05:10 +01:00
config.c usb: fix various gadget panics on 10gbps cabling 2021-06-09 10:40:08 +02:00
configfs.c usb: gadget: configfs: change config attributes file operation 2021-10-22 11:18:26 +02:00
configfs.h
epautoconf.c usb: gadget: fix for a typo that conveys logically-inverted information. 2021-09-14 10:27:54 +02:00
functions.c
Kconfig usb: gadget: uvc: add scatter gather support 2021-07-27 15:59:19 +02:00
Makefile
u_f.c
u_f.h USB: gadget: u_f: Unbreak offset calculation in VLAs 2020-08-27 09:25:06 +02:00
u_os_desc.h
usbstring.c usb: gadget: fix langid kernel-doc warning in usbstring.c 2020-07-09 10:13:07 +03:00