From: Wentao Liang <vulab@iscas.ac.cn>
To: 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, Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] scsi: libsas: Fix use-after-free in sas_eh_handle_resets()
Date: Thu, 17 Sep 2026 14:39:46 +0000 [thread overview]
Message-ID: <20260917143946.2157366-1-vulab@iscas.ac.cn> (raw)
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
next reply other threads:[~2026-09-17 14:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 14:39 Wentao Liang [this message]
2026-09-21 11:43 ` John Garry
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=20260917143946.2157366-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--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=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®