Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCHv2 1/4] serial: mxs-auart: fix cast type for of_device_get_match_data
Date: Tue, 09 Jun 2026 22:49:33 +0000	[thread overview]
Message-ID: <20260609224934.13E8A1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609223717.41670-2-rosenp@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Out-of-bounds array write to negative index (-1) due to using pdev->id.
- [High] Use-after-unmap race condition due to mixing devm_request_irq with manual iounmap.
--

commit 65b6a79a32694ff06e9c834fc282d2c8989565ff
Author: Rosen Penev <rosenp@gmail.com>

serial: mxs-auart: fix cast type for of_device_get_match_data

of_device_get_match_data returns const void*. Cast to unsigned long to
avoid implicit integer truncation warnings. All the data parameters are
correct anyway.

> diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
> index 693b491f1e755..3e14c2768c48e 100644
> --- a/drivers/tty/serial/mxs-auart.c
> +++ b/drivers/tty/serial/mxs-auart.c
> @@ -1598,7 +1598,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	s->devtype = (enum mxs_auart_type)of_device_get_match_data(&pdev->dev);
> +	s->devtype = (unsigned long)of_device_get_match_data(&pdev->dev);
>  
>  	ret = mxs_get_clks(s, pdev);
>  	if (ret)

[ ... ]

>  out_free_qpio_irq:
>  	mxs_auart_free_gpio_irq(s);
>  	auart_port[pdev->id] = NULL;

[Severity: High]
This isn't a bug introduced by this patch, but does this result in an
out-of-bounds write to a negative index?

For devices instantiated via Device Tree, pdev->id is initialized to
PLATFORM_DEVID_NONE (-1).

The driver correctly registers the port using auart_port[s->port.line] = s;
earlier in probe, but on the error path it attempts to clean up using
auart_port[pdev->id] = NULL;.

Could this corrupt the adjacent global memory in the BSS/Data section? It also
seems to fail to clear the actual dangling pointer at
auart_port[s->port.line], which might lead to a use-after-free later.

>  
>  out_iounmap:
>  	iounmap(s->port.membase);

[Severity: High]
This is a pre-existing issue, but does this manual iounmap() create a
use-after-unmap race condition?

The driver requests the main UART interrupt using devm_request_irq().
Devm-managed resources are freed automatically, but only after the probe
function returns.

Since the memory is manually unmapped here, there is a window where the
interrupt handler mxs_auart_irq_handle() remains registered and active.

If a spurious interrupt fires during this window, the handler could execute an
MMIO read via mxs_read(s, REG_STAT) on the unmapped memory, potentially causing
a kernel page fault.

[ ... ]

>  static void mxs_auart_remove(struct platform_device *pdev)
>  {
>  	struct mxs_auart_port *s = platform_get_drvdata(pdev);
>  
>  	uart_remove_one_port(&auart_driver, &s->port);
>  	auart_port[pdev->id] = NULL;

[Severity: High]
This is a pre-existing issue, but doesn't this also result in the same
out-of-bounds write to a negative index as seen in the probe error path?

>  	mxs_auart_free_gpio_irq(s);
>  	iounmap(s->port.membase);

[Severity: High]
This isn't a bug introduced by this patch, but does this create the same
use-after-unmap race condition during device removal?

Since the devm subsystem cleans up the IRQ handler after remove() completes,
manually unmapping the memory here leaves a window where an active interrupt
could trigger an MMIO read on the unmapped memory.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260609223717.41670-2-rosenp@gmail.com?part=1

  reply	other threads:[~2026-06-09 22:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 22:37 [PATCHv2 0/4] serial: mxs-auart: devm conversion, clock rework, and IRQ ordering fixes Rosen Penev
2026-06-09 22:37 ` [PATCHv2 1/4] serial: mxs-auart: fix cast type for of_device_get_match_data Rosen Penev
2026-06-09 22:49   ` sashiko-bot [this message]
2026-06-10  1:13   ` Frank Li
2026-06-10  6:06     ` Rosen Penev
2026-06-09 22:37 ` [PATCHv2 2/4] serial: mxs-auart: rework clock handling in mxs_get_clks and probe Rosen Penev
2026-06-09 22:49   ` sashiko-bot
2026-06-10  1:24   ` Frank Li
2026-06-09 22:37 ` [PATCHv2 3/4] serial: mxs-auart: use devm resources for iomem and GPIO IRQs Rosen Penev
2026-06-10  1:26   ` Frank Li
2026-06-09 22:37 ` [PATCHv2 4/4] serial: mxs-auart: fix IRQ registration ordering and manage console clock Rosen Penev
2026-06-10  1:32   ` Frank Li

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=20260609224934.13E8A1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=rosenp@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox