scsi: message: fusion: Fix a possible data race in mpt_ioc_reset()
Subsystems (2)
PATCH 1/1 scsi: message: fusion: Fix a possible data race in mpt_ioc_reset()
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.
--- drivers/message/fusion/mptbase.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/message/fusion/mptbase.c +3 -0
@@ -6561,9 +6561,12 @@ 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 ;
Signature · 1 line
2.34.1
Quoted 3 lines · Tuo Li
In my opinion, this may be a harmful race, because the value of
ioc->taskmgmt_quiesce_iocan be rewritten bympt_ioc_reset()when another thread is accessing it.
It is a common pattern in the Linux kernel that a variable is set from one thread without using locking and is read by another thread that is holding a lock. It should be sufficient here to use WRITE_ONCE(). I don't think that acquiring and releasing the spin lock is required.
Thanks,
Bart.