From: Chaohai Chen <wdhh6@aliyun.com>
To: john.g.garry@oracle.com, yanaijie@huawei.com,
James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com, dlemoal@kernel.org, mingo@kernel.org,
cassel@kernel.org, tglx@linutronix.de, wdhh6@aliyun.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] scsi: libsas: Fix potential array out of bounds in sas_check_*_expander_topo().
Date: Mon, 8 Dec 2025 15:31:21 +0800 [thread overview]
Message-ID: <20251208073121.3773147-1-wdhh6@aliyun.com> (raw)
No check was made to ensure that parent_phy->appended_phy_id is within the
valid range. If the expander reports an invalid phy_id, it may cause the
array to be out of bounds.
Signed-off-by: Chaohai Chen <wdhh6@aliyun.com>
---
drivers/scsi/libsas/sas_expander.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index d953225f6cc2..07633d795182 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -1266,6 +1266,11 @@ static int sas_check_edge_expander_topo(struct domain_device *child,
struct expander_device *parent_ex = &child->parent->ex_dev;
struct ex_phy *child_phy;
+ if (parent_phy->attached_phy_id >= child_ex->num_phys) {
+ pr_err("Invalid attached_phy_id:%u, num_phys:%u\n",
+ parent_phy->attached_phy_id, child_ex->num_phys);
+ return -EINVAL;
+ }
child_phy = &child_ex->ex_phy[parent_phy->attached_phy_id];
if (child->dev_type == SAS_FANOUT_EXPANDER_DEVICE) {
@@ -1296,6 +1301,11 @@ static int sas_check_fanout_expander_topo(struct domain_device *child,
struct expander_device *child_ex = &child->ex_dev;
struct ex_phy *child_phy;
+ if (parent_phy->attached_phy_id >= child_ex->num_phys) {
+ pr_err("Invalid attached_phy_id:%u, num_phys:%u\n",
+ parent_phy->attached_phy_id, child_ex->num_phys);
+ return -EINVAL;
+ }
child_phy = &child_ex->ex_phy[parent_phy->attached_phy_id];
if (parent_phy->routing_attr == TABLE_ROUTING &&
--
2.43.7
next reply other threads:[~2025-12-08 7:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 7:31 Chaohai Chen [this message]
2025-12-08 7:47 ` James Bottomley
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=20251208073121.3773147-1-wdhh6@aliyun.com \
--to=wdhh6@aliyun.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=john.g.garry@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=yanaijie@huawei.com \
/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
all inboxes | Powered by JetHome®