mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Garry <john.garry@linux.dev>
To: Wentao Liang <vulab@iscas.ac.cn>, JBottomley@Parallels.com
Cc: James.Bottomley@HansenPartnership.com, djbw@kernel.org,
	jacek.danecki@intel.com, john.g.garry@oracle.com,
	linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	martin.petersen@oracle.com, stern@rowland.harvard.edu,
	yanaijie@huawei.com, stable@vger.kernel.org
Subject: Re: [PATCH] scsi: libsas: Fix use-after-free in sas_suspend_devices()
Date: Thu, 17 Sep 2026 17:45:48 +0100	[thread overview]
Message-ID: <b0e2de23-7421-4217-bd37-e98e59bef873@linux.dev> (raw)
In-Reply-To: <20260917143800.2157286-1-vulab@iscas.ac.cn>

On 9/17/26 15:38, Wentao Liang wrote:
> sas_suspend_devices() walks port->dev_list with list_for_each_entry()
> while sas_notify_lldd_dev_gone() may drop the last reference 

The low-level device driver should not keep (nor put) a reference to the 
domain device.

Notice how sas_put_device() is in sas_internal.h ?

> and free
> the current device, so the next iteration dereferences freed memory.
> 
> Use list_for_each_entry_safe() to keep the next entry around.
> 
> Fixes: 303694eeee5e ("[SCSI] libsas: suspend / resume support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>   drivers/scsi/libsas/sas_discover.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/libsas/sas_discover.c b/drivers/scsi/libsas/sas_discover.c
> index b07062db50b2..91045966612e 100644
> --- a/drivers/scsi/libsas/sas_discover.c
> +++ b/drivers/scsi/libsas/sas_discover.c
> @@ -231,7 +231,7 @@ static void sas_probe_devices(struct asd_sas_port *port)
>   static void sas_suspend_devices(struct work_struct *work)
>   {
>   	struct asd_sas_phy *phy;
> -	struct domain_device *dev;
> +	struct domain_device *dev, *n;
>   	struct sas_discovery_event *ev = to_sas_discovery_event(work);
>   	struct asd_sas_port *port = ev->port;
>   	struct Scsi_Host *shost = port->ha->shost;
> @@ -245,7 +245,7 @@ static void sas_suspend_devices(struct work_struct *work)
>   	 * suspension, we force the issue here to keep the reference
>   	 * counts aligned
>   	 */
> -	list_for_each_entry(dev, &port->dev_list, dev_list_node)
> +	list_for_each_entry_safe(dev, n, &port->dev_list, dev_list_node)
>   		sas_notify_lldd_dev_gone(dev);
>   
>   	/* we are suspending, so we know events are disabled and


      reply	other threads:[~2026-09-17 16:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 14:38 Wentao Liang
2026-09-17 16:45 ` John Garry [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=b0e2de23-7421-4217-bd37-e98e59bef873@linux.dev \
    --to=john.garry@linux.dev \
    --cc=JBottomley@Parallels.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=djbw@kernel.org \
    --cc=jacek.danecki@intel.com \
    --cc=john.g.garry@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=vulab@iscas.ac.cn \
    --cc=yanaijie@huawei.com \
    /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

all inboxes | Powered by JetHome®