[PATCH 6/9] scsi: csiostor: hold hw lock when issuing port stats mailbox command
From: Praneeth Balasubramanian
Date: Sat Dec 05 2026 - 01:33:53 EST
csio_get_phy_port_stats() calls csio_mb_issue() without holding
hw->lock. The comment above csio_mb_issue() says that the caller should
hold the hw lock, and the other mailbox users in the driver do. If
another thread uses the mailbox at the same time, the two commands can
interfere with each other. The path is reached through csio_get_stats()
from the fc_host statistics attributes in sysfs, which every user can
read.
Take hw->lock around the csio_mb_issue() call in
csio_get_phy_port_stats(). This matches the locking of the other sysfs
handlers in csio_attr.c. csio_mb_issue() polls with mdelay() instead of
sleeping, so it is safe to call under spin_lock_irq().
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: a3667aaed569 ("[SCSI] csiostor: Chelsio FCoE offload driver")
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/csiostor/csio_lnode.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/csiostor/csio_lnode.c b/drivers/scsi/csiostor/csio_lnode.c
index 161973957976..7fef0882862f 100644
--- a/drivers/scsi/csiostor/csio_lnode.c
+++ b/drivers/scsi/csiostor/csio_lnode.c
@@ -1408,11 +1408,14 @@ csio_get_phy_port_stats(struct csio_hw *hw, uint8_t portid,
portparams.nstats = 4;
csio_fcoe_read_portparams_init_mb(hw, mbp, CSIO_MB_DEFAULT_TMO,
&portparams, NULL);
+ spin_lock_irq(&hw->lock);
if (csio_mb_issue(hw, mbp)) {
csio_err(hw, "Issue of FCoE port params failed!\n");
mempool_free(mbp, hw->mb_mempool);
+ spin_unlock_irq(&hw->lock);
return -EINVAL;
}
+ spin_unlock_irq(&hw->lock);
csio_mb_process_portparams_rsp(hw, mbp, &retval,
&portparams, port_stats);
}
--
2.25.1