From: Tuo Li <islituo@gmail.com>
To: sathya.prakash@broadcom.com, sreekanth.reddy@broadcom.com,
suganath-prabu.subramani@broadcom.com
Cc: MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org, baijiaju1990@outlook.com,
Tuo Li <islituo@gmail.com>, BassCheck <bass@buaa.edu.cn>
Subject: [PATCH] scsi: message: fusion: Fix a possible data race in mpt_ioc_reset()
Date: Sat, 15 Jul 2023 10:53:06 +0800 [thread overview]
Message-ID: <20230715025306.164847-1-islituo@gmail.com> (raw)
The variable ioc->taskmgmt_quiesce_io is often protected by the lock
ioc->taskmgmt_lock when is accessed. Here is an example in
mpt_SoftResetHandler():
spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
...
ioc->taskmgmt_quiesce_io = 0;
...
spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
However, ioc->taskmgmt_quiesce_io is set to 1 without holding the lock
ioc->taskmgmt_lock in mpt_ioc_reset():
case MPT_IOC_SETUP_RESET:
ioc->taskmgmt_quiesce_io = 1;
In my opinion, this may be a harmful race, because the value of
ioc->taskmgmt_quiesce_io can be rewritten by mpt_ioc_reset() when another
thread is accessing it.
To fix this possible data race, a lock and unlock pair is added when
accessing the variable ioc->taskmgmt_quiesce_io.
Reported-by: BassCheck <bass@buaa.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
drivers/message/fusion/mptbase.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 4bf669c55649..560057daf4ee 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -6561,9 +6561,13 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
static int
mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
{
+ unsigned long flags;
+
switch (reset_phase) {
case MPT_IOC_SETUP_RESET:
+ spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
ioc->taskmgmt_quiesce_io = 1;
+ spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
"%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
break;
--
2.34.1
next reply other threads:[~2023-07-15 2:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-15 2:53 Tuo Li [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-10-24 7:27 [PATCH] scsi: message: fusion: Fix a possible data race in mpt_ioc_reset() Tuo Li
2023-10-24 19:03 ` Bart Van Assche
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=20230715025306.164847-1-islituo@gmail.com \
--to=islituo@gmail.com \
--cc=MPT-FusionLinux.pdl@broadcom.com \
--cc=baijiaju1990@outlook.com \
--cc=bass@buaa.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--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