Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH 0/4] tty: fix a stack overread and missing locking in serial drivers
@ 2026-12-05  6:35 Praneeth Balasubramanian
  2026-12-05  6:35 ` [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info() Praneeth Balasubramanian
  0 siblings, 1 reply; 3+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05  6:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Richard Genoud, Nicolas Ferre,
	Alexandre Belloni, Claudiu Beznea, Frank Li, Sascha Hauer
  Cc: Praneeth Balasubramanian, linuxppc-dev, linux-kernel,
	linux-serial, linux-arm-kernel, Pengutronix Kernel Team,
	Fabio Estevam, imx

These 4 patches fix bugs that an LLM-based audit found. The audit checks
code against the rules stated in kernel comments, such as "the caller
must hold this lock" or "drop the reference when done". Each changelog
explains the rule and the path that breaks it.

The patches are independent of each other, and each one can be applied
on its own. They are against next-20261204 and also apply to mainline
(007722b8211f).

None of them was runtime-tested. There is no reproducer, and I do not
have the hardware. Each one builds without new warnings with W=1, and
checkpatch.pl is clean. Details are below the --- of each patch.

Tools: GLM-5.3 drafted the fixes and changelogs. Claude Opus 5.5 checked
each one against the source and rewrote parts where needed. I reviewed
every patch.

Praneeth Balasubramanian (4):
  tty: hvsi: fix stack overread in hvsi_version_respond()
  serial: men_z135_uart: do not release an unrequested memory region
  tty: atmel_serial: take the port lock in console write
  mxser: take termios_rwsem in mxser_set_serial_info()

 drivers/tty/hvc/hvsi.c             |  7 +++++--
 drivers/tty/mxser.c                |  1 +
 drivers/tty/serial/atmel_serial.c  | 15 ++++++++++++---
 drivers/tty/serial/men_z135_uart.c |  7 +++++--
 4 files changed, 23 insertions(+), 7 deletions(-)


base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ 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
@ 2026-12-05  6:35 ` Praneeth Balasubramanian
  2026-12-05  6:56   ` sashiko-bot
  0 siblings, 1 reply; 3+ 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] 3+ messages in thread

* Re: [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info()
  2026-12-05  6:35 ` [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info() Praneeth Balasubramanian
@ 2026-12-05  6:56   ` sashiko-bot
  0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-05  6:56 UTC (permalink / raw)
  To: Praneeth Balasubramanian; +Cc: linux-serial, imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] tty: mxser: missing Fixes trailer on bug-fix commit
--

commit 44a7f707c343c7759dfecdededbf501d80470e81
Author: Praneeth Balasubramanian <praneethb2002@gmail.com>

> mxser: take termios_rwsem in mxser_set_serial_info()
>
> 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>

[Severity: Low]
This fixes an unlocked tty_encode_baud_rate() call in
mxser_set_serial_info().  Should this include:

  Fixes: 80ff8a805113 ("Char: mxser, add support for CP-114UL")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205063536.2519566-1-praneethb2002@gmail.com?part=4

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-05  6:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 4/4] mxser: take termios_rwsem in mxser_set_serial_info() Praneeth Balasubramanian
2026-12-05  6:56   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox