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,
	john.g.garry@oracle.com, linux-kernel@vger.kernel.org,
	linux-scsi@vger.kernel.org, martin.petersen@oracle.com,
	yanaijie@huawei.com, stable@vger.kernel.org
Subject: Re: [PATCH] scsi: libsas: Fix use-after-free in sas_eh_handle_resets()
Date: Mon, 21 Sep 2026 12:43:55 +0100	[thread overview]
Message-ID: <085fcc2e-112f-4d4c-a07d-9d0962936e44@linux.dev> (raw)
In-Reply-To: <20260917143946.2157366-1-vulab@iscas.ac.cn>

On 9/17/26 15:39, Wentao Liang wrote:
> sas_eh_handle_resets() drops the reference it took on the domain device
> with sas_put_device() and then accesses dev->state again while holding
> ha->lock. The put may release the last reference, so the clear_bit()
> can touch freed memory.
> 
> Clear the pending flag first and drop the reference last.
> 
> Fixes: 5db45bdc87ce ("[SCSI] libsas: enforce eh strategy handlers only in eh context")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>   drivers/scsi/libsas/sas_scsi_host.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
> index c83282733ec4..14ca19c93c32 100644
> --- a/drivers/scsi/libsas/sas_scsi_host.c
> +++ b/drivers/scsi/libsas/sas_scsi_host.c
> @@ -680,10 +680,15 @@ static void sas_eh_handle_resets(struct Scsi_Host *shost)
>   		if (test_and_clear_bit(SAS_DEV_RESET, &dev->state))
>   			i->dft->lldd_I_T_nexus_reset(dev);
>   
> -		sas_put_device(dev);
>   		spin_lock_irq(&ha->lock);
>   		clear_bit(SAS_DEV_EH_PENDING, &dev->state);
>   		ha->eh_active--;
> +		spin_unlock_irq(&ha->lock);
> +
> +		/* dev->state is no longer used, this may be the last reference */
> +		sas_put_device(dev);
> +
> +		spin_lock_irq(&ha->lock);
>   	}
>   	spin_unlock_irq(&ha->lock);
>   }


I think that the following is a better change:

----8<-----

--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -695,9 +695,9 @@ static void sas_eh_handle_resets(struct Scsi_Host 
*shost)
                 if (test_and_clear_bit(SAS_DEV_RESET, &dev->state))
                         i->dft->lldd_I_T_nexus_reset(dev);

+               clear_bit(SAS_DEV_EH_PENDING, &dev->state);
                 sas_put_device(dev);
                 spin_lock_irq(&ha->lock);
-               clear_bit(SAS_DEV_EH_PENDING, &dev->state);
                 ha->eh_active--;
         }
         spin_unlock_irq(&ha->lock);


---->8-----

      reply	other threads:[~2026-09-21 11:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 14:39 Wentao Liang
2026-09-21 11:43 ` 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=085fcc2e-112f-4d4c-a07d-9d0962936e44@linux.dev \
    --to=john.garry@linux.dev \
    --cc=JBottomley@Parallels.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=djbw@kernel.org \
    --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=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®