lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20230928144721.31794-1-dg573847474@gmail.com>
Date:   Thu, 28 Sep 2023 14:47:21 +0000
From:   Chengfeng Ye <dg573847474@...il.com>
To:     jejb@...ux.ibm.com, martin.petersen@...cle.com,
        john.g.garry@...cle.com, dlemoal@...nel.org, yanaijie@...wei.com,
        jinpu.wang@...os.com
Cc:     linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org,
        Chengfeng Ye <dg573847474@...il.com>
Subject: [PATCH v2] scsi: mvsas: fix potential deadlock on &task->task_state_lock

&mvi->lock and &task->task_state_lock could be acquired under irq
context from mvs_64xx_isr(). As mvs_port_deformed() also acquire
the lock, called from workqueue sas_suspend_devices() under process
context, and without irq protection.

<deadlock #1>
mvs_port_deformed()
--> mvs_port_notify_deformed()
--> mvs_do_release_task()
--> mvs_int_rx()
--> mvs_slot_complete()
--> spin_lock(&mvi->lock)
<interrupt>
   --> mvs_64xx_isr()
   --> spin_lock(&mvi->lock)

<deadlock #2>
mvs_port_deformed()
--> mvs_port_notify_deformed()
--> mvs_do_release_task()
--> mvs_int_rx()
--> mvs_slot_complete()
--> spin_lock(&task->task_state_lock)
<interrupt>
   --> mvs_64xx_isr()
   --> mvs_int_rx()
   --> mvs_slot_complete()
   --> spin_lock(&task->task_state_lock)

Another strange thing is that while inspecting the code I find
mvs_do_release_task() should be called with phy->mvi locked held,
but the call chain from mvs_port_notify_deformed() seems do not
hold the lock.

The current patch just switch spin_lock(&task->task_state_lock)
to spin_lock_irqsave(). If I didn't miss anything, seems the better
way could be adding a spin_lock_irqsave() to protect mvi->lock at
mvs_port_notify_deformed()?

Signed-off-by: Chengfeng Ye <dg573847474@...il.com>
---
Change in v2:
  Declare varible name as "irqflags", since "flags" is already used
---
 drivers/scsi/mvsas/mv_sas.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index 1444b1f1c4c8..ea48c1e9f185 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -1534,6 +1534,7 @@ int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags)
 	struct mvs_device *mvi_dev = NULL;
 	struct task_status_struct *tstat;
 	struct domain_device *dev;
+	unsigned long irqflags;
 	u32 aborted;
 
 	void *to;
@@ -1546,12 +1547,12 @@ int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags)
 	dev = task->dev;
 	mvi_dev = dev->lldd_dev;
 
-	spin_lock(&task->task_state_lock);
+	spin_lock_irqsave(&task->task_state_lock, irqflags);
 	task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
 	task->task_state_flags |= SAS_TASK_STATE_DONE;
 	/* race condition*/
 	aborted = task->task_state_flags & SAS_TASK_STATE_ABORTED;
-	spin_unlock(&task->task_state_lock);
+	spin_unlock_irqrestore(&task->task_state_lock, irqflags);
 
 	memset(tstat, 0, sizeof(*tstat));
 	tstat->resp = SAS_TASK_COMPLETE;
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ