[lvc-project] [PATCH v5.10] serial: core: fix infinite loop in handle_tx() for PORT_UNKNOWN
Andrey Kalachev
kalachev at swemel.ru
Fri Aug 21 18:41:08 MSK 2026
From: Jiayuan Chen <jiayuan.chen at shopee.com>
commit 455ce986fa356ff43a43c0d363ba95fa152f21d5 upstream.
uart_write_room() and uart_write() behave inconsistently when
xmit_buf is NULL (which happens for PORT_UNKNOWN ports that were
never properly initialized):
- uart_write_room() returns kfifo_avail() which can be > 0
- uart_write() checks xmit_buf and returns 0 if NULL
This inconsistency causes an infinite loop in drivers that rely on
tty_write_room() to determine if they can write:
while (tty_write_room(tty) > 0) {
written = tty->ops->write(...);
// written is always 0, loop never exits
}
For example, caif_serial's handle_tx() enters an infinite loop when
used with PORT_UNKNOWN serial ports, causing system hangs.
Fix by making uart_write_room() also check xmit_buf and return 0 if
it's NULL, consistent with uart_write().
Reproducer: https://gist.github.com/mrpre/d9a694cc0e19828ee3bc3b37983fde13
Signed-off-by: Jiayuan Chen <jiayuan.chen at shopee.com>
Cc: stable <stable at kernel.org>
Link: https://patch.msgid.link/20260204074327.226165-1-jiayuan.chen@linux.dev
Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
[ The original patch returns '0' for unallocated buffers.
This causes a boot hang during systemd initialization on Linux kernels
with stable versions 6.1.y or earlier. Added a check for
uart_console(port), which returns the default buffer size,
preventing deadlocks. ]
Signed-off-by: Andrey Kalachev <kalachev at swemel.ru>
---
drivers/tty/serial/serial_core.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 6d7d448d0fbf..7b685b8c09ad 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -625,7 +625,17 @@ static int uart_write_room(struct tty_struct *tty)
int ret;
port = uart_port_lock(state, flags);
- ret = uart_circ_chars_free(&state->xmit);
+ if (!state->port.xmit_buf) {
+ /* fix systemd hang, return buffer size if it is console */
+ if (port && uart_console(port))
+ ret = UART_XMIT_SIZE - 1;
+ else {
+ printk_ratelimited(KERN_WARNING "SECURITY_ALERT: Possible CVE-2026-23472 exploit attempt! Process '%s' (PID %d) tried to write to uninitialized port on line %d.\n",
+ current->comm, current->pid, port ? port->line : -1);
+ ret = 0;
+ }
+ } else
+ ret = uart_circ_chars_free(&state->xmit);
uart_port_unlock(port, flags);
return ret;
}
--
2.39.5
More information about the lvc-project
mailing list