* [PATCH] scsi: libsas: Fix potential array out of bounds in sas_check_*_expander_topo().
@ 2025-12-08 7:31 Chaohai Chen
2025-12-08 7:47 ` James Bottomley
0 siblings, 1 reply; 2+ messages in thread
From: Chaohai Chen @ 2025-12-08 7:31 UTC (permalink / raw)
To: john.g.garry, yanaijie, James.Bottomley, martin.petersen,
dlemoal, mingo, cassel, tglx, wdhh6
Cc: linux-scsi, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] scsi: libsas: Fix potential array out of bounds in sas_check_*_expander_topo().
2025-12-08 7:31 [PATCH] scsi: libsas: Fix potential array out of bounds in sas_check_*_expander_topo() Chaohai Chen
@ 2025-12-08 7:47 ` James Bottomley
0 siblings, 0 replies; 2+ messages in thread
From: James Bottomley @ 2025-12-08 7:47 UTC (permalink / raw)
To: Chaohai Chen, john.g.garry, yanaijie, martin.petersen, dlemoal,
mingo, cassel, tglx
Cc: linux-scsi, linux-kernel
On Mon, 2025-12-08 at 15:31 +0800, Chaohai Chen wrote:
> 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.
We tend to assume hardware operates correctly unless there's a known
faulty device that we need to code around. Have you got a device that
exhibits this problem? Assuming you do, I think the fix is a little
harsh: wouldn't it be better to ignore the misnumbered phy than to
ignore the entire expander?
Regards,
James
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-08 7:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-08 7:31 [PATCH] scsi: libsas: Fix potential array out of bounds in sas_check_*_expander_topo() Chaohai Chen
2025-12-08 7:47 ` James Bottomley
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®