mirror-linux/drivers/tty/serial
Krzysztof Kozlowski 32f37e5758 serial: Fix not set tty->port race condition
Revert commit bfc467db60 ("serial: remove redundant
tty_port_link_device()") because the tty_port_link_device() is not
redundant: the tty->port has to be confured before we call
uart_configure_port(), otherwise user-space can open console without TTY
linked to the driver.

This tty_port_link_device() was added explicitly to avoid this exact
issue in commit fb2b90014d ("tty: link tty and port before configuring
it as console"), so offending commit basically reverted the fix saying
it is redundant without addressing the actual race condition presented
there.

Reproducible always as tty->port warning on Qualcomm SoC with most of
devices disabled, so with very fast boot, and one serial device being
the console:

  printk: legacy console [ttyMSM0] enabled
  printk: legacy console [ttyMSM0] enabled
  printk: legacy bootconsole [qcom_geni0] disabled
  printk: legacy bootconsole [qcom_geni0] disabled
  ------------[ cut here ]------------
  tty_init_dev: ttyMSM driver does not set tty->port. This would crash the kernel. Fix the driver!
  WARNING: drivers/tty/tty_io.c:1414 at tty_init_dev.part.0+0x228/0x25c, CPU#2: systemd/1
  Modules linked in: socinfo tcsrcc_eliza gcc_eliza sm3_ce fuse ipv6
  CPU: 2 UID: 0 PID: 1 Comm: systemd Tainted: G S                  6.19.0-rc4-next-20260108-00024-g2202f4d30aa8 #73 PREEMPT
  Tainted: [S]=CPU_OUT_OF_SPEC
  Hardware name: Qualcomm Technologies, Inc. Eliza (DT)
  ...
  tty_init_dev.part.0 (drivers/tty/tty_io.c:1414 (discriminator 11)) (P)
  tty_open (arch/arm64/include/asm/atomic_ll_sc.h:95 (discriminator 3) drivers/tty/tty_io.c:2073 (discriminator 3) drivers/tty/tty_io.c:2120 (discriminator 3))
  chrdev_open (fs/char_dev.c:411)
  do_dentry_open (fs/open.c:962)
  vfs_open (fs/open.c:1094)
  do_open (fs/namei.c:4634)
  path_openat (fs/namei.c:4793)
  do_filp_open (fs/namei.c:4820)
  do_sys_openat2 (fs/open.c:1391 (discriminator 3))
  ...
  Starting Network Name Resolution...

Apparently the flow with this small Yocto-based ramdisk user-space is:

driver (qcom_geni_serial.c):                  user-space:
============================                  ===========
qcom_geni_serial_probe()
 uart_add_one_port()
  serial_core_register_port()
   serial_core_add_one_port()
    uart_configure_port()
     register_console()
    |
    |                                         open console
    |                                          ...
    |                                          tty_init_dev()
    |                                           driver->ports[idx] is NULL
    |
    tty_port_register_device_attr_serdev()
     tty_port_link_device() <- set driver->ports[idx]

Fixes: bfc467db60 ("serial: remove redundant tty_port_link_device()")
Cc: stable@vger.kernel.org
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Link: https://patch.msgid.link/20260123072139.53293-2-krzysztof.kozlowski@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-01-23 17:23:09 +01:00
..
8250 serial: 8250_pci: Fix broken RS485 for F81504/508/512 2026-01-16 14:29:10 +01:00
jsm treewide: Drop pci_save_state() after pci_restore_state() 2025-11-24 16:58:59 -06:00
21285.c
Kconfig serial: sc16is7xx: Kconfig: allow building with COMPILE_TEST 2025-10-28 15:25:41 +01:00
Makefile serial: sh-sci: Add support for RZ/T2H SCI 2025-07-09 13:45:30 +02:00
altera_jtaguart.c serial: altera_jtaguart: Use KBUILD_MODNAME 2024-12-04 16:35:53 +01:00
altera_uart.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
amba-pl010.c
amba-pl011.c serial: amba-pl011: prefer dma_mapping_error() over explicit address checking 2025-10-28 15:26:47 +01:00
apbuart.c
apbuart.h
ar933x_uart.c serial: ar933x: Add polling support 2025-10-22 12:04:43 +02:00
arc_uart.c
atmel_serial.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
atmel_serial.h
bcm63xx_uart.c
clps711x.c
cpm_uart.c TTY / Serial driver updates for 6.13-rc1 2024-11-30 09:03:16 -08:00
cpm_uart.h
digicolor-usart.c
dz.c
dz.h
earlycon-riscv-sbi.c
earlycon-semihost.c
earlycon.c
esp32_acm.c
esp32_uart.c
fsl_linflexuart.c
fsl_lpuart.c tty: serial: fsl_lpuart: Add missing wakeup event reporting 2025-10-22 12:04:51 +02:00
icom.c TTY/Serial changes for 6.19-rc1 2025-12-06 18:38:19 -08:00
imx.c tty: serial: imx: Add missing wakeup event reporting 2025-10-22 12:06:35 +02:00
imx_earlycon.c
ip22zilog.c tty: serial: ip22zilog: Use platform device for probing 2025-08-14 11:58:40 +02:00
ip22zilog.h
kgdboc.c drivers: serial: kgdboc: Drop checks for CON_ENABLED and CON_BOOT 2025-11-27 15:54:50 +01:00
lantiq.c serial: lantiq: Remove unnecessary print function dev_err() 2025-04-11 16:51:49 +02:00
liteuart.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
lpc32xx_hs.c
ma35d1_serial.c tty: serial: pl011: remove incorrect of_match_ptr annotation 2025-03-20 08:09:56 -07:00
max310x.c serial: max310x: improve interrupt handling 2025-09-12 16:10:16 +02:00
max3100.c tty: serial: Modify the use of dev_err_probe() 2025-08-21 08:09:20 +02:00
mcf.c
men_z135_uart.c module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
meson_uart.c
milbeaut_usio.c serial: Fix potential null-ptr-deref in mlb_usio_probe() 2025-04-11 16:53:34 +02:00
mpc52xx_uart.c serial: mpc52xx_uart: Remove legacy PM hook 2025-02-04 14:38:32 +01:00
mps2-uart.c
msm_serial.c tty: remove redundant condition checks 2025-09-06 15:49:58 +02:00
mux.c serial: mux: Fix kernel doc for mux_poll() 2025-11-26 13:11:17 +01:00
mvebu-uart.c tty: serial: mvebu-uart: convert from round_rate() to determine_rate() 2025-08-14 11:59:04 +02:00
mxs-auart.c
omap-serial.c
owl-uart.c
pch_uart.c pch_uart: Fix dma_sync_sg_for_device() nents value 2025-07-09 13:43:02 +02:00
pic32_uart.c
pmac_zilog.c
pmac_zilog.h
pxa.c
qcom_geni_serial.c serial: qcom_geni: Fix BT failure regression on RB2 platform 2026-01-16 14:28:49 +01:00
rda-uart.c
rp2.c
rsci.c serial: sh-sci: Add support for RZ/T2H SCI 2025-07-09 13:45:30 +02:00
rsci.h serial: sh-sci: Add support for RZ/T2H SCI 2025-07-09 13:45:30 +02:00
sa1100.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
samsung_tty.c tty: serial: samsung: Declare earlycon for Exynos850 2025-11-26 13:11:55 +01:00
sb1250-duart.c
sc16is7xx.c serial: sc16is7xx: add comments for lock requirements 2025-10-28 15:25:41 +01:00
sc16is7xx.h serial: sc16is7xx: use KBUILD_MODNAME 2025-10-28 15:25:41 +01:00
sc16is7xx_i2c.c serial: sc16is7xx: use KBUILD_MODNAME 2025-10-28 15:25:41 +01:00
sc16is7xx_spi.c serial: sc16is7xx: use KBUILD_MODNAME 2025-10-28 15:25:41 +01:00
sccnxp.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
serial-tegra.c
serial_base.h
serial_base_bus.c serial: core: Fix serial device initialization 2025-12-23 11:53:37 +01:00
serial_core.c serial: Fix not set tty->port race condition 2026-01-23 17:23:09 +01:00
serial_ctrl.c
serial_mctrl_gpio.c serial: mctrl_gpio: split disable_ms into sync and no_sync APIs 2025-02-19 15:08:36 +01:00
serial_mctrl_gpio.h serial: mctrl_gpio: split disable_ms into sync and no_sync APIs 2025-02-19 15:08:36 +01:00
serial_port.c serial: port: Make ->iotype validation global in __uart_read_properties() 2025-02-04 14:44:44 +01:00
serial_txx9.c
sh-sci-common.h serial: sh-sci: Add support for RZ/T2H SCI 2025-07-09 13:45:30 +02:00
sh-sci.c serial: sh-sci: Check that the DMA cookie is valid 2025-12-23 11:54:00 +01:00
sifive.c Linux 6.15-rc4 2025-04-28 10:13:28 +02:00
sprd_serial.c serial: sprd: Return -EPROBE_DEFER when uart clock is not ready 2025-11-26 13:12:19 +01:00
st-asc.c
stm32-usart.c serial: stm32: do not deassert RS485 RTS GPIO prematurely 2025-03-20 08:30:44 -07:00
stm32-usart.h
suncore.c
sunhv.c
sunplus-uart.c
sunsab.c
sunsab.h
sunsu.c tty: sunsu: remove unused serial_icr_read() 2025-03-20 08:00:51 -07:00
sunzilog.c
sunzilog.h
tegra-tcu.c
tegra-utc.c serial: tegra-utc: Remove unneeded semicolon 2025-04-11 16:52:21 +02:00
timbuart.c
timbuart.h
uartlite.c tty: serial: uartlite: register uart driver in init 2025-04-11 16:52:06 +02:00
ucc_uart.c TTY / Serial driver updates for 6.13-rc1 2024-11-30 09:03:16 -08:00
vt8500_serial.c
xilinx_uartps.c serial: xilinx_uartps: fix rs485 delay_rts_after_send 2025-12-23 11:55:16 +01:00
zs.c
zs.h