linux-stable/drivers/usb
Johan Hovold fedc5219fd USB: serial: fix unthrottle races
commit 3f5edd58d0 upstream.

Fix two long-standing bugs which could potentially lead to memory
corruption or leave the port throttled until it is reopened (on weakly
ordered systems), respectively, when read-URB completion races with
unthrottle().

First, the URB must not be marked as free before processing is complete
to prevent it from being submitted by unthrottle() on another CPU.

	CPU 1				CPU 2
	================		================
	complete()			unthrottle()
	  process_urb();
	  smp_mb__before_atomic();
	  set_bit(i, free);		  if (test_and_clear_bit(i, free))
	  					  submit_urb();

Second, the URB must be marked as free before checking the throttled
flag to prevent unthrottle() on another CPU from failing to observe that
the URB needs to be submitted if complete() sees that the throttled flag
is set.

	CPU 1				CPU 2
	================		================
	complete()			unthrottle()
	  set_bit(i, free);		  throttled = 0;
	  smp_mb__after_atomic();	  smp_mb();
	  if (throttled)		  if (test_and_clear_bit(i, free))
	  	  return;			  submit_urb();

Note that test_and_clear_bit() only implies barriers when the test is
successful. To handle the case where the URB is still in use an explicit
barrier needs to be added to unthrottle() for the second race condition.

Fixes: d83b405383 ("USB: serial: add support for multiple read urbs")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-16 19:42:19 +02:00
..
atm
c67x00
chipidea usb: chipidea: Grab the (legacy) USB PHY by phandle first 2019-04-05 22:31:29 +02:00
class USB: cdc-acm: fix unthrottle races 2019-05-10 17:53:14 +02:00
common usb: common: Consider only available nodes for dr_mode 2019-04-03 06:25:19 +02:00
core USB: core: Fix bug caused by duplicate interface PM usage counter 2019-05-08 07:20:46 +02:00
dwc2 dwc2: gadget: Fix ISOC IN DDMA PID bitfield value calculation 2018-08-24 13:09:01 +02:00
dwc3 usb: dwc3: Fix default lpm_nyet_threshold value 2019-05-10 17:53:13 +02:00
early
gadget usb: gadget: net2272: Fix net2272_dequeue() 2019-05-04 09:15:19 +02:00
host usb: u132-hcd: fix resource leak 2019-05-04 09:15:22 +02:00
image
isp1760
misc USB: yurex: Fix protection fault after device removal 2019-05-08 07:20:46 +02:00
mon usb: usbmon: Read text within supplied buffer size 2018-03-19 08:42:46 +01:00
mtu3 usb: mtu3: fix EXTCON dependency 2019-04-03 06:25:19 +02:00
musb usb: gadget: musb: fix short isoc packets with inventra dma 2019-02-12 19:46:12 +01:00
phy usb: phy: fix link errors 2019-03-13 14:03:20 -07:00
renesas_usbhs usb: renesas_usbhs: missed the "running" flag in usb_dmac with rx path 2018-02-28 10:19:43 +01:00
serial USB: serial: fix unthrottle races 2019-05-16 19:42:19 +02:00
storage UAS: fix alignment of scatter/gather segments 2019-05-10 17:53:15 +02:00
typec usb: typec: ucsi: Fix for incorrect status data issue 2018-07-08 15:30:47 +02:00
usbip usb: usbip: fix isoc packet num validation in get_pipe 2019-05-08 07:20:46 +02:00
wusbcore usb: wusbcore: security: cast sizeof to int for comparison 2018-10-03 17:00:49 -07:00
Kconfig usb: Move USB_UHCI_BIG_ENDIAN_* out of USB_SUPPORT 2018-02-22 15:42:31 +01:00
Makefile
README
usb-skeleton.c

To understand all the Linux-USB framework, you'll use these resources:

    * This source code.  This is necessarily an evolving work, and
      includes kerneldoc that should help you get a current overview.
      ("make pdfdocs", and then look at "usb.pdf" for host side and
      "gadget.pdf" for peripheral side.)  Also, Documentation/usb has
      more information.

    * The USB 2.0 specification (from www.usb.org), with supplements
      such as those for USB OTG and the various device classes.
      The USB specification has a good overview chapter, and USB
      peripherals conform to the widely known "Chapter 9".

    * Chip specifications for USB controllers.  Examples include
      host controllers (on PCs, servers, and more); peripheral
      controllers (in devices with Linux firmware, like printers or
      cell phones); and hard-wired peripherals like Ethernet adapters.

    * Specifications for other protocols implemented by USB peripheral
      functions.  Some are vendor-specific; others are vendor-neutral
      but just standardized outside of the www.usb.org team.

Here is a list of what each subdirectory here is, and what is contained in
them.

core/		- This is for the core USB host code, including the
		  usbfs files and the hub class driver ("hub_wq").

host/		- This is for USB host controller drivers.  This
		  includes UHCI, OHCI, EHCI, and others that might
		  be used with more specialized "embedded" systems.

gadget/		- This is for USB peripheral controller drivers and
		  the various gadget drivers which talk to them.


Individual USB driver directories.  A new driver should be added to the
first subdirectory in the list below that it fits into.

image/		- This is for still image drivers, like scanners or
		  digital cameras.
../input/	- This is for any driver that uses the input subsystem,
		  like keyboard, mice, touchscreens, tablets, etc.
../media/	- This is for multimedia drivers, like video cameras,
		  radios, and any other drivers that talk to the v4l
		  subsystem.
../net/		- This is for network drivers.
serial/		- This is for USB to serial drivers.
storage/	- This is for USB mass-storage drivers.
class/		- This is for all USB device drivers that do not fit
		  into any of the above categories, and work for a range
		  of USB Class specified devices. 
misc/		- This is for all USB device drivers that do not fit
		  into any of the above categories.