* [PATCH 1/4] tty: hvsi: fix stack overread in hvsi_version_respond()
2026-12-05 6:35 [PATCH 0/4] tty: fix a stack overread and missing locking in serial drivers Praneeth Balasubramanian
@ 2026-12-05 6:35 ` Praneeth Balasubramanian
[not found] ` <sashiko-outbox-251156@kernel.org>
2026-12-05 6:35 ` [PATCH 2/4] serial: men_z135_uart: do not release an unrequested memory region Praneeth Balasubramanian
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:35 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Praneeth Balasubramanian, stable, linuxppc-dev, linux-kernel,
linux-serial
hvc_put_chars() always loads two unsigned long words from the buffer,
16 bytes in total, whatever count its caller passes. Its comment says
the buffer must be at least 16 bytes. hvsi_version_respond() passes a
struct hvsi_query_response, which is only 12 bytes. The load of the
second word reads 4 bytes past the end of the stack object. This
happens on every HVSI handshake, when the port answers the version
query of the service processor.
Copy the packet into a zeroed, aligned 16 byte buffer and pass that to
hvc_put_chars(). The 4 bytes after the packet are then zero instead of
stack contents. The count stays packet.hdr.len, so the service
processor sees the same bytes as before.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by an LLM-based audit, part of research at UCSB SecLab.
An LLM turned a kernel comment into a rule, and three LLM votes checked
the code against it. The fix and changelog were drafted with GLM-5.3,
then checked against the source and partly rewritten with Claude Opus
5.5. I reviewed the patch and take responsibility for it.
Testing: builds without new warnings with W=1 (x86_64 allmodconfig;
powerpc pseries_defconfig), clang 23. checkpatch.pl is clean. Not
runtime-tested, and there is no reproducer. I do not have this hardware.
drivers/tty/hvc/hvsi.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index a94068bce76f..ec91ee42ad8c 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -279,7 +279,9 @@ static void hvsi_recv_response(struct hvsi_struct *hp, uint8_t *packet)
/* respond to service processor's version query */
static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
{
- struct hvsi_query_response packet __ALIGNED__;
+ struct hvsi_query_response packet;
+ /* hvc_put_chars() reads 16 bytes even if count is smaller. */
+ uint8_t buf[16] __ALIGNED__ = {};
int wrote;
packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
@@ -292,7 +294,8 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
dbg_dump_hex((uint8_t*)&packet, packet.hdr.len);
- wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.hdr.len);
+ memcpy(buf, &packet, sizeof(packet));
+ wrote = hvc_put_chars(hp->vtermno, buf, packet.hdr.len);
if (wrote != packet.hdr.len) {
printk(KERN_ERR "hvsi%i: couldn't send query response!\n",
hp->index);
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/4] serial: men_z135_uart: do not release an unrequested memory region
2026-12-05 6:35 [PATCH 0/4] tty: fix a stack overread and missing locking in serial drivers Praneeth Balasubramanian
2026-12-05 6:35 ` [PATCH 1/4] tty: hvsi: fix stack overread in hvsi_version_respond() Praneeth Balasubramanian
@ 2026-12-05 6:35 ` Praneeth Balasubramanian
2026-12-05 6:35 ` [PATCH 3/4] tty: atmel_serial: take the port lock in console write Praneeth Balasubramanian
2026-12-05 6:35 ` [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info() Praneeth Balasubramanian
3 siblings, 0 replies; 7+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:35 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Praneeth Balasubramanian, stable, linux-kernel, linux-serial
men_z135_config_port() sets the port type and ignores the return value
of men_z135_request_port(). The port type is also set in probe. So the
port stays registered even when the memory request fails, for example
when mcb_request_mem() returns -EBUSY because the region is already
claimed.
serial core calls release_port for any port with a known type. After
a failed request uart->mem is still NULL, and men_z135_release_port()
passes it to mcb_release_mem(), which dereferences it. When ioremap()
fails instead, men_z135_request_port() releases the region itself but
leaves uart->mem set. A later release_port then releases the same
region a second time.
Set uart->mem only once the region is requested and mapped. In
men_z135_release_port(), release the region only if uart->mem is set,
and clear it afterwards.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 37f0679964fa ("tty: serial: men_z135_uart.c: use mcb memory region size instead of hardcoded one")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by an LLM-based audit, part of research at UCSB SecLab.
An LLM turned a kernel comment into a rule, and three LLM votes checked
the code against it. The fix and changelog were drafted with GLM-5.3,
then checked against the source and partly rewritten with Claude Opus
5.5. I reviewed the patch and take responsibility for it.
Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
reproducer. I do not have this hardware.
drivers/tty/serial/men_z135_uart.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c
index 861b783cec3d..2eddac1da37e 100644
--- a/drivers/tty/serial/men_z135_uart.c
+++ b/drivers/tty/serial/men_z135_uart.c
@@ -726,7 +726,10 @@ static void men_z135_release_port(struct uart_port *port)
iounmap(port->membase);
port->membase = NULL;
- mcb_release_mem(uart->mem);
+ if (uart->mem) {
+ mcb_release_mem(uart->mem);
+ uart->mem = NULL;
+ }
}
static int men_z135_request_port(struct uart_port *port)
@@ -740,13 +743,13 @@ static int men_z135_request_port(struct uart_port *port)
return PTR_ERR(mem);
port->mapbase = mem->start;
- uart->mem = mem;
port->membase = ioremap(mem->start, resource_size(mem));
if (port->membase == NULL) {
mcb_release_mem(mem);
return -ENOMEM;
}
+ uart->mem = mem;
return 0;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 3/4] tty: atmel_serial: take the port lock in console write
2026-12-05 6:35 [PATCH 0/4] tty: fix a stack overread and missing locking in serial drivers Praneeth Balasubramanian
2026-12-05 6:35 ` [PATCH 1/4] tty: hvsi: fix stack overread in hvsi_version_respond() Praneeth Balasubramanian
2026-12-05 6:35 ` [PATCH 2/4] serial: men_z135_uart: do not release an unrequested memory region Praneeth Balasubramanian
@ 2026-12-05 6:35 ` Praneeth Balasubramanian
[not found] ` <sashiko-outbox-251173@kernel.org>
2026-12-05 6:35 ` [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info() Praneeth Balasubramanian
3 siblings, 1 reply; 7+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:35 UTC (permalink / raw)
To: Richard Genoud, Greg Kroah-Hartman, Jiri Slaby, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea
Cc: Praneeth Balasubramanian, stable, linux-kernel, linux-serial,
linux-arm-kernel
atmel_console_write() touches the PDC and USART TX control registers and
the tx_stopped flag without holding the port lock. atmel_stop_tx() and
atmel_start_tx() run under the lock. So the console can race with a
TCXONC ioctl or another path that stops the transmitter. The comment
that says interrupts are disabled on entry does not hold on PREEMPT_RT.
There legacy consoles are printed from a kthread, and con->write runs in
task context with interrupts enabled.
If atmel_stop_tx() runs while the console is between its PDC_TXTEN
snapshot and the TXTEN restore, the console re-enables a transmitter that
was just stopped and writes back a stale PDC_TXTEN value. The port ends up
in an inconsistent state and serial output can stall.
Take the port lock for the whole callback so the register accesses are
serialized against the other paths. Drop the stale comment. Follow the
pl011 pattern: skip the lock when a sysrq is being handled on the port,
since atmel_rx_chars() calls uart_handle_sysrq_char() under the port lock,
and use a trylock when an oops is in progress.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 39d4c922b596 ("atmel_serial: fix uart/console concurrent access")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by an LLM-based audit, part of research at UCSB SecLab.
An LLM turned a kernel comment into a rule, and three LLM votes checked
the code against it. The fix and changelog were drafted with GLM-5.3,
then checked against the source and partly rewritten with Claude Opus
5.5. I reviewed the patch and take responsibility for it.
Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
reproducer. I do not have this hardware.
James Hilliard's serial port lock series (v14, 2026-12-04) changes other
functions in atmel_serial.c, not atmel_console_write(). The two may need
a rebase against each other.
drivers/tty/serial/atmel_serial.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index c3880259e3bc..7446c956262a 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -2560,15 +2560,21 @@ static void atmel_console_putchar(struct uart_port *port, unsigned char ch)
atmel_uart_write_char(port, ch);
}
-/*
- * Interrupts are disabled on entering
- */
static void atmel_console_write(struct console *co, const char *s, u_int count)
{
struct uart_port *port = &atmel_ports[co->index].uart;
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
unsigned int status, imr;
unsigned int pdc_tx;
+ unsigned long flags;
+ int locked = 1;
+
+ if (port->sysrq)
+ locked = 0;
+ else if (oops_in_progress)
+ locked = uart_port_trylock_irqsave(port, &flags);
+ else
+ uart_port_lock_irqsave(port, &flags);
/*
* First, save IMR and then disable interrupts
@@ -2601,6 +2607,9 @@ static void atmel_console_write(struct console *co, const char *s, u_int count)
/* set interrupts back the way they were */
atmel_uart_writel(port, ATMEL_US_IER, imr);
+
+ if (locked)
+ uart_port_unlock_irqrestore(port, flags);
}
/*
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info()
2026-12-05 6:35 [PATCH 0/4] tty: fix a stack overread and missing locking in serial drivers Praneeth Balasubramanian
` (2 preceding siblings ...)
2026-12-05 6:35 ` [PATCH 3/4] tty: atmel_serial: take the port lock in console write Praneeth Balasubramanian
@ 2026-12-05 6:35 ` Praneeth Balasubramanian
3 siblings, 0 replies; 7+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:35 UTC (permalink / raw)
To: Jiri Slaby, Greg Kroah-Hartman, Frank Li, Sascha Hauer
Cc: Praneeth Balasubramanian, Pengutronix Kernel Team, Fabio Estevam,
linux-kernel, linux-serial, imx, linux-arm-kernel
mxser_set_serial_info() updates the termios without holding
tty->termios_rwsem. It calls tty_encode_baud_rate() which writes c_ispeed
and c_ospeed and rewrites the CBAUD bits of c_cflag. It also reads the
termios in mxser_change_speed() and mxser_activate().
A concurrent TCSETS or TCSETS2 on the same tty stores the whole termios
under termios_rwsem in tty_set_termios(). The TIOCSSERIAL path takes no
termios_rwsem. The two writers can interleave. The whole-struct store can
land between the speed stores and leave c_cflag, c_ispeed and c_ospeed
disagreeing with each other.
Take termios_rwsem for write at the top of mxser_set_serial_info().
Take it before port->mutex. serial_core takes termios_rwsem before
port->mutex in uart_set_info_user() and both lock classes are global. The
same order here avoids a lockdep inversion. Nothing inside the critical
section takes termios_rwsem itself.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by an LLM-based audit, part of research at UCSB SecLab.
An LLM turned a kernel comment into a rule, and three LLM votes checked
the code against it. The fix and changelog were drafted with GLM-5.3,
then checked against the source and partly rewritten with Claude Opus
5.5. I reviewed the patch and take responsibility for it.
Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
reproducer. I do not have this hardware.
drivers/tty/mxser.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 281c599a12f2..a761dd9f3c71 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -982,6 +982,7 @@ static int mxser_set_serial_info(struct tty_struct *tty,
if (tty_io_error(tty))
return -EIO;
+ guard(rwsem_write)(&tty->termios_rwsem);
guard(mutex)(&port->mutex);
if (ss->irq != info->board->irq || ss->port != info->ioaddr)
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread