From: sashiko-bot@kernel.org
To: "Johan Hovold" <johan@kernel.org>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH v4 2/4] serial: fix ioctl hangup race
Date: Thu, 10 Sep 2026 13:25:02 +0000 [thread overview]
Message-ID: <20260910132503.3F9221F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910130816.642699-3-johan@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch misses several tty driver callbacks that access hardware and can race with hangup, including those triggered by the TCXONC ioctl and racing writes.
--
commit b720c07153ba95668df0da514b07008b06834b2e
Author: Johan Hovold <johan@kernel.org>
serial: fix ioctl hangup race
This commit adds tty_io_error checks to several tty ioctls and driver
operations. It aims to ensure the port has not been hung up before accessing
the hardware, avoiding kernel panics.
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 1553bc6cbe7ba..139b938762298 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -896,7 +896,7 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
> upf_t old_flags, new_flags;
> int retval;
>
> - if (!uport)
> + if (!uport || tty_io_error(tty))
> return -EIO;
>
> new_port = new_info->port;
[Severity: High]
This isn't a bug introduced by this patch, but does this miss several other
tty driver callbacks that access hardware and can race with hangup, including
those triggered by the TCXONC ioctl and racing writes?
Invoking hardware callbacks (start_tx, stop_tx, send_xchar) on a powered-down
or unclocked UART port causes bus errors and kernel panics.
Can a user call ioctl(TCXONC) on a hung-up terminal and invoke uart_stop(),
uart_start(), or uart_send_xchar()? These do not check tty_io_error(tty) and
unconditionally access the hardware:
drivers/tty/serial/serial_core.c:uart_stop() {
port = uart_port_ref_lock(state, &flags);
if (port)
port->ops->stop_tx(port);
...
}
drivers/tty/serial/serial_core.c:uart_start() {
port = uart_port_ref_lock(state, &flags);
__uart_start(state);
...
}
drivers/tty/serial/serial_core.c:uart_send_xchar() {
if (port->ops->send_xchar)
port->ops->send_xchar(port, ch);
...
}
Additionally, can a concurrent write() race with uart_shutdown()? If
uart_write() acquires the port lock after uart_port_shutdown() disables the
hardware but before uart_free_xmit_buf() clears the buffer pointer, it will
pass the !state->port.xmit_buf check and invoke start_tx on the dead hardware:
drivers/tty/serial/serial_core.c:uart_write() {
port = uart_port_ref_lock(state, &flags);
if (!state->port.xmit_buf) {
uart_port_unlock_deref(port, flags);
return 0;
}
...
__uart_start(state);
...
}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910130816.642699-1-johan@kernel.org?part=2
next prev parent reply other threads:[~2026-09-10 13:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 13:08 [PATCH v4 0/4] serial: fix ioctl hangup race Johan Hovold
2026-09-10 13:08 ` [PATCH v4 1/4] serial: revert guards in uart_wait_modem_status() Johan Hovold
2026-09-10 13:16 ` sashiko-bot
2026-09-10 13:08 ` [PATCH v4 2/4] serial: fix ioctl hangup race Johan Hovold
2026-09-10 13:25 ` sashiko-bot [this message]
2026-09-10 13:08 ` [PATCH v4 3/4] serial: fix TIOCMIWAIT race Johan Hovold
2026-09-10 13:16 ` sashiko-bot
2026-09-10 13:08 ` [PATCH v4 4/4] serial: abort TIOCMIWAIT on hangup Johan Hovold
2026-09-10 13:20 ` sashiko-bot
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=20260910132503.3F9221F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=johan@kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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