All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Haoxiang Li" <haoxiang_li2024@163.com>
Cc: linux-ide@vger.kernel.org, dlemoal@kernel.org, cassel@kernel.org
Subject: Re: [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start()
Date: Tue, 17 Nov 2026 09:54:12 +0000	[thread overview]
Message-ID: <sashiko-outbox-218548@kernel.org> (raw)
In-Reply-To: <20261117094903.1282096-1-haoxiang_li2024@163.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] ata: sata_dwc_460ex: use-after-free in sata_dwc_probe() [1]
--

commit 7cbed05368af81c2d62d6074918f0d6f1dc52c91
Author: Haoxiang Li <haoxiang_li2024@163.com>

ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start()

This commit releases the DMA channel in sata_dwc_port_start() when
phy_power_on() fails before freeing the port structure.

> diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c
> index 0daa5850a7bd0..4ab378d2c26f7 100644
> --- a/drivers/ata/sata_dwc_460ex.c
> +++ b/drivers/ata/sata_dwc_460ex.c
> @@ -852,7 +852,7 @@ static int sata_dwc_port_start(struct ata_port *ap)
>  
>  	err = phy_power_on(hsdev->phy);
>  	if (err)
> -		goto CLEANUP_ALLOC;
> +		goto CLEANUP_DMA;
>  
>  	for (i = 0; i < SATA_DWC_QCMD_MAX; i++)
>  		hsdevp->cmd_issued[i] = SATA_DWC_CMD_ISSUED_NOT;
> @@ -879,6 +879,8 @@ static int sata_dwc_port_start(struct ata_port *ap)
>  	dev_dbg(ap->dev, "%s: done\n", __func__);
>  	return 0;
>  
> +CLEANUP_DMA:
> +	dma_release_channel(hsdevp->chan);
>  CLEANUP_ALLOC:
>  	kfree(hsdevp);
>  CLEANUP:

[Severity: Critical]
This problem wasn't introduced by this patch, but can a failure in
sata_dwc_probe() after sata_dwc_dma_init_old() cause a use-after-free
[1] on the shared interrupt line?

drivers/ata/sata_dwc_460ex.c:sata_dwc_probe() {
	...
#ifdef CONFIG_SATA_DWC_OLD_DMA
	if (!of_property_present(dev->of_node, "dmas")) {
		err = sata_dwc_dma_init_old(ofdev, hsdev);
		if (err)
			return err;
	}
#endif

	hsdev->phy = devm_phy_optional_get(dev, "sata-phy");
	if (IS_ERR(hsdev->phy))
		return PTR_ERR(hsdev->phy);

	err = phy_init(hsdev->phy);
	if (err)
		goto error_out;
	...
error_out:
	phy_exit(hsdev->phy);
	return err;
}

sata_dwc_dma_init_old() registers a DMA engine and requests a shared
interrupt without devres, but the subsequent error paths in
sata_dwc_probe() return without calling sata_dwc_dma_exit_old().  When
probe fails, the driver core frees the devm-allocated device context while
the shared interrupt remains registered, so a later interrupt on that line
invokes the handler with freed memory.

[1] https://sashiko.dev/#/bug/linux-4f29918f-8b5f-48b5-ab4d-aa40ae6890e7

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117094903.1282096-1-haoxiang_li2024@163.com?part=1

  reply	other threads:[~2026-11-17  9:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  9:49 [PATCH] ata: sata_dwc_460ex: Fix DMA channel leak in sata_dwc_port_start() Haoxiang Li
2026-11-17  9:54 ` sashiko-bot [this message]
2026-11-17 12:05 ` Damien Le Moal
2026-11-17 12:38 ` Niklas Cassel

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-218548@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=haoxiang_li2024@163.com \
    --cc=linux-ide@vger.kernel.org \
    --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.