From: sashiko-bot@kernel.org
To: "Hongyu Guo" <guohongyu@cmss.chinamobile.com>,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: leapraid: bound the phy index used to update card links
Date: Fri, 04 Dec 2026 07:00:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-249278@kernel.org> (raw)
In-Reply-To: <20261204062938.344219-1-guohongyu@cmss.chinamobile.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: leapraid: leapraid_transport_update_links() reads
topo_node after unlock
--
commit 29d15e789a79f9b363f1bebb028e93bbca890708
Author: Hongyu Guo <guohongyu@cmss.chinamobile.com>
scsi: leapraid: bound the phy index used to update card links
This commit adds a bounds check on phy_index against topo_node->phys_num
in leapraid_transport_update_links() before indexing into
topo_node->card_phy[], logging a warning and returning early if it is
out of range.
> diff --git a/drivers/scsi/leapraid/leapraid_transport.c b/drivers/scsi/leapraid/leapraid_transport.c
> index 77ffbd6ddce4c..7468276b4a102 100644
> --- a/drivers/scsi/leapraid/leapraid_transport.c
> +++ b/drivers/scsi/leapraid/leapraid_transport.c
> @@ -1146,6 +1146,15 @@ void leapraid_transport_update_links(
> return;
> }
>
> + if (phy_index >= topo_node->phys_num) {
> + spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock,
> + flags);
> + dev_warn(&adapter->pdev->dev,
> + "%s: phy index %u out of range, max %u\n",
> + __func__, phy_index, topo_node->phys_num);
> + return;
> + }
[Severity: Medium]
Can reading topo_node->phys_num in dev_warn() trigger a use-after-free?
struct leapraid_topo_node has no reference count or RCU protection, and
leapraid_exp_node_rm() frees expander nodes right after unlinking them
under topo_node_lock.
Once LEAPRAID_EVT_SCAN_DEV_DONE clears scan_start, fw_evt_thread can run
leapraid_transport_update_links() while the SCSI scan thread removes an
expander via leapraid_probe_sas() -> ... -> leapraid_exp_node_rm():
CPU0 (fw_evt_thread) CPU1 (SCSI scan)
leapraid_transport_update_links()
spin_lock_irqsave(...)
topo_node = ...
if (phy_index >= topo_node->phys_num)
spin_unlock_irqrestore(...)
leapraid_probe_sas()
...
leapraid_exp_node_rm()
spin_lock_irqsave(...)
list_del(&topo_node_exp->list)
spin_unlock_irqrestore(...)
kfree(topo_node_exp)
dev_warn(..., topo_node->phys_num) <-- use-after-free
Saving topo_node->phys_num into a local variable before releasing
topo_node_lock avoids dereferencing topo_node after the unlock.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204062938.344219-1-guohongyu@cmss.chinamobile.com?part=1
next prev parent reply other threads:[~2026-12-04 7:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:29 [PATCH] scsi: leapraid: bound the phy index used to update card links Hongyu Guo
2026-12-04 7:00 ` sashiko-bot [this message]
2026-12-04 7:29 ` Hongyu Guo
2026-12-04 7:31 ` guohongyu
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=sashiko-outbox-249278@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=guohongyu@cmss.chinamobile.com \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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