From: Wentao Liang <vulab@iscas.ac.cn>
To: John Garry <john.garry@linux.dev>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
Dan Williams <djbw@kernel.org>,
Martin K. Petersen <martin.petersen@oracle.com>,
Jason Yan <yanaijie@huawei.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, vulab@iscas.ac.cn
Subject: [PATCH v2] scsi: libsas: Fix use-after-free in sas_eh_handle_resets()
Date: Sat, 07 Nov 2026 14:53:23 +0000 [thread overview]
Message-ID: <20261107145323.314159-1-vulab@iscas.ac.cn> (raw)
In-Reply-To: <085fcc2e-112f-4d4c-a07d-9d0962936e44@linux.dev>
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 before dropping the reference.
The candidate was found with static analysis tools; DeepSeek and GPT-6.1
Sol were used to audit it and to help prepare this fix.
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>
---
Changes in v2:
- Adopt John's suggestion: clear SAS_DEV_EH_PENDING before
sas_put_device(), so the locked section is back to just ha->eh_active--.
Sorry for the late reply.
- Rebuilt on v7.4-rc1 with W=1; drivers/scsi/libsas/ builds cleanly.
- Link to v1: https://lore.kernel.org/all/20260917143946.2157366-1-vulab@iscas.ac.cn/
drivers/scsi/libsas/sas_scsi_host.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 76517c8f0684..448f35de67fb 100644
--- 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);
prev parent reply other threads:[~2026-11-07 14:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 14:39 [PATCH] " Wentao Liang
2026-09-21 11:43 ` John Garry
2026-11-07 14:53 ` Wentao Liang [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=20261107145323.314159-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=James.Bottomley@HansenPartnership.com \
--cc=djbw@kernel.org \
--cc=john.garry@linux.dev \
--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®