DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: vkoul@kernel.org, dmaengine@vger.kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCHv5] dmaengine: fsl_raid: check fsl_re_chan_probe() return value
Date: Tue, 15 Sep 2026 19:19:59 +0000	[thread overview]
Message-ID: <20260915192000.79E561F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915190047.86218-1-rosenp@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] dmaengine: fsl_raid: orphaning partially probed channels causes UAF and leaks
--

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

dmaengine: fsl_raid: check fsl_re_chan_probe() return value
    
fsl_re_probe() ignores the return value of fsl_re_chan_probe() and
unconditionally increments total_chans. When a channel fails to probe
(for example, an IRQ mapping failure) its re_jrs[] slot is left NULL, yet
total_chans still advances, so fsl_re_remove_chan() later dereferences the
NULL pointer during device removal.

> diff --git a/drivers/dma/fsl_raid.c b/drivers/dma/fsl_raid.c
> index 2d86f61105e52..8c57250ecea6a 100644
> --- a/drivers/dma/fsl_raid.c
> +++ b/drivers/dma/fsl_raid.c
> @@ -828,18 +828,27 @@ static int fsl_re_probe(struct platform_device *ofdev)
>  		}
>  		/* Find out the Job Rings present under each JQ */
>  		for_each_child_of_node(np, child) {
> -			rc = of_device_is_compatible(child,
> -					     "fsl,raideng-v1.0-job-ring");
> +			if (ridx >= FSL_RE_MAX_CHANS) {
> +				dev_warn(dev, "too many job rings, max %d\n", FSL_RE_MAX_CHANS);
> +				of_node_put(child);
> +				break;
> +			}
> +
> +			rc = of_device_is_compatible(child, "fsl,raideng-v1.0-job-ring");
> +			if (!rc)
> +				continue;
> +
> +			rc = fsl_re_chan_probe(ofdev, child, ridx, off);
>  			if (rc) {
> -				fsl_re_chan_probe(ofdev, child, ridx++, off);
> -				re_priv->total_chans++;
> +				dev_err(dev, "job ring %d probe failed: %d\n", ridx, rc);
> +				continue;

[Severity: High]
Does this code risk orphaning a partially probed channel, leading to a
use-after-free?

If fsl_re_chan_probe() in drivers/dma/fsl_raid.c fails late during its
execution (for example, if a DMA pool allocation fails), it will have
already assigned:
re_priv->re_jrs[ridx] = chan;
and registered an IRQ handler and a tasklet.

By calling continue without incrementing ridx, the next loop iteration in
fsl_re_probe() will overwrite re_priv->re_jrs[ridx]. This leaves the
partially initialized channel orphaned, meaning its tasklet will not be
killed during driver teardown. When devres eventually frees the chan
structure, an active tasklet or IRQ will access the freed memory.

>  			}
> +			ridx++;
> +			re_priv->total_chans++;
>  		}
>  	}
>  
> -	dma_async_device_register(dma_dev);
> -
> -	return 0;
> +	return dma_async_device_register(dma_dev);

[Severity: High]
This isn't a bug introduced by this patch, but does returning this error
code expose a use-after-free if dma_async_device_register() fails?

If dma_async_device_register() fails, fsl_re_probe() in drivers/dma/fsl_raid.c
now returns the error code, which triggers devres cleanup and frees the chan
structures. However, since the driver allocates IRQs using the non-devm
request_irq() in fsl_re_chan_probe() and lacks an error unwinding path, the
IRQ handlers remain active. When a hardware interrupt fires after the probe
failure, the handler will access the freed chan memory.

>  }

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

      reply	other threads:[~2026-09-15 19:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 19:00 [PATCHv5] dmaengine: fsl_raid: check fsl_re_chan_probe() return value Rosen Penev
2026-09-15 19:19 ` sashiko-bot [this message]

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=20260915192000.79E561F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=rosenp@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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