From: Chengfeng Ye <dg573847474@gmail.com>
To: sathya.prakash@broadcom.com, sreekanth.reddy@broadcom.com,
suganath-prabu.subramani@broadcom.com
Cc: James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com, MPT-FusionLinux.pdl@broadcom.com,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Chengfeng Ye <dg573847474@gmail.com>
Subject: [PATCH v2] scsi: mpt3sas: Fix use-after-free race in event log access
Date: Sun, 18 Jan 2026 07:02:56 +0000 [thread overview]
Message-ID: <20260118070256.321184-1-dg573847474@gmail.com> (raw)
A use-after-free race exists between ioctl operations accessing the
event log and device removal freeing it. The race occurs because
ioc->remove_host flag is set without synchronization, creating
a window where an ioctl can pass the removal check but still access
freed memory.
Race scenario:
CPU0 (ioctl) CPU1 (device removal)
---------------- ---------------------
_ctl_ioctl_main()
mutex_lock(&pci_access_mutex)
if (!ioc->remove_host)
[check passes]
scsih_remove()
ioc->remove_host = 1
mpt3sas_ctl_release()
kfree(ioc->event_log)
_ctl_eventreport()
copy_to_user(..., ioc->event_log, ...) <- use-after-free
mutex_unlock(&pci_access_mutex)
Fix by setting ioc->remove_host while holding pci_access_mutex. This
ensures the ioctl path either completes before removal starts, or sees
the flag and returns -EAGAIN.
Fixes: 6a965ee1892a ("scsi: mpt3sas: Suppress a warning in debug kernel")
Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 7092d0debef3..973893528747 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -11264,7 +11264,10 @@ static void scsih_remove(struct pci_dev *pdev)
if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc))
return;
- ioc->remove_host = 1;
+ /* Set remove_host flag under pci_access_mutex to synchronize with ioctl path */
+ scoped_guard(mutex, &ioc->pci_access_mutex) {
+ ioc->remove_host = 1;
+ }
if (!pci_device_is_present(pdev)) {
mpt3sas_base_pause_mq_polling(ioc);
--
2.25.1
next reply other threads:[~2026-01-18 7:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-18 7:02 Chengfeng Ye [this message]
2026-01-18 8:31 ` Markus Elfring
2026-01-18 8:46 ` Chengfeng Ye
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=20260118070256.321184-1-dg573847474@gmail.com \
--to=dg573847474@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=MPT-FusionLinux.pdl@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=sathya.prakash@broadcom.com \
--cc=sreekanth.reddy@broadcom.com \
--cc=suganath-prabu.subramani@broadcom.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®