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]
Date:   Fri, 28 Jul 2023 18:25:54 +0000
From:   Chengfeng Ye <dg573847474@...il.com>
To:     kashyap.desai@...adcom.com, sumit.saxena@...adcom.com,
        shivasharan.srikanteshwara@...adcom.com, jejb@...ux.ibm.com,
        martin.petersen@...cle.com, bvanassche@....org
Cc:     megaraidlinux.pdl@...adcom.com, linux-scsi@...r.kernel.org,
        linux-kernel@...r.kernel.org, Chengfeng Ye <dg573847474@...il.com>
Subject: [PATCH] scsi: megaraid: Fix potential deadlock on &adapter->lock

As &adapter->lock is acquired by megaraid_isr_iomapped() under irq context,
process context code acquiring the lock should disable irq, otherwise
deadlock could happen if the irq preempt the execution while the
lock is held in process context on the same CPU.

Lock acquisition of &adapter->lock in megaraid_reset_handler() does not 
disable irq. Inside the function there is a calling sequence shows like 
the below where irq is re-enabled by spin_unlock_irqrestore() on
PENDING_LIST_LOCK(adapter).

  spin_lock_irqsave(PENDING_LIST_LOCK(adapter), flags);
  ...
  spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter), flags);

  spin_lock(&adapter->lock)
  ...
  spin_unlock(&adapter->lock)

This flaw was found by an experimental static analysis tool I am developing
for irq-related deadlock.

The patch fix the potential deadlock by also use spin_lock_irqsave() on
&adapter->lock.

Signed-off-by: Chengfeng Ye <dg573847474@...il.com>
---
 drivers/scsi/megaraid/megaraid_mbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index ef2b6380e19a..7edddefcc9a3 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -2603,7 +2603,7 @@ megaraid_reset_handler(struct scsi_cmnd *scp)
 		msleep(1000);
 	}
 
-	spin_lock(&adapter->lock);
+	spin_lock_irqsave(&adapter->lock, flags);
 
 	// If still outstanding commands, bail out
 	if (adapter->outstanding_cmds) {
@@ -2643,7 +2643,7 @@ megaraid_reset_handler(struct scsi_cmnd *scp)
 	}
 
  out:
-	spin_unlock(&adapter->lock);
+	spin_unlock_irqrestore(&adapter->lock, flags);
 	return rval;
 }
 
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ