Skip to contentSkip to conversation

net: dsa: bcm_sf2: potential array overflow in bcm_sf2_sw_suspend()

PATCH Applied Dan Carpenter 4 participants 4 messages Feb 13, 2019 – Feb 15, 2019

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

PATCH 1/1 net: dsa: bcm_sf2: potential array overflow in bcm_sf2_sw_suspend()

The value of ->num_ports comes from bcm_sf2_sw_probe() and it is less than or equal to DSA_MAX_PORTS. The ds->ports[] array is used inside the dsa_is_user_port() and dsa_is_cpu_port() functions. The ds->ports[] array is allocated in dsa_switch_alloc() and it has ds->num_ports elements so this leads to a static checker warning about a potential out of bounds read.

Fixes 8cfa94984c9c ("net: dsa: bcm_sf2: add suspend/resume callbacks")
---
 drivers/net/dsa/bcm_sf2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/bcm_sf2.c +1 -1
index 5193da67dcdc..98696a88fa1c 100644
@@ -690,7 +690,7 @@ static int bcm_sf2_sw_suspend(struct dsa_switch *ds)
 	 * port, the other ones have already been disabled during
 	 * bcm_sf2_sw_setup
 	 */
-	for (port = 0; port < DSA_MAX_PORTS; port++) {
+	for (port = 0; port < ds->num_ports; port++) {
 		if (dsa_is_user_port(ds, port) || dsa_is_cpu_port(ds, port))
 			bcm_sf2_port_disable(ds, port, NULL);
 	}
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Dan Carpenter

The value of ->num_ports comes from bcm_sf2_sw_probe() and it is less than or equal to DSA_MAX_PORTS. The ds->ports[] array is used inside the dsa_is_user_port() and dsa_is_cpu_port() functions. The ds->ports[] array is allocated in dsa_switch_alloc() and it has ds->num_ports elements so this leads to a static checker warning about a potential out of bounds read.

Fixes 8cfa94984c9c ("net: dsa: bcm_sf2: add suspend/resume callbacks")
maintainer Applied
#2 lore raw
In reply to Dan Carpenter

From: Dan Carpenter <[email protected]>
Date: Wed, 13 Feb 2019 11:23:04 +0300

Quoted 9 lines

The value of ->num_ports comes from bcm_sf2_sw_probe() and it is less than or equal to DSA_MAX_PORTS. The ds->ports[] array is used inside the dsa_is_user_port() and dsa_is_cpu_port() functions. The ds->ports[] array is allocated in dsa_switch_alloc() and it has ds->num_ports elements so this leads to a static checker warning about a potential out of bounds read.

Fixes 8cfa94984c9c ("net: dsa: bcm_sf2: add suspend/resume callbacks")

Applied.

#3 lore raw
Quoted 9 lines · David Miller

From: Dan Carpenter <[email protected]>
Date: Wed, 13 Feb 2019 11:23:04 +0300

Quoted 6 lines

The value of ->num_ports comes from bcm_sf2_sw_probe() and it is less than or equal to DSA_MAX_PORTS. The ds->ports[] array is used inside the dsa_is_user_port() and dsa_is_cpu_port() functions. The ds->ports[] array is allocated in dsa_switch_alloc() and it has ds->num_ports elements so this leads to a static checker warning about a potential out of bounds read.

This would not happen here because bcm_sf2 calls b53_switch_alloc() which does allocate the full port range (not for a good reason), but it's good to fix that anyways.

Quoted 6 lines
Quoted 3 lines
Fixes 8cfa94984c9c ("net: dsa: bcm_sf2: add suspend/resume callbacks")

Applied.

Signature · 1 line
Florian