From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Jiri Slaby <jirislaby@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org
Subject: [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info()
Date: Fri, 4 Dec 2026 22:35:36 -0800 [thread overview]
Message-ID: <20261205063536.2519566-5-praneethb2002@gmail.com> (raw)
In-Reply-To: <20261205063536.2519566-1-praneethb2002@gmail.com>
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
prev parent reply other threads:[~2026-12-05 6:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` [PATCH 3/4] tty: atmel_serial: take the port lock in console write Praneeth Balasubramanian
2026-12-05 6:35 ` Praneeth Balasubramanian [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205063536.2519566-5-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=imx@lists.linux.dev \
--cc=jirislaby@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox