From: sashiko-bot@kernel.org
To: "Karl Mehltretter" <kmehltretter@gmail.com>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH 4/4] serial: imx: clear imx_uart_ports[] entry on probe failure and removal
Date: Sun, 19 Jul 2026 16:28:49 +0000 [thread overview]
Message-ID: <20260719162850.043B41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260719160812.35407-5-kmehltretter@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Lockless updates to the global imx_uart_ports[] array leave a Time-Of-Check to Time-Of-Use (TOCTOU) race condition during concurrent sibling probes and removals, allowing a stale pointer to be used for console registration and causing a deferred NULL pointer dereference.
Pre-existing issues:
- [High] Missing hrtimer cancellation for RS485 tx timers during device removal and shutdown leads to a Use-After-Free of the sport structure.
--
--- Patch [4]: [PATCH 4/4] serial: imx: clear imx_uart_ports[] entry on probe failure and removal ---
commit 85b874e619e770afd678fef4f09d60cd44a0c477
Author: Karl Mehltretter <kmehltretter@gmail.com>
serial: imx: clear imx_uart_ports[] entry on probe failure and removal
This commit clears the imx_uart_ports[] entry on probe failure and driver
removal. It prevents a stale pointer from being used by a sibling probe's
console setup during a devres free.
> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 251a50c8aa387..617c35772056c 100644
> --- a/drivers/tty/serial/imx.c
> +++ b/drivers/tty/serial/imx.c
> @@ -2637,6 +2637,8 @@ static int imx_uart_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, sport);
>
> ret = uart_add_one_port(&imx_uart_uart_driver, &sport->port);
> + if (ret)
> + imx_uart_ports[sport->port.line] = NULL;
>
> err_clk:
[ ... ]
> @@ -2647,8 +2649,10 @@ static int imx_uart_probe(struct platform_device *pdev)
> static void imx_uart_remove(struct platform_device *pdev)
> {
> struct imx_port *sport = platform_get_drvdata(pdev);
> + unsigned int line = sport->port.line;
>
> uart_remove_one_port(&imx_uart_uart_driver, &sport->port);
> + imx_uart_ports[line] = NULL;
[Severity: High]
Does clearing imx_uart_ports[] after uart_remove_one_port() create a race
condition with concurrent sibling probes?
When uart_remove_one_port() returns, all locks (including console_list_lock
and port->mutex) have been dropped.
If Thread A unbinds the UART, it unregisters the console inside
uart_remove_one_port(), drops the locks, but has not yet executed the newly
added line to clear imx_uart_ports[line].
Concurrently, Thread B probing a sibling UART can see the console is
unregistered, and successfully register it. During registration, Thread B's
imx_uart_console_setup() locklessly reads the still-valid
imx_uart_ports[0].
When Thread A resumes, it clears imx_uart_ports[0] = NULL, and devres frees
the port. A subsequent printk calls imx_uart_console_write_atomic(), which
reads the NULL pointer from the array and dereferences it.
> }
[Severity: High]
This is a pre-existing issue, but does device removal fail to cancel RS485
tx timers, leading to a use-after-free?
During device unbind, imx_uart_shutdown() loops waiting for
tx_state != OFF.
If the trigger_start_tx or trigger_stop_tx hrtimer is delayed or executing
concurrently, the loop times out, forcefully sets tx_state to OFF, and
returns without explicitly cancelling the timer using hrtimer_cancel().
Because imx_uart_remove() finishes without cancelling these driver-specific
hrtimers, devres will free the sport structure memory. If the delayed timer
subsequently fires, it will dereference the freed sport memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260719160812.35407-1-kmehltretter@gmail.com?part=4
next prev parent reply other threads:[~2026-07-19 16:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-19 16:08 [PATCH 0/4] serial: fix console lifetime bugs on failed bind and removal Karl Mehltretter
2026-07-19 16:08 ` [PATCH 1/4] serial: core: do fallible allocations before the console can be registered Karl Mehltretter
2026-07-19 16:08 ` [PATCH 2/4] serial: core: clear freed pointers on uart_register_driver() failure Karl Mehltretter
2026-07-19 16:08 ` [PATCH 3/4] tty: don't oops in tty_unregister_device() when no cdev is registered Karl Mehltretter
2026-07-19 16:08 ` [PATCH 4/4] serial: imx: clear imx_uart_ports[] entry on probe failure and removal Karl Mehltretter
2026-07-19 16:28 ` sashiko-bot [this message]
2026-07-19 22:02 ` Karl Mehltretter
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=20260719162850.043B41F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=kmehltretter@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.