[PATCH 1/9] scsi: bnx2i: Hold the session back_lock around iscsi_itt_to_task()

From: Praneeth Balasubramanian

Date: Sat Dec 05 2026 - 01:33:26 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Praneeth Balasubramanian <praneethb2002@xxxxxxxxx>
---

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