From: sashiko-bot@kernel.org
To: "Tapio Reijonen" <tapio.reijonen@vaisala.com>
Cc: linux-serial@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 4/7] serial: core: Power the line transceiver with the port
Date: Wed, 11 Nov 2026 13:16:24 +0000 [thread overview]
Message-ID: <sashiko-outbox-209052@kernel.org> (raw)
In-Reply-To: <20261111-serial-transceiver-supply-v1-4-40bad0f912f2@vaisala.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 2 related pre-existing issues it does not
introduce:
- [Critical] serial: core: use-after-free in uart_line_info() [1]
- [Critical] serial: core: dangling pointer in
serial_core_add_one_port() [2]
--
commit 54c2531a6ac957209b731d5dba93f7f0ba6a052f
Author: Tapio Reijonen <tapio.reijonen@vaisala.com>
serial: core: Power the line transceiver with the port
This commit requests the optional transceiver-enable GPIO and startup delay
for a serial port and toggles the transceiver power alongside the port in
uart_change_pm().
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 6c0a6d9dcb851..d36bffaa100b8 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
[ ... ]
> @@ -3282,6 +3310,12 @@ static void serial_core_remove_one_port(struct uart_driver *drv,
>
> if (tty_port_initialized(port))
> uart_shutdown(NULL, state);
> +
> + /* Only a console port is still powered here */
> + if (uport->transceiver_enable_gpio &&
> + state->pm_state == UART_PM_STATE_ON)
> + uart_change_pm(state, UART_PM_STATE_OFF);
> + uport->transceiver_enable_gpio = NULL;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can uart_line_info() race
with serial_core_remove_one_port() and cause a use-after-free [1]?
serial_core_remove_one_port() drops port->mutex at the end of this block and
calls uport->ops->release_port(uport) before setting uport->type to
PORT_UNKNOWN:
CPU0 CPU1
serial_core_remove_one_port()
// drops port->mutex
uport->ops->release_port(uport)
uart_line_info()
guard(mutex)(&port->mutex)
if (uport->type == PORT_UNKNOWN)
return;
uport->ops->get_mctrl(uport) <-- use-after-free
uport->type = PORT_UNKNOWN
A concurrent read of /proc/tty/driver/serial sees uport->type != PORT_UNKNOWN
and invokes get_mctrl() on unmapped IO resources.
[ ... ]
> @@ -3409,6 +3453,14 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
> err_unregister_ctrl_dev:
> serial_base_ctrl_device_remove(new_ctrl_dev);
>
> +err_put_transceiver:
> + /* The port may be registered again: forget the GPIO */
> + if (core_transceiver && port->transceiver_enable_gpio) {
> + devm_gpiod_put(port->dev, port->transceiver_enable_gpio);
> + port->transceiver_enable_gpio = NULL;
> + port->transceiver_startup_delay_us = 0;
> + }
> +
> return ret;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but does
serial_core_add_one_port() leave a dangling pointer in uport->name when
allocating uport->tty_groups fails [2]?
drivers/tty/serial/serial_core.c:serial_core_add_one_port() {
...
uport->tty_groups = kzalloc_objs(*uport->tty_groups, 3);
if (!uport->tty_groups) {
kfree(uport->name);
return -ENOMEM;
}
...
}
Because the caller owns uport across registration failure, leaving the freed
pointer in uport->name can lead to a use-after-free or double free during
driver cleanup or a subsequent registration retry.
[1] https://sashiko.dev/#/bug/linux-dccfb530-78ab-4c75-b86c-353ac639e159
[2] https://sashiko.dev/#/bug/linux-4946dfed-5de8-46a5-b799-8b71897faf37
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111-serial-transceiver-supply-v1-0-40bad0f912f2@vaisala.com?part=4
next prev parent reply other threads:[~2026-11-11 13:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:27 [PATCH 0/7] serial: core: Power the line transceiver with the port Tapio Reijonen
2026-11-11 12:28 ` [PATCH 1/7] serial: max310x: Look up all channels before adding any port Tapio Reijonen
2026-11-11 12:52 ` sashiko-bot
2026-11-11 12:28 ` [PATCH 2/7] dt-bindings: serial: Add the line transceiver enable GPIO Tapio Reijonen
2026-11-11 12:28 ` [PATCH 3/7] dt-bindings: serial: sc16is7xx: Disallow transceiver GPIO on dual parts Tapio Reijonen
2026-11-11 12:28 ` [PATCH 4/7] serial: core: Power the line transceiver with the port Tapio Reijonen
2026-11-11 13:16 ` sashiko-bot [this message]
2026-11-11 12:28 ` [PATCH 5/7] serial: max310x: Request the line transceiver per port Tapio Reijonen
2026-11-11 12:28 ` [PATCH 6/7] dt-bindings: serial: max310x: Add maxim,tristate-when-closed Tapio Reijonen
2026-11-11 12:28 ` [PATCH 7/7] serial: max310x: Three-state TX and RTS while the port is closed Tapio Reijonen
2026-11-11 13:54 ` 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=sashiko-outbox-209052@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tapio.reijonen@vaisala.com \
/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