linux/drivers/usb
Alan Stern 9472aff16c USB: rio500: Fix lockdep violation
The syzbot fuzzer found a lockdep violation in the rio500 driver:

	======================================================
	WARNING: possible circular locking dependency detected
	5.3.0-rc2+ #23 Not tainted
	------------------------------------------------------
	syz-executor.2/20386 is trying to acquire lock:
	00000000772249c6 (rio500_mutex){+.+.}, at: open_rio+0x16/0xc0
	drivers/usb/misc/rio500.c:64

	but task is already holding lock:
	00000000d3e8f4b9 (minor_rwsem){++++}, at: usb_open+0x23/0x270
	drivers/usb/core/file.c:39

	which lock already depends on the new lock.

The problem is that the driver's open_rio() routine is called while
the usbcore's minor_rwsem is locked for reading, and it acquires the
rio500_mutex; whereas conversely, probe_rio() and disconnect_rio()
first acquire the rio500_mutex and then call usb_register_dev() or
usb_deregister_dev(), which lock minor_rwsem for writing.

The correct ordering of acquisition should be: minor_rwsem first, then
rio500_mutex (since the locking in open_rio() cannot be changed).
Thus, the probe and disconnect routines should avoid holding
rio500_mutex while doing their registration and deregistration.

This patch adjusts the code in those two routines to do just that.  It
also relies on the fact that the probe and disconnect routines are
protected by the device mutex, so the initial test of rio->present
needs no extra locking.

Reported-by: syzbot+7bbcbe9c9ff0cd49592a@syzkaller.appspotmail.com
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Fixes: d710734b06 ("USB: rio500: simplify locking")
Acked-by: Oliver Neukum <oneukum@suse.com>
CC: <stable@vger.kernel.org>

Link: https://lore.kernel.org/r/Pine.LNX.4.44L0.1908081329240.1319-100000@iolanthe.rowland.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-03 20:18:18 +02:00
..
atm USB: atm: cxacru: convert to use dev_groups 2019-08-09 07:55:45 +02:00
c67x00
cdns3 usb: cdns3: fix spelling mistake: "cnfiguration" -> "configuration" 2019-09-03 15:46:46 +02:00
chipidea usb: chipidea: msm: Use device-managed registration API 2019-09-03 15:53:27 +02:00
class Merge 5.3-rc7 into usb-next 2019-09-02 19:31:18 +02:00
common usb: common: add USB GPIO based connection detection driver 2019-09-03 19:01:04 +02:00
core Merge generic_lookup_helpers into usb-next 2019-09-03 17:11:07 +02:00
dwc2 USB: Changes for v5.4 merge window 2019-09-02 19:20:57 +02:00
dwc3 usb: dwc3: remove generic PHY calibrate() calls 2019-09-03 15:54:56 +02:00
early drivers: Remove explicit invocations of mmiowb() 2019-04-08 12:01:02 +01:00
gadget USB: Changes for v5.4 merge window 2019-09-02 19:20:57 +02:00
host xhci-ext-caps.c: Add property to disable Intel SW switch 2019-09-03 15:56:03 +02:00
image scsi: usb: image: microtek: use sg helper to iterate over scatterlist 2019-06-20 15:21:32 -04:00
isp1760 usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
misc USB: rio500: Fix lockdep violation 2019-09-03 20:18:18 +02:00
mon docs: usb: rename files to .rst and add them to drivers-api 2019-06-20 14:28:36 +02:00
mtu3 usb: mtu3: register a USB Role Switch for dual role mode 2019-09-03 20:02:15 +02:00
musb usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
phy USB: Changes for v5.4 merge window 2019-09-02 19:20:57 +02:00
renesas_usbhs usb: add a HCD_DMA flag instead of guestimating DMA capabilities 2019-08-21 10:03:35 -07:00
roles usb: roles: get usb-role-switch from parent 2019-09-03 18:00:43 +02:00
serial USB: serial: option: add the BroadMobi BM818 card 2019-08-15 13:46:22 +02:00
storage usb-storage: use hcd_uses_dma to check for DMA capabilities 2019-09-03 15:26:09 +02:00
typec Merge generic_lookup_helpers into usb-next 2019-09-03 17:11:07 +02:00
usbip usbip: Implement SG support to vhci-hcd and stub driver 2019-09-03 16:00:38 +02:00
Kconfig usb: common: create Kconfig file 2019-09-03 19:00:39 +02:00
Makefile USB: Changes for v5.4 merge window 2019-09-02 19:20:57 +02:00
usb-skeleton.c usb: usb-skeleton: make comment block in line with coding style 2019-08-21 09:57:36 -07:00