[PATCH 8/9] scsi: qla2xxx: Hold qp_lock when completing command in abort timeout

From: Praneeth Balasubramanian

Date: Sat Dec 05 2026 - 01:34:08 EST


qla24xx_abort_iocb_timeout() removes the original command from the
outstanding command array under qpair->qp_lock_ptr, then drops the lock
before calling sp->cmd_sp->done(). The done callback completes and frees
the original command, which ends in qla2x00_sp_free_dma() or
qla2xxx_qpair_sp_free_dma() and their qla_put_buf() call.
qla_put_buf() must run under qp_lock_ptr, as its comment and
lockdep_assert_held() state, so on this path the buffer is returned to
the pool without the lock.

The unlocked qla_put_buf() can race qla_get_buf() on the same qpair. The
pool accounting is then updated non-atomically, and qla_trim_buf() can
dma_pool_free() a buffer that qla_get_buf() has just handed to a new
EDIF command, which is then submitted using the freed buffer. This
affects the EDIF buffer pool only and needs a firmware abort timeout to
trigger.

Call sp->cmd_sp->done() before dropping qp_lock_ptr, so the completion
chain runs under the same lock as the interrupt completion path, which
already invokes this callback with the lock held. qla2x00_abort_srb
calls done under the lock as well, and no done or free path takes the
qp lock itself, so no new lock ordering is introduced. The abort srb
itself never takes a pool buffer, so its own completion stays outside
the lock.

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

Fixes: 71c80b75ce8f ("scsi: qla2xxx: Do command completion on abort timeout")
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.

drivers/scsi/qla2xxx/qla_init.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index ccb039d97353..3d80ead06aa1 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -139,15 +139,17 @@ static void qla24xx_abort_iocb_timeout(void *data)
break;
}
}
- spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
-
if (cmdsp_found && sp->cmd_sp) {
/*
* This done function should take care of
* original command ref: INIT
+ *
+ * The completion path ends in qla_put_buf(), which
+ * must run under qp_lock.
*/
sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
}
+ spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);

if (sp_found) {
abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
--
2.25.1