linux/drivers/usb
Norihiko Hama 6334b8e455 usb: gadget: f_ncm: Fix UAF ncm object at re-bind after usb ep transport error
When ncm function is working and then stop usb0 interface for link down,
eth_stop() is called. At this piont, accidentally if usb transport error
should happen in usb_ep_enable(), 'in_ep' and/or 'out_ep' may not be enabled.

After that, ncm_disable() is called to disable for ncm unbind
but gether_disconnect() is never called since 'in_ep' is not enabled.

As the result, ncm object is released in ncm unbind
but 'dev->port_usb' associated to 'ncm->port' is not NULL.

And when ncm bind again to recover netdev, ncm object is reallocated
but usb0 interface is already associated to previous released ncm object.

Therefore, once usb0 interface is up and eth_start_xmit() is called,
released ncm object is dereferrenced and it might cause use-after-free memory.

[function unlink via configfs]
  usb0: eth_stop dev->port_usb=ffffff9b179c3200
  --> error happens in usb_ep_enable().
  NCM: ncm_disable: ncm=ffffff9b179c3200
  --> no gether_disconnect() since ncm->port.in_ep->enabled is false.
  NCM: ncm_unbind: ncm unbind ncm=ffffff9b179c3200
  NCM: ncm_free: ncm free ncm=ffffff9b179c3200   <-- released ncm

[function link via configfs]
  NCM: ncm_alloc: ncm alloc ncm=ffffff9ac4f8a000
  NCM: ncm_bind: ncm bind ncm=ffffff9ac4f8a000
  NCM: ncm_set_alt: ncm=ffffff9ac4f8a000 alt=0
  usb0: eth_open dev->port_usb=ffffff9b179c3200  <-- previous released ncm
  usb0: eth_start dev->port_usb=ffffff9b179c3200 <--
  eth_start_xmit()
  --> dev->wrap()
  Unable to handle kernel paging request at virtual address dead00000000014f

This patch addresses the issue by checking if 'ncm->netdev' is not NULL at
ncm_disable() to call gether_disconnect() to deassociate 'dev->port_usb'.
It's more reasonable to check 'ncm->netdev' to call gether_connect/disconnect
rather than check 'ncm->port.in_ep->enabled' since it might not be enabled
but the gether connection might be established.

Signed-off-by: Norihiko Hama <Norihiko.Hama@alpsalpine.com>
Cc: stable <stable@kernel.org>
Link: https://lore.kernel.org/r/20240327023550.51214-1-Norihiko.Hama@alpsalpine.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-04 16:55:53 +02:00
..
atm usb: ueagle-atm: Use wait_event_freezable_timeout() in uea_wait() 2024-01-04 15:57:29 +01:00
c67x00 USB: c67x00: Remove unused declaration c67x00_hcd_msg_received() 2023-10-02 16:42:33 +02:00
cdns3 usb: cdns3: Fix spelling mistake "supporte" -> "supported" 2024-03-02 20:37:19 +01:00
chipidea usb: chipidea: core: handle power lost in workqueue 2024-01-27 16:39:14 -08:00
class usb: cdc-wdm: close race between read and workqueue 2024-03-26 14:56:33 +01:00
common usb: ulpi: Fix debugfs directory leak 2024-01-27 17:41:42 -08:00
core USB: core: Fix deadlock in port "disable" sysfs attribute 2024-03-26 15:02:28 +01:00
dwc2 usb: dwc2: gadget: LPM flow fix 2024-03-26 14:56:28 +01:00
dwc3 usb: dwc3: pci: Drop duplicate ID 2024-03-26 14:58:24 +01:00
early
fotg210 USB / Thunderbolt changes for 6.8-rc1 2024-01-18 11:43:55 -08:00
gadget usb: gadget: f_ncm: Fix UAF ncm object at re-bind after usb ep transport error 2024-04-04 16:55:53 +02:00
host xhci: Fix root hub port null pointer dereference in xhci tracepoints 2024-04-04 14:54:54 +02:00
image usb: image: mdc800: Remove redundant assignment to variable retval 2024-02-17 17:01:13 +01:00
isp1760 mm, slab: remove last vestiges of SLAB_MEM_SPREAD 2024-03-12 20:32:19 -07:00
misc usb: misc: ljca: Fix double free in error handling path 2024-03-26 11:01:23 +01:00
mon usb: mon: Fix atomicity violation in mon_bin_vma_fault 2024-01-05 10:36:08 +01:00
mtu3 usb: mtu3: Add MT8195 MTU3 ip-sleep wakeup support 2024-01-27 17:36:50 -08:00
musb usb: musb: remove unused variable 'count' 2024-03-05 13:25:16 +00:00
phy Revert "usb: phy: generic: Get the vbus supply" 2024-03-26 14:57:22 +01:00
renesas_usbhs
roles Merge v6.8-rc6 into usb-next 2024-02-26 06:53:50 +01:00
serial USB: serial: cp210x: add pid/vid for TDK NC0110013M and MM0110113M 2024-03-05 07:51:37 +01:00
storage USB: UAS: return ENODEV when submit urbs fail with device not attached 2024-03-26 10:50:56 +01:00
typec usb: typec: tcpm: Correct the PDO counting in pd_set 2024-04-04 16:30:31 +02:00
usbip USB: core: Use device_driver directly in struct usb_driver and usb_device_driver 2024-01-04 16:06:32 +01:00
Kconfig usb: pci-quirks: handle HAS_IOPORT dependency for AMD quirk 2023-10-02 16:19:12 +02:00
Makefile
usb-skeleton.c