linux/drivers/usb/gadget/function
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
..
Makefile
f_acm.c
f_ecm.c
f_eem.c
f_fs.c fs: get rid of the res2 iocb->ki_complete argument 2021-10-25 10:36:24 -06:00
f_hid.c usb: gadget: f_hid: optional SETUP/SET_REPORT mode 2021-08-24 15:41:08 +02:00
f_loopback.c
f_mass_storage.c usb: gadget: f_mass_storage: Disable eps during disconnect 2021-10-30 10:55:55 +02:00
f_mass_storage.h
f_midi.c
f_ncm.c usb: gadget: f_ncm: ncm_wrap_ntb - move var definitions into if statement 2021-07-21 10:04:19 +02:00
f_obex.c
f_phonet.c net: remove single-byte netdev->dev_addr writes 2021-10-13 10:03:59 -07:00
f_printer.c
f_rndis.c
f_serial.c
f_sourcesink.c
f_subset.c
f_tcm.c scsi: target: usb: Replace enable attr with ops.enable 2021-10-04 23:27:39 -04:00
f_uac1.c usb:gadget: f_uac1: fixed sync playback 2021-10-25 09:19:21 +02:00
f_uac1_legacy.c
f_uac2.c usb:gadget: f_uac1: fixed sync playback 2021-10-25 09:19:21 +02:00
f_uvc.c usb: gadget: uvc: ensure the vdev is unset 2021-10-21 12:58:57 +02:00
f_uvc.h
g_zero.h
ndis.h
rndis.c
rndis.h
storage_common.c
storage_common.h
tcm.h
u_audio.c usb: gadget: u_audio.c: Adding Playback Pitch ctl for sync playback 2021-10-13 13:59:43 +02:00
u_audio.h usb:gadget: f_uac1: fixed sync playback 2021-10-25 09:19:21 +02:00
u_ecm.h
u_eem.h
u_ether.c usb: gadget: u_ether: fix race in setting MAC address in setup phase 2021-12-13 15:22:23 +01:00
u_ether.h
u_ether_configfs.h
u_fs.h
u_gether.h
u_hid.h usb: gadget: f_hid: optional SETUP/SET_REPORT mode 2021-08-24 15:41:08 +02:00
u_midi.h
u_ncm.h
u_phonet.h
u_printer.h
u_rndis.h
u_serial.c Merge 5.14-rc5 into tty-next 2021-08-09 08:52:46 +02:00
u_serial.h
u_tcm.h
u_uac1.h usb: gadget: f_uac1: add volume and mute support 2021-07-21 10:10:11 +02:00
u_uac1_legacy.c
u_uac1_legacy.h
u_uac2.h usb:gadget: f_uac1: fixed sync playback 2021-10-25 09:19:21 +02:00
u_uvc.h
uvc.h usb: gadget: uvc: implement dwPresentationTime and scrSourceClock 2021-10-25 09:20:08 +02:00
uvc_configfs.c
uvc_configfs.h
uvc_queue.c usb: gadget: uvc: implement dwPresentationTime and scrSourceClock 2021-10-25 09:20:08 +02:00
uvc_queue.h usb: gadget: uvc: add scatter gather support 2021-07-27 15:59:19 +02:00
uvc_v4l2.c usb: gadget: uvc: only schedule stream in streaming state 2021-10-21 12:58:34 +02:00
uvc_v4l2.h
uvc_video.c usb: gadget: uvc: implement dwPresentationTime and scrSourceClock 2021-10-25 09:20:08 +02:00
uvc_video.h usb: gadget: uvc: consistently use define for headerlen 2021-10-21 12:53:31 +02:00