1
0
Fork 0
alistair23-linux/drivers/usb/storage
Alan Stern c2b71462d2 USB: core: Fix bug caused by duplicate interface PM usage counter
The syzkaller fuzzer reported a bug in the USB hub driver which turned
out to be caused by a negative runtime-PM usage counter.  This allowed
a hub to be runtime suspended at a time when the driver did not expect
it.  The symptom is a WARNING issued because the hub's status URB is
submitted while it is already active:

	URB 0000000031fb463e submitted while active
	WARNING: CPU: 0 PID: 2917 at drivers/usb/core/urb.c:363

The negative runtime-PM usage count was caused by an unfortunate
design decision made when runtime PM was first implemented for USB.
At that time, USB class drivers were allowed to unbind from their
interfaces without balancing the usage counter (i.e., leaving it with
a positive count).  The core code would take care of setting the
counter back to 0 before allowing another driver to bind to the
interface.

Later on when runtime PM was implemented for the entire kernel, the
opposite decision was made: Drivers were required to balance their
runtime-PM get and put calls.  In order to maintain backward
compatibility, however, the USB subsystem adapted to the new
implementation by keeping an independent usage counter for each
interface and using it to automatically adjust the normal usage
counter back to 0 whenever a driver was unbound.

This approach involves duplicating information, but what is worse, it
doesn't work properly in cases where a USB class driver delays
decrementing the usage counter until after the driver's disconnect()
routine has returned and the counter has been adjusted back to 0.
Doing so would cause the usage counter to become negative.  There's
even a warning about this in the USB power management documentation!

As it happens, this is exactly what the hub driver does.  The
kick_hub_wq() routine increments the runtime-PM usage counter, and the
corresponding decrement is carried out by hub_event() in the context
of the hub_wq work-queue thread.  This work routine may sometimes run
after the driver has been unbound from its interface, and when it does
it causes the usage counter to go negative.

It is not possible for hub_disconnect() to wait for a pending
hub_event() call to finish, because hub_disconnect() is called with
the device lock held and hub_event() acquires that lock.  The only
feasible fix is to reverse the original design decision: remove the
duplicate interface-specific usage counter and require USB drivers to
balance their runtime PM gets and puts.  As far as I know, all
existing drivers currently do this.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-and-tested-by: syzbot+7634edaea4d0b341c625@syzkaller.appspotmail.com
CC: <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-19 21:15:13 +02:00
..
Kconfig USB: add missing SPDX lines to Kconfig and Makefiles 2019-01-22 09:08:17 +01:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
alauda.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
cypress_atacb.c USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
datafab.c USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
debug.c USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
debug.h USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
ene_ub6250.c USB: ene_usb6250: add missing indentation 2018-11-23 16:13:14 +01:00
freecom.c usb: storage: Replace mdelay with msleep in init_freecom 2018-04-22 15:49:42 +02:00
initializers.c USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
initializers.h USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
isd200.c USB: STORAGE: ISD200 Fixed coding style issue "space required in for loop" 2018-09-20 15:10:29 +02:00
jumpshot.c USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
karma.c USB: storage: karma: add whitespace after declarations 2019-01-22 09:08:17 +01:00
onetouch.c USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
option_ms.c USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
option_ms.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
protocol.c USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
protocol.h USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
realtek_cr.c USB: core: Fix bug caused by duplicate interface PM usage counter 2019-04-19 21:15:13 +02:00
scsiglue.c USB: storage: don't insert sane sense for SPC3+ when bad sense specified 2019-01-07 17:23:29 +01:00
scsiglue.h USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
sddr09.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
sddr55.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
shuttle_usbat.c USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
sierra_ms.c USB: move many drivers to use DEVICE_ATTR_RO 2018-01-24 08:49:52 +01:00
sierra_ms.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
transport.c USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
transport.h USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
uas-detect.h uas: Always apply US_FL_NO_ATA_1X quirk to Seagate devices 2017-11-28 15:17:49 +01:00
uas.c scsi: uas: Use scsi_[gs]et_resid() where appropriate 2019-02-12 11:13:41 -05:00
unusual_alauda.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_cypress.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_datafab.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_devs.h USB: storage: add quirk for SMI SM3350 2019-01-07 17:23:30 +01:00
unusual_ene_ub6250.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_freecom.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_isd200.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_jumpshot.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_karma.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_onetouch.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_realtek.h USB: usb-storage: Add new IDs to ums-realtek 2018-11-26 08:09:47 +01:00
unusual_sddr09.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_sddr55.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
unusual_uas.h usb-storage: Add compatibility quirk flags for G-Technologies G-Drive 2018-05-24 18:19:39 +02:00
unusual_usbat.h USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
usb.c USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
usb.h USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
usual-tables.c USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00