public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2] net: mscc: ocelot: Fix crash when adding interface under a lag
@ 2025-12-20 19:01 Jerry Wu
  2025-12-20 19:56 ` Vladimir Oltean
  2025-12-20 20:00 ` Christophe JAILLET
  0 siblings, 2 replies; 10+ messages in thread
From: Jerry Wu @ 2025-12-20 19:01 UTC (permalink / raw)
  To: vladimir.oltean
  Cc: claudiu.manoil, alexandre.belloni, UNGLinuxDriver, andrew+netdev,
	davem, edumazet, kuba, pabeni, netdev, linux-kernel, Jerry Wu

Commit 15faa1f67ab4 ("lan966x: Fix crash when adding interface under a lag")
fixed a similar issue in the lan966x driver caused by a NULL pointer dereference.
The ocelot_set_aggr_pgids() function in the ocelot driver has similar logic
and is susceptible to the same crash.

This issue specifically affects the ocelot_vsc7514.c frontend, which leaves
unused ports as NULL pointers. The felix_vsc9959.c frontend is unaffected as
it uses the DSA framework which registers all ports.

Fix this by checking if the port pointer is valid before accessing it.

Fixes: 528d3f190c98 ("net: mscc: ocelot: drop the use of the "lags" array")
Signed-off-by: Jerry Wu <w.7erry@foxmail.com>
---
 drivers/net/ethernet/mscc/ocelot.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c
index 08bee56aea35..6f917fd7af4d 100644
--- a/drivers/net/ethernet/mscc/ocelot.c
+++ b/drivers/net/ethernet/mscc/ocelot.c
@@ -2307,14 +2307,16 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
 
 	/* Now, set PGIDs for each active LAG */
 	for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
-		struct net_device *bond = ocelot->ports[lag]->bond;
+		struct ocelot_port *ocelot_port = ocelot->ports[lag];
 		int num_active_ports = 0;
+		struct net_device *bond;
 		unsigned long bond_mask;
 		u8 aggr_idx[16];
 
-		if (!bond || (visited & BIT(lag)))
+		if (!ocelot_port || !ocelot_port->bond || (visited & BIT(lag)))
 			continue;
 
+		bond = ocelot_port->bond;
 		bond_mask = ocelot_get_bond_mask(ocelot, bond);
 
 		for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread
* [PATCH net v2] net: mscc: ocelot: Fix crash when adding interface under a lag
@ 2025-12-20 18:56 Jerry Wu
  2025-12-20 19:58 ` Christophe JAILLET
  0 siblings, 1 reply; 10+ messages in thread
From: Jerry Wu @ 2025-12-20 18:56 UTC (permalink / raw)
  To: vladimir.oltean
  Cc: claudiu.manoil, alexandre.belloni, UNGLinuxDriver, andrew+netdev,
	davem, edumazet, kuba, pabeni, netdev, linux-kernel, Jerry Wu

Commit 15faa1f67ab4 ("lan966x: Fix crash when adding interface under a lag")
fixed a similar issue in the lan966x driver caused by a NULL pointer dereference.
The ocelot_set_aggr_pgids() function in the ocelot driver has similar logic
and is susceptible to the same crash.

This issue specifically affects the ocelot_vsc7514.c frontend, which leaves
unused ports as NULL pointers. The felix_vsc9959.c frontend is unaffected as
it uses the DSA framework which registers all ports.

Fix this by checking if the port pointer is valid before accessing it.

Fixes: 528d3f190c98 ("net: mscc: ocelot: drop the use of the "lags" array")
Signed-off-by: Jerry Wu <w.7erry@foxmail.com>
---
 drivers/net/ethernet/mscc/ocelot.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c
index 08bee56aea35..6f917fd7af4d 100644
--- a/drivers/net/ethernet/mscc/ocelot.c
+++ b/drivers/net/ethernet/mscc/ocelot.c
@@ -2307,14 +2307,16 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
 
 	/* Now, set PGIDs for each active LAG */
 	for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
-		struct net_device *bond = ocelot->ports[lag]->bond;
+		struct ocelot_port *ocelot_port = ocelot->ports[lag];
 		int num_active_ports = 0;
+		struct net_device *bond;
 		unsigned long bond_mask;
 		u8 aggr_idx[16];
 
-		if (!bond || (visited & BIT(lag)))
+		if (!port || !port->bond || (visited & BIT(lag)))
 			continue;
 
+		bond = port->bond;
 		bond_mask = ocelot_get_bond_mask(ocelot, bond);
 
 		for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-01-04 18:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-20 19:01 [PATCH net v2] net: mscc: ocelot: Fix crash when adding interface under a lag Jerry Wu
2025-12-20 19:56 ` Vladimir Oltean
2025-12-20 20:00 ` Christophe JAILLET
2025-12-20 20:36   ` Jerry Wu
2025-12-20 21:08     ` Vladimir Oltean
2025-12-25 20:36       ` [PATCH net v3] " Jerry Wu
2025-12-28 19:40         ` Vladimir Oltean
2026-01-04 18:22         ` patchwork-bot+netdevbpf
  -- strict thread matches above, loose matches on Subject: below --
2025-12-20 18:56 [PATCH net v2] " Jerry Wu
2025-12-20 19:58 ` Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox