public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] scsi: message: fusion: Fix a possible data race in mpt_ioc_reset()
@ 2023-10-30  9:09 Tuo Li
  0 siblings, 0 replies; only message in thread
From: Tuo Li @ 2023-10-30  9:09 UTC (permalink / raw)
  To: sathya.prakash, sreekanth.reddy, suganath-prabu.subramani
  Cc: MPT-FusionLinux.pdl, linux-scsi, linux-kernel, baijiaju1990,
	Tuo Li, BassCheck

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-30  9:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-30  9:09 [PATCH v2] scsi: message: fusion: Fix a possible data race in mpt_ioc_reset() Tuo Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox