linux-uconsole/drivers/tty/serial
Sudip Mukherjee 65c6710c3f tty: link tty and port before configuring it as console
commit fb2b90014d upstream.

There seems to be a race condition in tty drivers and I could see on
many boot cycles a NULL pointer dereference as tty_init_dev() tries to
do 'tty->port->itty = tty' even though tty->port is NULL.
'tty->port' will be set by the driver and if the driver has not yet done
it before we open the tty device we can get to this situation. By adding
some extra debug prints, I noticed that:

6.650130: uart_add_one_port
6.663849: register_console
6.664846: tty_open
6.674391: tty_init_dev
6.675456: tty_port_link_device

uart_add_one_port() registers the console, as soon as it registers, the
userspace tries to use it and that leads to tty_open() but
uart_add_one_port() has not yet done tty_port_link_device() and so
tty->port is not yet configured when control reaches tty_init_dev().

Further look into the code and tty_port_link_device() is done by
uart_add_one_port(). After registering the console uart_add_one_port()
will call tty_port_register_device_attr_serdev() and
tty_port_link_device() is called from this.

Call add tty_port_link_device() before uart_configure_port() is done and
add a check in tty_port_link_device() so that it only links the port if
it has not been done yet.

Suggested-by: Jiri Slaby <jslaby@suse.com>
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20191212131602.29504-1-sudipm.mukherjee@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-01-14 20:07:05 +01:00
..
8250 serial: 8250: Fix serial8250 initialization crash 2019-12-05 09:21:06 +01:00
cpm_uart tty: serial: cpm_uart - fix init when SMC is relocated 2019-07-31 07:26:57 +02:00
jsm tty: serial: jsm: remove redundant pointer ch 2018-07-13 15:36:32 +02:00
21285.c
altera_jtaguart.c
altera_uart.c serial: altera: set RRDY flag also without irq 2018-02-28 13:30:09 +01:00
amba-pl010.c
amba-pl011.c serial: pl011: Fix DMA ->flush_buffer() 2019-12-13 08:51:00 +01:00
amba-pl011.h
apbuart.c
apbuart.h
ar933x_uart.c serial: ar933x_uart: Fix build failure with disabled console 2019-05-04 09:20:13 +02:00
arc_uart.c serial: arc_uart: Fix out-of-bounds access through DT alias 2018-02-28 15:29:59 +01:00
atmel_serial.c tty/serial: atmel: fix out of range clock divider handling 2020-01-04 19:13:44 +01:00
atmel_serial.h
bcm63xx_uart.c
clps711x.c
digicolor-usart.c tty/serial: digicolor: Fix digicolor-usart already registered warning 2019-07-31 07:26:59 +02:00
dz.c
dz.h
earlycon-arm-semihost.c
earlycon.c earlycon: Remove hardcoded port->uartclk initialization in of_setup_earlycon 2018-05-14 13:41:05 +02:00
efm32-uart.c
fsl_lpuart.c tty: serial: fsl_lpuart: use the sg count from dma_map_sg 2019-12-13 08:50:59 +01:00
icom.c
icom.h
ifx6x60.c serial: ifx6x60: add missed pm_runtime_disable 2019-12-13 08:51:01 +01:00
ifx6x60.h
imx.c serial: imx: fix error handling in console_setup 2019-12-13 08:51:56 +01:00
ioc3_serial.c
ioc4_serial.c
ip22zilog.c
ip22zilog.h
Kconfig tty: serial: drop ATH79 specific SoC symbols 2018-05-14 13:51:12 +02:00
kgdb_nmi.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
kgdboc.c Disable kgdboc failed by echo space to /sys/module/kgdboc/parameters/kgdboc 2019-04-03 06:26:26 +02:00
lantiq.c
lpc32xx_hs.c
Makefile TTY/Serial driver patches for 4.17-rc1 2018-04-04 18:43:49 -07:00
max310x.c serial: max310x: Fix tx_empty() callback 2019-12-05 09:20:40 +01:00
max3100.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
mcf.c
men_z135_uart.c
meson_uart.c tty: serial: meson: fix typo in the "stop bit" register definition 2017-11-28 15:32:33 +01:00
mpc52xx_uart.c
mps2-uart.c
mpsc.c
msm_serial.c tty: serial: msm_serial: Fix lockup for sysrq and oops 2020-01-09 10:19:06 +01:00
mux.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
mvebu-uart.c serial: mvebu-uart: Fix to avoid a potential NULL pointer dereference 2019-04-03 06:26:25 +02:00
mxs-auart.c serial: mxs-auart: Fix potential infinite loop 2019-11-20 18:46:54 +01:00
netx-serial.c
omap-serial.c tty: omap-serial: Fix initial on-boot RTS GPIO level 2018-01-09 16:45:17 +01:00
owl-uart.c tty: serial: owl: Fix the link time qualifier of 'owl_uart_exit()' 2019-11-06 13:05:49 +01:00
pch_uart.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
pic32_uart.c serial: set suppress_bind_attrs flag only if builtin 2019-01-26 09:32:34 +01:00
pic32_uart.h
pmac_zilog.c
pmac_zilog.h
pnx8xxx_uart.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
pxa.c serial: pxa: Fix an error handling path in 'serial_pxa_probe()' 2018-06-28 21:07:54 +09:00
qcom_geni_serial.c tty: serial: qcom_geni_serial: Fix softlock 2019-12-13 08:52:27 +01:00
rp2.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
sa1100.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
samsung.c serial: samsung: Enable baud clock for UART reset procedure in resume 2019-11-20 18:46:53 +01:00
samsung.h
sb1250-duart.c
sc16is7xx.c sc16is7xx: Fix for "Unexpected interrupt: 8" 2019-11-06 13:05:15 +01:00
sccnxp.c headers: separate linux/mod_devicetable.h from linux/platform_device.h 2018-07-07 17:52:26 +02:00
serial-tegra.c
serial_core.c tty: link tty and port before configuring it as console 2020-01-14 20:07:05 +01:00
serial_ks8695.c
serial_mctrl_gpio.c serial: mctrl_gpio: Check for NULL pointer 2019-11-06 13:05:52 +01:00
serial_mctrl_gpio.h
serial_txx9.c
sh-sci.c serial: sh-sci: Fix crash in rx_timer_fn() on PIO fallback 2019-12-05 09:20:23 +01:00
sh-sci.h serial: sh-sci: Support for HSCIF RX sampling point adjustment 2018-04-23 10:08:18 +02:00
sirfsoc_uart.c serial: sirf: Fix out-of-bounds access through DT alias 2018-02-28 15:30:00 +01:00
sirfsoc_uart.h
sn_console.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
sprd_serial.c serial: sprd: correct the wrong sequence of arguments 2019-09-21 07:16:45 +02:00
st-asc.c tty: serial: simplify getting .drvdata 2018-04-22 17:29:43 +02:00
stm32-usart.c serial: stm32: fix initialization of RS485 mode 2018-03-15 17:39:43 +01:00
stm32-usart.h serial: stm32: add support for RS485 hardware control mode 2018-03-14 13:35:37 +01:00
suncore.c drivers/tty: add missing of_node_put() 2018-12-21 14:15:18 +01:00
sunhv.c sunhv: Fix device naming inconsistency between sunhv_console and sunhv_reg 2019-06-22 08:15:14 +02:00
sunsab.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
sunsab.h
sunsu.c serial/sunsu: fix refcount leak 2019-01-13 09:51:03 +01:00
sunzilog.c
sunzilog.h
timbuart.c
timbuart.h
uartlite.c serial: uartlite: fix exit path null pointer 2019-10-17 13:45:00 -07:00
ucc_uart.c
vr41xx_siu.c
vt8500_serial.c
xilinx_uartps.c serial: uartps: Fix suspend functionality 2019-11-20 18:46:53 +01:00
zs.c
zs.h