linux/drivers/usb/serial
Johan Hovold 3f5edd58d0 USB: serial: fix unthrottle races
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>
2019-04-30 10:23:28 +02:00
..
aircable.c
ark3116.c USB: serial: ark3116: drop redundant init_termios 2019-04-26 08:37:53 +02:00
belkin_sa.c
belkin_sa.h
bus.c
ch341.c USB: serial: ch341: fix type promotion bug in ch341_control_in() 2018-07-04 15:40:54 +02:00
console.c USB: serial: console: fix reported terminal settings 2018-12-05 11:29:10 +01:00
cp210x.c USB: serial: cp210x: add new device id 2019-03-28 08:59:49 +01:00
cyberjack.c
cypress_m8.c USB: serial: cypress_m8: clean up initial-termios handling 2019-04-26 08:37:59 +02:00
cypress_m8.h
digi_acceleport.c USB: serial: digi_acceleport: clean up set_termios 2019-04-21 14:24:12 +02:00
empeg.c
ezusb_convert.pl
f81232.c f81232: switch to ->get_serial() 2018-10-13 00:50:35 -04:00
f81534.c USB: serial: f81534: fix reading old/new IC config 2018-11-20 18:25:44 +01:00
ftdi_sio_ids.h USB: serial: ftdi_sio: add additional NovaTech products 2019-03-19 10:37:26 +01:00
ftdi_sio.c USB: serial: ftdi_sio: add additional NovaTech products 2019-03-19 10:37:26 +01:00
ftdi_sio.h USB: serial: ftdi_sio: add support for FT232R CBUS gpios 2018-10-05 08:57:06 +02:00
garmin_gps.c
generic.c USB: serial: fix unthrottle races 2019-04-30 10:23:28 +02:00
io_16654.h
io_edgeport.c io_edgeport: switch to ->get_serial() 2018-10-13 00:50:37 -04:00
io_edgeport.h
io_ionsp.h
io_ti.c io_ti: switch to ->get_serial() 2018-10-13 00:50:38 -04:00
io_ti.h USB: serial: io_ti: fix array underflow in completion handler 2018-08-27 11:52:34 +02:00
io_usbvend.h
ipaq.c
ipw.c
ir-usb.c
iuu_phoenix.c USB: serial: iuu_phoenix: simplify init_termios 2019-04-26 08:38:00 +02:00
iuu_phoenix.h
Kconfig USB: add missing SPDX lines to Kconfig and Makefiles 2019-01-22 09:08:17 +01:00
keyspan_pda.c USB: serial: keyspan_pda: fix modem-status error handling 2018-07-06 10:32:14 +02:00
keyspan_usa26msg.h USB: serial: keyspan_usa: add proper SPDX lines for .h files 2019-01-18 11:09:32 +01:00
keyspan_usa28msg.h USB: serial: keyspan_usa: add proper SPDX lines for .h files 2019-01-18 11:09:32 +01:00
keyspan_usa49msg.h USB: serial: keyspan_usa: add proper SPDX lines for .h files 2019-01-18 11:09:32 +01:00
keyspan_usa67msg.h USB: serial: keyspan_usa: add proper SPDX lines for .h files 2019-01-18 11:09:32 +01:00
keyspan_usa90msg.h USB: serial: keyspan_usa: add proper SPDX lines for .h files 2019-01-18 11:09:32 +01:00
keyspan.c
kl5kusb105.c USB: serial: kl5kusb105: remove KLSI device id 2018-07-11 10:11:29 +02:00
kl5kusb105.h USB: serial: kl5kusb105: remove KLSI device id 2018-07-11 10:11:29 +02:00
kobil_sct.c USB: serial: kobil_sct: add missing version error handling 2018-07-06 10:42:42 +02:00
kobil_sct.h
Makefile
Makefile-keyspan_pda_fw
mct_u232.c
mct_u232.h
metro-usb.c
mos7720.c USB: serial: mos7720: fix mos_parport refcount imbalance on error path 2019-03-20 13:58:42 +01:00
mos7840.c USB: serial: mos7840: remove set but not used variables 'number, serial' 2018-12-10 10:20:44 +01:00
mxuport.c
navman.c
omninet.c
opticon.c opticon: switch to ->get_serial() 2018-10-13 00:50:39 -04:00
option.c USB: serial: option: add Olicard 600 2019-03-28 09:27:22 +01:00
oti6858.c USB: serial: oti6858: simplify init_termios 2019-04-26 08:38:00 +02:00
oti6858.h
pl2303.c USB: serial: pl2303: fix tranceiver suspend mode 2019-04-03 09:46:50 +02:00
pl2303.h USB: serial: pl2303: add new PID to support PL2303TB 2019-01-17 17:24:39 +01:00
qcaux.c
qcserial.c
quatech2.c USB: serial: quatech2: remove set but not used variable 'port_priv' 2018-11-12 10:08:10 +01:00
safe_serial.c
sierra.c USB: serial: sierra: use irqsave() in USB's complete callback 2018-06-26 15:22:25 +02:00
spcp8x5.c USB: serial: spcp8x5: simplify init_termios 2019-04-26 08:38:02 +02:00
ssu100.c ssu100: switch to ->get_serial() 2018-10-13 00:50:41 -04:00
symbolserial.c USB: serial: symbolserial: use irqsave() in USB's complete callback 2018-06-26 15:25:01 +02:00
ti_usb_3410_5052.c Merge branch 'work.tty-ioctl' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2018-10-24 14:43:41 +01:00
upd78f0730.c
usb_debug.c
usb_wwan.c usb_wwan: switch to ->[sg]et_serial() 2018-10-13 00:50:42 -04:00
usb-serial-simple.c USB: serial: simple: add Motorola Tetra TPG2200 device id 2019-01-07 16:37:52 +01:00
usb-serial.c USB: serial: fix initial-termios handling 2019-04-26 08:37:53 +02:00
usb-wwan.h usb_wwan: switch to ->[sg]et_serial() 2018-10-13 00:50:42 -04:00
visor.c
visor.h
whiteheat.c whiteheat: switch to ->get_serial() 2018-10-13 00:50:42 -04:00
whiteheat.h
wishbone-serial.c
xsens_mt.c