* [PATCH] scsi: libsas: Fix use-after-free in sas_eh_handle_resets()
@ 2026-09-17 14:39 Wentao Liang
2026-09-21 11:43 ` John Garry
0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-17 14:39 UTC (permalink / raw)
To: JBottomley
Cc: James.Bottomley, djbw, john.g.garry, linux-kernel, linux-scsi,
martin.petersen, yanaijie, Wentao Liang, stable
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);
}
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] scsi: libsas: Fix use-after-free in sas_eh_handle_resets()
2026-09-17 14:39 [PATCH] scsi: libsas: Fix use-after-free in sas_eh_handle_resets() Wentao Liang
@ 2026-09-21 11:43 ` John Garry
0 siblings, 0 replies; 2+ messages in thread
From: John Garry @ 2026-09-21 11:43 UTC (permalink / raw)
To: Wentao Liang, JBottomley
Cc: James.Bottomley, djbw, john.g.garry, linux-kernel, linux-scsi,
martin.petersen, yanaijie, stable
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-----
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-21 11:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 14:39 [PATCH] scsi: libsas: Fix use-after-free in sas_eh_handle_resets() Wentao Liang
2026-09-21 11:43 ` John Garry
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®