Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: 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: Re: [PATCH v5 3/6] ata: sata_fsl: Fix use-after-free of host_priv on probe() failure
Date: Tue, 15 Sep 2026 15:50:50 +0700	[thread overview]
Message-ID: <e5245a11-d6a0-42d8-a6ef-1b5ca9622413@kernel.org> (raw)
In-Reply-To: <20260915084127.692494-11-cassel@kernel.org>

On 2026/09/15 15:41, Niklas Cassel wrote:
> 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>

Looks good.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

One nit below that is worth fixing I think.

> +	/*
> +	 * 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:

The label should really go above the comment block to clearly show this is the
explanation for what is done in this label block.

> +	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);


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2026-09-15  8:50 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 ` [PATCH v5 3/6] ata: sata_fsl: Fix use-after-free of host_priv on probe() failure Niklas Cassel
2026-09-15  8:50   ` Damien Le Moal [this message]
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=e5245a11-d6a0-42d8-a6ef-1b5ca9622413@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=cassel@kernel.org \
    --cc=computersforpeace@gmail.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --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