From: Niklas Cassel <cassel@kernel.org>
To: Damien Le Moal <dlemoal@kernel.org>,
Niklas Cassel <cassel@kernel.org>,
Baokun Li <libaokun1@huawei.com>,
Sergei Shtylyov <sergei.shtylyov@gmail.com>
Cc: Brian Norris <computersforpeace@gmail.com>,
stable@vger.kernel.org,
Damien Le Moal <damien.lemoal@opensource.wdc.com>,
linux-ide@vger.kernel.org
Subject: [PATCH v5 3/6] ata: sata_fsl: Fix use-after-free of host_priv on probe() failure
Date: Tue, 15 Sep 2026 10:41:29 +0200 [thread overview]
Message-ID: <20260915084127.692494-11-cassel@kernel.org> (raw)
In-Reply-To: <20260915084127.692494-8-cassel@kernel.org>
sata_fsl_host_stop() releases hcr_base and host_priv:
static void sata_fsl_host_stop(struct ata_host *host)
{
struct sata_fsl_host_priv *host_priv = host->private_data;
iounmap(host_priv->hcr_base);
kfree(host_priv);
}
->host_stop() is called by the driver core through the ata_host_stop()
devres action which ata_host_start() registers, so it is called both when
the device is unbound and when probe() fails after the host has been
started.
The error_exit_with_cleanup label of sata_fsl_probe() releases hcr_base
and host_priv as well, and it is reachable from the two
device_create_file() calls which are done after the host has been
activated. In that case sata_fsl_host_stop() runs on an already freed
host_priv, resulting in a use-after-free and a double iounmap()/kfree().
Add a separate error label for the failures happening after the host has
been activated, which only detaches the host and leaves hcr_base and
host_priv to sata_fsl_host_stop().
Note that ata_host_detach() is dropped from error_exit_with_cleanup, as
that label is now only reachable while host is still NULL.
Fixes: 6c8ad7e8cf29 ("sata_fsl: fix UAF in sata_fsl_port_stop when rmmod sata_fsl")
Cc: stable@vger.kernel.org
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
drivers/ata/sata_fsl.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 70b210afd291..4037dd758f87 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -1500,7 +1500,7 @@ static int sata_fsl_probe(struct platform_device *ofdev)
host_priv->intr_coalescing.attr.mode = S_IRUGO | S_IWUSR;
retval = device_create_file(host->dev, &host_priv->intr_coalescing);
if (retval)
- goto error_exit_with_cleanup;
+ goto error_exit_detach;
host_priv->rx_watermark.show = fsl_sata_rx_watermark_show;
host_priv->rx_watermark.store = fsl_sata_rx_watermark_store;
@@ -1510,16 +1510,24 @@ static int sata_fsl_probe(struct platform_device *ofdev)
retval = device_create_file(host->dev, &host_priv->rx_watermark);
if (retval) {
device_remove_file(&ofdev->dev, &host_priv->intr_coalescing);
- goto error_exit_with_cleanup;
+ goto error_exit_detach;
}
return 0;
-error_exit_with_cleanup:
+ /*
+ * Once the host has been activated, hcr_base and host_priv are
+ * released by sata_fsl_host_stop(), which is called by the driver core
+ * through the ata_host_stop() devres action registered by
+ * ata_host_start(). Releasing them here as well would result in a
+ * double iounmap() and a use-after-free.
+ */
+error_exit_detach:
+ ata_host_detach(host);
- if (host)
- ata_host_detach(host);
+ return retval;
+error_exit_with_cleanup:
if (hcr_base)
iounmap(hcr_base);
kfree(host_priv);
--
2.55.0
next prev parent reply other threads:[~2026-09-15 8:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 8:41 [PATCH v5 0/6] ata: Do not release the host resources twice on probe() failure Niklas Cassel
2026-09-15 8:41 ` [PATCH v5 1/6] ata: ahci_st: Do not ignore errors when getting the reset controls Niklas Cassel
2026-09-15 8:48 ` Damien Le Moal
2026-09-15 8:41 ` [PATCH v5 2/6] ata: ahci_st: Assert the power down reset in the probe() error path Niklas Cassel
2026-09-15 8:41 ` Niklas Cassel [this message]
2026-09-15 8:50 ` [PATCH v5 3/6] ata: sata_fsl: Fix use-after-free of host_priv on probe() failure Damien Le Moal
2026-09-15 9:49 ` Niklas Cassel
2026-09-15 8:41 ` [PATCH v5 4/6] ata: libahci: Free the IRQs when activating a multi-IRQ host fails Niklas Cassel
2026-09-15 8:41 ` [PATCH v5 5/6] ata: libata: Do not leave ata_host_stop() registered when activation fails Niklas Cassel
2026-09-15 8:52 ` Damien Le Moal
2026-09-15 8:41 ` [PATCH v5 6/6] ata: libata-core: Fix the ata_host_register() kdoc Niklas Cassel
2026-09-15 9:58 ` [PATCH v5 0/6] ata: Do not release the host resources twice on probe() failure 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=20260915084127.692494-11-cassel@kernel.org \
--to=cassel@kernel.org \
--cc=computersforpeace@gmail.com \
--cc=damien.lemoal@opensource.wdc.com \
--cc=dlemoal@kernel.org \
--cc=libaokun1@huawei.com \
--cc=linux-ide@vger.kernel.org \
--cc=sergei.shtylyov@gmail.com \
--cc=stable@vger.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