All of lore.kernel.org
 help / color / mirror / Atom feed
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 v2] scsi: message: fusion: Fix a possible data race in mpt_ioc_reset()
Date: Mon, 30 Oct 2023 17:09:24 +0800	[thread overview]
Message-ID: <20231030090924.2873408-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(), which can cause possible data
races:

  case MPT_IOC_SETUP_RESET:
    ioc->taskmgmt_quiesce_io = 1;

To fix this possible data race, WRITE_ONCE() is used to access the
variable ioc->taskmgmt_lock.

Reported-by: BassCheck <bass@buaa.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
v2:
* Replace lock operations with a WRITE_ONCE to avoid possible data 
races.
  Thank Bart Van Assche for helpful advice.
---
 drivers/message/fusion/mptbase.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 4bf669c55649..6c67eec9ab85 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -6563,7 +6563,7 @@ mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
 {
 	switch (reset_phase) {
 	case MPT_IOC_SETUP_RESET:
-		ioc->taskmgmt_quiesce_io = 1;
+		WRITE_ONCE(ioc->taskmgmt_quiesce_io, 1);
 		dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
 		    "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
 		break;
-- 
2.34.1


                 reply	other threads:[~2023-10-30  9:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20231030090924.2873408-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.