The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Nilesh Javali <njavali@marvell.com>,
	Manish Rangankar <mrangankar@marvell.com>,
	GR-ETH-Storage-Upstream@marvell.com,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Martin K. Petersen" <mkp@kernel.org>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
	stable@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/9] scsi: bnx2i: Hold the session back_lock around iscsi_itt_to_task()
Date: Fri,  4 Dec 2026 22:32:21 -0800	[thread overview]
Message-ID: <20261205063229.2518424-2-praneethb2002@gmail.com> (raw)
In-Reply-To: <20261205063229.2518424-1-praneethb2002@gmail.com>

bnx2i_send_iscsi_tmf() looks up the task to abort with
iscsi_itt_to_task(), then reads ctask->sc and the command's data
direction. iscsi_itt_to_task() requires the session back_lock, but
bnx2i holds only the frwd_lock here. A TODO comment and an
__assume_ctx_lock() annotation mark the gap.

The completion path runs under back_lock. It clears task->sc and
completes the command. If it runs between the !ctask->sc check and the
ref_sc load, ref_sc is NULL and the data direction read faults.

Take back_lock around the lookup and the two reads. libiscsi already
nests back_lock inside frwd_lock, so the lock order does not change.
Remove the TODO and the annotation.

This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.

Fixes: 659743b02c41 ("[SCSI] libiscsi: Reduce locking contention in fast path")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by an LLM-based audit, part of research at UCSB SecLab.
    An LLM turned a kernel comment into a rule, and three LLM votes checked
    the code against it. The fix and changelog were drafted with GLM-5.3 and
    checked against the source with Claude Opus 5.5. I reviewed the patch
    and take responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
    clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
    reproducer. I do not have this hardware.
    
    This is against linux-next, where the lock context annotations for SCSI
    added the TODO. In mainline the same lookup has no TODO and
    iscsi_itt_to_task() takes (conn, itt). The fix is the same there.

 drivers/scsi/bnx2i/bnx2i_hwi.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c
index c22f1c981d02..70bc5e5f9b8b 100644
--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
@@ -405,13 +405,10 @@ int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
 	switch (tmfabort_hdr->flags & ISCSI_FLAG_TM_FUNC_MASK) {
 	case ISCSI_TM_FUNC_ABORT_TASK:
 	case ISCSI_TM_FUNC_TASK_REASSIGN:
-		/*
-		 * TODO: hold session->back_lock around the iscsi_itt_to_task()
-		 * call below.
-		 */
-		__assume_ctx_lock(&session->back_lock);
+		spin_lock_bh(&session->back_lock);
 		ctask = iscsi_itt_to_task(session, conn, tmfabort_hdr->rtt);
-		if (!ctask || !ctask->sc)
+		if (!ctask || !ctask->sc) {
+			spin_unlock_bh(&session->back_lock);
 			/*
 			 * the iscsi layer must have completed the cmd while
 			 * was starting up.
@@ -421,6 +418,7 @@ int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
 			 *       In this case, the task must be aborted
 			 */
 			return 0;
+		}
 
 		ref_sc = ctask->sc;
 		if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
@@ -429,6 +427,7 @@ int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
 		else
 			dword = (ISCSI_TASK_TYPE_READ <<
 				 ISCSI_CMD_REQUEST_TYPE_SHIFT);
+		spin_unlock_bh(&session->back_lock);
 		tmfabort_wqe->ref_itt = (dword |
 					(tmfabort_hdr->rtt & ISCSI_ITT_MASK));
 		break;
-- 
2.25.1


  reply	other threads:[~2026-12-05  6:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  6:32 [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers Praneeth Balasubramanian
2026-12-05  6:32 ` Praneeth Balasubramanian [this message]
2026-12-05  6:32 ` [PATCH 2/9] scsi: mpt3sas: do not keep an enclosure pointer across a host reset Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 3/9] scsi: pmcraid: Take host_lock around scsi_report_bus_reset() Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 4/9] scsi: ipr: Skip dump entries whose length is not a 4 byte multiple Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 5/9] scsi: arm: Fix eh_abort race against the interrupt handler Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 6/9] scsi: csiostor: hold hw lock when issuing port stats mailbox command Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 7/9] scsi: fnic: Hold fnic_lock for the oxid calls in the FIP timer work Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 8/9] scsi: qla2xxx: Hold qp_lock when completing command in abort timeout Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 9/9] scsi: target: core: Fix PRgeneration race in REGISTER AND MOVE Praneeth Balasubramanian

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=20261205063229.2518424-2-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --cc=GR-ETH-Storage-Upstream@marvell.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=mrangankar@marvell.com \
    --cc=njavali@marvell.com \
    --cc=stable@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox