]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: dsa: bcm_sf2: Fix array overrun in bcm_sf2_num_active_ports()
authorFlorian Fainelli <f.fainelli@gmail.com>
Thu, 16 Sep 2021 21:33:35 +0000 (14:33 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 17 Sep 2021 13:21:46 +0000 (14:21 +0100)
After d12e1c464988 ("net: dsa: b53: Set correct number of ports in the
DSA struct") we stopped setting dsa_switch::num_ports to DSA_MAX_PORTS,
which created an off by one error between the statically allocated
bcm_sf2_priv::port_sts array (of size DSA_MAX_PORTS). When
dsa_is_cpu_port() is used, we end-up accessing an out of bounds member
and causing a NPD.

Fix this by iterating with the appropriate port count using
ds->num_ports.

Fixes: d12e1c464988 ("net: dsa: b53: Set correct number of ports in the DSA struct")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/bcm_sf2.c

index 6ce9ec1283e05d63f9a46629d9757b40121fda4a..b6c4b3adb171529426199f5fe6895edd4f644afb 100644 (file)
@@ -68,7 +68,7 @@ static unsigned int bcm_sf2_num_active_ports(struct dsa_switch *ds)
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
        unsigned int port, count = 0;
 
-       for (port = 0; port < ARRAY_SIZE(priv->port_sts); port++) {
+       for (port = 0; port < ds->num_ports; port++) {
                if (dsa_is_cpu_port(ds, port))
                        continue;
                if (priv->port_sts[port].enabled)