Skip to contentSkip to conversation

mpi3mr: sanitise num_phys

PATCH Applied Tomas Henzl 3 participants 4 messages Feb 26, 2024 – May 11, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mpi3mr: sanitise num_phys

Information is stored in mr_sas_port->phy_mask, values larger then size of this field shouldn't be allowed.

---
 drivers/scsi/mpi3mr/mpi3mr_transport.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/scsi/mpi3mr/mpi3mr_transport.c +10 -0
index c0c8ab586957..352f006c8fe4 100644
@@ -1355,11 +1355,21 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
 	mpi3mr_sas_port_sanity_check(mrioc, mr_sas_node,
 	    mr_sas_port->remote_identify.sas_address, hba_port);
 
+	if (mr_sas_node->num_phys > sizeof(mr_sas_port->phy_mask) * 8)
+		ioc_info(mrioc, "max port count %u could be too high\n",
+		    mr_sas_node->num_phys);
+
 	for (i = 0; i < mr_sas_node->num_phys; i++) {
 		if ((mr_sas_node->phy[i].remote_identify.sas_address !=
 		    mr_sas_port->remote_identify.sas_address) ||
 		    (mr_sas_node->phy[i].hba_port != hba_port))
 			continue;
+
+		if (i > sizeof(mr_sas_port->phy_mask) * 8) {
+			ioc_warn(mrioc, "skipping port %u, max allowed value is %lu\n",
+			    i, sizeof(mr_sas_port->phy_mask) * 8);
+			goto out_fail;
+		}
 		list_add_tail(&mr_sas_node->phy[i].port_siblings,
 		    &mr_sas_port->phy_list);
 		mr_sas_port->num_phys++;
Signature · 1 line
2.43.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Tomas Henzl

Information is stored in mr_sas_port->phy_mask, values larger then size of this field shouldn't be allowed.

---

Quoted 32 lines
 drivers/scsi/mpi3mr/mpi3mr_transport.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/scsi/mpi3mr/mpi3mr_transport.c +10 -1
index c0c8ab586957..352f006c8fe4 100644
@@ -1355,11 +1355,21 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
        mpi3mr_sas_port_sanity_check(mrioc, mr_sas_node,
            mr_sas_port->remote_identify.sas_address, hba_port);
 
+       if (mr_sas_node->num_phys > sizeof(mr_sas_port->phy_mask) * 8)
+               ioc_info(mrioc, "max port count %u could be too high\n",
+                   mr_sas_node->num_phys);
+
        for (i = 0; i < mr_sas_node->num_phys; i++) {
                if ((mr_sas_node->phy[i].remote_identify.sas_address !=
                    mr_sas_port->remote_identify.sas_address) ||
                    (mr_sas_node->phy[i].hba_port != hba_port))
                        continue;
+
+               if (i > sizeof(mr_sas_port->phy_mask) * 8) {
+                       ioc_warn(mrioc, "skipping port %u, max allowed value is %lu\n",
+                           i, sizeof(mr_sas_port->phy_mask) * 8);
+                       goto out_fail;
+               }
                list_add_tail(&mr_sas_node->phy[i].port_siblings,
                    &mr_sas_port->phy_list);
                mr_sas_port->num_phys++;
--

2.43.2

#2 lore raw

Sathya,

Quoted 2 lines
Quoted 2 lines

Information is stored in mr_sas_port->phy_mask, values larger then size of this field shouldn't be allowed.

Applied to 6.10/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering