From: sashiko-bot@kernel.org
To: "Fan Wu" <fanwu01@zju.edu.cn>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH] serial: imx: cancel RS485 trigger hrtimers in shutdown and remove
Date: Wed, 19 Aug 2026 02:35:38 +0000 [thread overview]
Message-ID: <20260819023539.2478E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819021916.442827-1-fanwu01@zju.edu.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing cancellation of `sport->timer` and modem status GPIO IRQs in `imx_uart_remove()` leads to a use-after-free and system crash (bus fault) for console ports.
--
--- Patch [1]: [PATCH] serial: imx: cancel RS485 trigger hrtimers in shutdown and remove ---
commit 00c3fef931cf8afdbbbb1c6e8dc49797a632d082
Author: Fan Wu <fanwu01@zju.edu.cn>
serial: imx: cancel RS485 trigger hrtimers in shutdown and remove
This commit cancels the RS485 trigger hrtimers synchronously in
imx_uart_shutdown() and imx_uart_remove() to prevent use-after-free
after the devm-allocated port is freed.
> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 251a50c8aa387..86c99f73c50a3 100644
> --- a/drivers/tty/serial/imx.c
> +++ b/drivers/tty/serial/imx.c
[ ... ]
> @@ -2649,6 +2653,10 @@ static void imx_uart_remove(struct platform_device *pdev)
> struct imx_port *sport = platform_get_drvdata(pdev);
>
> uart_remove_one_port(&imx_uart_uart_driver, &sport->port);
> +
> + /* Serial core can reach remove() without calling the driver shutdown. */
> + hrtimer_cancel(&sport->trigger_start_tx);
> + hrtimer_cancel(&sport->trigger_stop_tx);
[Severity: High]
This is a pre-existing issue, but since we are cancelling timers in
imx_uart_remove(), does this function also need to cancel sport->timer and
disable the modem status GPIO IRQs?
If the system boots with hardware flow control enabled on the console,
imx_uart_console_setup() sets termios, which calls imx_uart_enable_ms() and
arms sport->timer.
If the driver is unbound via sysfs or the module is unloaded,
imx_uart_remove() unregisters the console, disabling the UART clocks.
However, it does not cancel sport->timer or disable the MS GPIO interrupts.
When devres frees the imx_port structure, the timer can still fire:
drivers/tty/serial/imx.c:imx_uart_timeout() {
struct imx_port *sport = timer_container_of(sport, t, timer);
unsigned long flags;
if (sport->port.state) {
uart_port_lock_irqsave(&sport->port, &flags);
imx_uart_mctrl_check(sport);
uart_port_unlock_irqrestore(&sport->port, flags);
mod_timer(&sport->timer, jiffies + MCTRL_TIMEOUT);
}
}
Could this lead to accessing the freed sport struct and reading disabled
UART registers, resulting in a use-after-free and system crash?
> }
>
> static void imx_uart_restore_context(struct imx_port *sport)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260819021916.442827-1-fanwu01@zju.edu.cn?part=1
next prev parent reply other threads:[~2026-08-19 2:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 2:19 [PATCH] serial: imx: cancel RS485 trigger hrtimers in shutdown and remove Fan Wu
2026-08-19 2:35 ` sashiko-bot [this message]
2026-08-19 4:26 ` Jiri Slaby
2026-08-19 6:39 ` Fan Wu
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=20260819023539.2478E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=fanwu01@zju.edu.cn \
--cc=imx@lists.linux.dev \
--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