linux-stable/drivers/tty
Peter Hurley e144c58cad serial: core: Fix crashes while echoing when closing
While closing, new rx data may be received after the input buffers
have been flushed but before stop_rx() halts receiving [1]. The
new data might not be processed by flush_to_ldisc() until after
uart_shutdown() and normal input processing is re-enabled (ie.,
tty->closing = 0). The race is outlined below:

CPU 0                         | CPU 1
                              |
uart_close()                  |
   tty_port_close_start()     |
      tty->closing = 1        |
      tty_ldisc_flush()       |
                              | => IRQ
                              |   while (LSR & data ready)
                              |      uart_insert_char()
                              |   tty_flip_buffer_push()
                              | <= EOI
   stop_rx()                  |   .
   uart_shutdown()            |   .
      free xmit.buf           |   .
   tty_port_tty_set(NULL)     |   .
   tty->closing = 0           |   .
                              | flush_to_ldisc()
                              |   n_tty_receive_buf_common()
                              |      __receive_buf()
                              |         ...
                              |         commit_echoes()
                              |            uart_flush_chars()
                              |               __uart_start()
                              | ** OOPS on port.tty deref **
   tty_ldisc_flush()          |

Input processing must be prevented from echoing (tty->closing = 1)
until _after_ the input buffers have been flushed again at the end
of uart_close().

[1] In fact, some input may actually be buffered _after_ stop_rx()
since the rx interrupt may have already triggered but not yet been
handled when stop_rx() disables rx interrupts.

Fixes: 2e75891083 ("serial: core: Flush ldisc after dropping port
mutex in uart_close()")
Reported-by: Robert Elliott <elliott@hp.com>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-07-23 18:08:28 -07:00
..
hvc xen: features and cleanups for 4.2-rc0 2015-07-01 11:53:46 -07:00
ipwireless Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2015-04-14 09:50:27 -07:00
serial serial: core: Fix crashes while echoing when closing 2015-07-23 18:08:28 -07:00
vt tty/vt: Fix the memory leak in visual_init 2015-07-23 15:11:08 -07:00
amiserial.c tty: amiserial.c: move assignment out of if () block 2015-05-10 19:04:16 +02:00
bfin_jtag_comm.c TTY: bfin_jtag_comm: remove incorrect wait_until_sent operation 2015-03-07 03:44:14 +01:00
cyclades.c tty: remove buf parameter from tty_name() 2015-05-06 22:26:57 +02:00
ehv_bytechan.c
goldfish.c staging: goldfish: Fix pointer cast for 32 bits 2015-05-31 11:40:14 +09:00
isicom.c
Kconfig ttyFDC: Implement KGDB IO operations. 2015-03-31 12:04:13 +02:00
Makefile TTY: Add MIPS EJTAG Fast Debug Channel TTY driver 2015-03-31 12:04:12 +02:00
metag_da.c tty/metag_da: Avoid module_init/module_exit in non-modular code 2015-06-16 14:12:31 -04:00
mips_ejtag_fdc.c ttyFDC: Fix to use native endian MMIO reads 2015-05-26 16:46:52 +02:00
moxa.c
moxa.h
mxser.c
mxser.h
n_gsm.c tty: Spelling s/reseved/reserved/ 2015-05-24 13:06:08 -07:00
n_hdlc.c pty: Fix input race when closing 2015-05-10 19:26:37 +02:00
n_r3964.c
n_tracerouter.c
n_tracesink.c
n_tracesink.h
n_tty.c n_tty: signal and flush atomically 2015-07-23 15:05:53 -07:00
nozomi.c drivers/tty/nozomi.c: rename CONFIG_MAGIC 2015-05-10 19:19:06 +02:00
pty.c pty: Fix input race when closing 2015-05-10 19:26:37 +02:00
rocket.c
rocket.h tty: rocket: fix comment of ROCKET_SPD_HI 2015-05-24 12:49:16 -07:00
rocket_int.h
synclink.c tty: synclink.c: move assignment out of if () block 2015-05-10 19:04:18 +02:00
synclink_gt.c tty: synclink_gt.c: move assignment out of if () block 2015-05-10 19:04:18 +02:00
synclinkmp.c tty: synclinkmp.c: move assignment out of if () block 2015-05-10 19:04:18 +02:00
sysrq.c Minor merge needed, due to function move. 2015-07-01 10:49:25 -07:00
tty_audit.c
tty_buffer.c Merge 4.1-rc4 into tty-next 2015-05-18 14:08:58 -07:00
tty_io.c tty: remove buf parameter from tty_name() 2015-05-06 22:26:57 +02:00
tty_ioctl.c tty: remove buf parameter from tty_name() 2015-05-06 22:26:57 +02:00
tty_ldisc.c tty: remove buf parameter from tty_name() 2015-05-06 22:26:57 +02:00
tty_ldsem.c tty: tty_ldsem.c: move assignment out of if () block 2015-05-10 19:04:18 +02:00
tty_mutex.c
tty_port.c