From: sashiko-bot@kernel.org
To: "Igor Putko" <igorpetindev@gmail.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH] serial: core: shut down initialized port on removal
Date: Thu, 24 Sep 2026 19:39:04 +0000 [thread overview]
Message-ID: <20260924193904.984FD1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260924192224.3175-1-igorpetindev@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] tty: data race on port->console in serial_core_remove_one_port()
--
commit ff681977bacb42b18c6925085fd5fa965af4c283
Author: Igor Putko <igorpetindev@gmail.com>
serial: core: shut down initialized port on removal
This commit addresses a use-after-free read during IRQ setup by ensuring
initialized console ports are properly shut down before removal. It clears
the console flag and calls uart_shutdown() under the port mutex.
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 95774b0f1484b..030735da6b8c5 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -3210,8 +3210,15 @@ static void serial_core_remove_one_port(struct uart_driver *drv,
> /*
> * If the port is used as a console, unregister it
> */
> - if (uart_console(uport))
> + if (uart_console(uport)) {
> unregister_console(uport->cons);
> + port->console = false;
[Severity: Medium]
Could this assignment cause a data race on the port->console bitfield?
If a user process holds the serial console open while the underlying device
is removed, serial_core_remove_one_port() will synchronously hang up the
tty by calling tty_port_tty_vhangup().
If the user process then calls close(), the syscall path will execute
tty_release() -> uart_close() -> tty_port_close() -> tty_port_shutdown().
In tty_port_shutdown(), the code acquires port->mutex and evaluates
port->console. Concurrently, the assignment above happens without
holding port->mutex.
While this might be practically benign at the machine level since byte stores
are usually atomic, concurrent read/write access without synchronization is
undefined behavior in C and can trigger KCSAN warnings.
> + }
> +
> + guard(mutex)(&port->mutex);
> +
> + if (tty_port_initialized(port))
> + uart_shutdown(NULL, state);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924192224.3175-1-igorpetindev@gmail.com?part=1
next prev parent reply other threads:[~2026-09-24 19:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 19:22 [PATCH] serial: core: shut down initialized port on removal Igor Putko
2026-09-24 19:39 ` sashiko-bot [this message]
2026-09-25 5:34 ` Greg Kroah-Hartman
2026-09-26 13:05 ` IgorpetinDev
2026-10-01 8:58 ` Greg KH
2026-10-03 16:33 ` [PATCH v2] " Igor Putko
2026-10-03 17:56 ` 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=20260924193904.984FD1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=igorpetindev@gmail.com \
--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