1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/drivers/usb/gadget/udc
Alan Stern 65dadb2bee USB: Gadget: core: Help prevent panic during UVC unconfigure
Avichal Rakesh reported a kernel panic that occurred when the UVC
gadget driver was removed from a gadget's configuration.  The panic
involves a somewhat complicated interaction between the kernel driver
and a userspace component (as described in the Link tag below), but
the analysis did make one thing clear: The Gadget core should
accomodate gadget drivers calling usb_gadget_deactivate() as part of
their unbind procedure.

Currently this doesn't work.  gadget_unbind_driver() calls
driver->unbind() while holding the udc->connect_lock mutex, and
usb_gadget_deactivate() attempts to acquire that mutex, which will
result in a deadlock.

The simple fix is for gadget_unbind_driver() to release the mutex when
invoking the ->unbind() callback.  There is no particular reason for
it to be holding the mutex at that time, and the mutex isn't held
while the ->bind() callback is invoked.  So we'll drop the mutex
before performing the unbind callback and reacquire it afterward.

We'll also add a couple of comments to usb_gadget_activate() and
usb_gadget_deactivate().  Because they run in process context they
must not be called from a gadget driver's ->disconnect() callback,
which (according to the kerneldoc for struct usb_gadget_driver in
include/linux/usb/gadget.h) may run in interrupt context.  This may
help prevent similar bugs from arising in the future.

Reported-and-tested-by: Avichal Rakesh <arakesh@google.com>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Fixes: 286d9975a8 ("usb: gadget: udc: core: Prevent soft_connect_store() race")
Link: https://lore.kernel.org/linux-usb/4d7aa3f4-22d9-9f5a-3d70-1bd7148ff4ba@google.com/
Cc: Badhri Jagan Sridharan <badhri@google.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/48b2f1f1-0639-46bf-bbfc-98cb05a24914@rowland.harvard.edu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-08-04 14:56:24 +02:00
..
aspeed-vhub usb: gadget: aspeed: Convert to platform remove callback returning void 2023-05-28 12:36:25 +01:00
bdc usb: bdc: Convert to platform remove callback returning void 2023-05-28 12:36:25 +01:00
cdns2 usb: cdns2: Fix spelling mistake in a trace message "Wakupe" -> "Wakeup" 2023-06-19 15:34:44 +02:00
amd5536udc.h USB: gadget: udc: Remove some dead code 2021-10-10 15:12:34 +02:00
amd5536udc_pci.c usb: gadget: udc: fix NULL dereference in remove() 2023-05-29 15:24:24 +01:00
aspeed_udc.c usb: gadget: aspeed_udc: fix handling of tx_len == 0 2022-06-29 21:01:54 +02:00
at91_udc.c usb: gadget: at91-udc: simplify at91rm9200_udc_pullup callback 2022-11-09 11:43:11 +01:00
at91_udc.h usb: gadget: at91_udc: Convert to GPIO descriptors 2021-11-17 14:41:15 +01:00
atmel_usba_udc.c usb: gadget/atmel_usba_udc: Convert to platform remove callback returning void 2023-05-28 12:36:25 +01:00
atmel_usba_udc.h usb: gadget: udc: atmel: update endpoint allocation for sam9x60 2020-09-24 11:56:17 +03:00
bcm63xx_udc.c usb: gadget/bcm63xx_udc: Convert to platform remove callback returning void 2023-05-28 12:36:25 +01:00
core.c USB: Gadget: core: Help prevent panic during UVC unconfigure 2023-08-04 14:56:24 +02:00
dummy_hcd.c usb: gadget/dummy_hcd: Convert to platform remove callback returning void 2023-05-28 12:36:25 +01:00
fsl_qe_udc.c usb: gadget/fsl_qe_udc: Convert to platform remove callback returning void 2023-05-28 12:36:25 +01:00
fsl_qe_udc.h usb: Spelling s/enpoint/endpoint/ 2019-11-04 15:53:00 +01:00
fsl_udc_core.c usb: gadget: udc: do not clear gadget driver.bus 2023-02-02 09:41:17 +01:00
fsl_usb2_udc.h usb: gadget: fsl: properly remove remnant of MXC support 2021-06-14 10:31:51 +02:00
fusb300_udc.c usb: gadget/fusb300_udc: Convert to platform remove callback returning void 2023-05-28 12:36:26 +01:00
fusb300_udc.h USB: gadget: udc: Remove redundant license text 2017-11-07 15:45:02 +01:00
goku_udc.c usb: gadget: udc: do not clear gadget driver.bus 2023-02-02 09:41:17 +01:00
goku_udc.h usb: gadget: udc: change comparison to bitshift when dealing with a mask 2018-03-08 15:12:00 +02:00
gr_udc.c USB: gadget: gr_udc: fix memory leak with using debugfs_lookup() 2023-02-06 13:46:42 +01:00
gr_udc.h USB: gr_udc: remove dentry storage for debugfs file 2021-06-02 16:41:00 +02:00
Kconfig usb: cdns2: Add main part of Cadence USBHS driver 2023-06-13 11:59:29 +02:00
lpc32xx_udc.c USB: gadget: lpc32xx_udc: fix memory leak with using debugfs_lookup() 2023-02-06 13:46:42 +01:00
m66592-udc.c usb: gadget/m66592-udc: Convert to platform remove callback returning void 2023-05-28 12:36:26 +01:00
m66592-udc.h USB: gadget: udc: Remove redundant license text 2017-11-07 15:45:02 +01:00
Makefile usb: cdns2: Add main part of Cadence USBHS driver 2023-06-13 11:59:29 +02:00
max3420_udc.c usb: gadget: max3420_udc: drop of_match_ptr for ID table 2023-03-16 12:15:23 +01:00
mv_u3d.h usb: Spelling s/enpoint/endpoint/ 2019-11-04 15:53:00 +01:00
mv_u3d_core.c usb: gadget/mv_u3d_core: Convert to platform remove callback returning void 2023-05-28 12:36:26 +01:00
mv_udc.h USB: gadget: udc: Remove redundant license text 2017-11-07 15:45:02 +01:00
mv_udc_core.c usb: gadget/mv_udc_core: Convert to platform remove callback returning void 2023-05-28 12:36:26 +01:00
net2272.c usb: gadget/net2272: Convert to platform remove callback returning void 2023-05-28 12:36:26 +01:00
net2272.h USB: UDC: Implement udc_async_callbacks in net2272 2021-06-04 13:52:09 +02:00
net2280.c usb: gadget: udc: do not clear gadget driver.bus 2023-02-02 09:41:17 +01:00
net2280.h USB: UDC: Implement udc_async_callbacks in net2280 2021-06-04 13:52:06 +02:00
omap_udc.c usb: gadget/omap_udc: Convert to platform remove callback returning void 2023-05-28 12:36:26 +01:00
omap_udc.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pch_udc.c usb: gadget: udc: do not clear gadget driver.bus 2023-02-02 09:41:17 +01:00
pxa25x_udc.c USB / Thunderbolt driver changes for 6.3-rc1 2023-02-24 12:07:00 -08:00
pxa25x_udc.h ARM: pxa: lubbock: pass udc irqs as resource 2022-05-07 22:55:47 +02:00
pxa27x_udc.c USB / Thunderbolt driver updates for 6.5-rc1 2023-07-03 13:23:10 -07:00
pxa27x_udc.h usb: gadget: pxa27x_udc: clean up comment 2022-04-21 19:20:42 +02:00
r8a66597-udc.c usb: gadget/r8a66597-udc: Convert to platform remove callback returning void 2023-05-28 12:36:26 +01:00
r8a66597-udc.h USB: gadget: udc: Remove redundant license text 2017-11-07 15:45:02 +01:00
renesas_usb3.c USB / Thunderbolt driver updates for 6.5-rc1 2023-07-03 13:23:10 -07:00
renesas_usbf.c usb: gadget/renesas_usbf: Convert to platform remove callback returning void 2023-05-28 12:36:27 +01:00
rzv2m_usb3drd.c usb: gadget/rzv2m_usb3drd: Convert to platform remove callback returning void 2023-05-28 12:36:27 +01:00
snps_udc_core.c usb: gadget: udc: do not clear gadget driver.bus 2023-02-02 09:41:17 +01:00
snps_udc_plat.c usb: gadget/snps_udc_plat: Convert to platform remove callback returning void 2023-05-28 12:36:27 +01:00
tegra-xudc.c Revert "usb: gadget: tegra-xudc: Fix error check in tegra_xudc_powerdomain_init()" 2023-07-25 17:44:37 +02:00
trace.c USB: gadget: udc: fix kernel-doc syntax in file headers 2021-05-24 15:27:03 +02:00
trace.h usb: gadget: Properly configure the device for remote wakeup 2023-03-29 10:27:00 +02:00
udc-xilinx.c usb: gadget: udc: udc-xilinx: Add identifier to read_fn function arg 2023-06-13 11:55:26 +02:00