linux/drivers/net/dsa/mv88e6xxx
Vladimir Oltean ea08dfc35f net: dsa: mv88e6xxx: fix -ENOENT when deleting VLANs and MST is unsupported
Russell King reports that on the ZII dev rev B, deleting a bridge VLAN
from a user port fails with -ENOENT:
https://lore.kernel.org/netdev/Z_lQXNP0s5-IiJzd@shell.armlinux.org.uk/

This comes from mv88e6xxx_port_vlan_leave() -> mv88e6xxx_mst_put(),
which tries to find an MST entry in &chip->msts associated with the SID,
but fails and returns -ENOENT as such.

But we know that this chip does not support MST at all, so that is not
surprising. The question is why does the guard in mv88e6xxx_mst_put()
not exit early:

	if (!sid)
		return 0;

And the answer seems to be simple: the sid comes from vlan.sid which
supposedly was previously populated by mv88e6xxx_vtu_get().
But some chip->info->ops->vtu_getnext() implementations do not populate
vlan.sid, for example see mv88e6185_g1_vtu_getnext(). In that case,
later in mv88e6xxx_port_vlan_leave() we are using a garbage sid which is
just residual stack memory.

Testing for sid == 0 covers all cases of a non-bridge VLAN or a bridge
VLAN mapped to the default MSTI. For some chips, SID 0 is valid and
installed by mv88e6xxx_stu_setup(). A chip which does not support the
STU would implicitly only support mapping all VLANs to the default MSTI,
so although SID 0 is not valid, it would be sufficient, if we were to
zero-initialize the vlan structure, to fix the bug, due to the
coincidence that a test for vlan.sid == 0 already exists and leads to
the same (correct) behavior.

Another option which would be sufficient would be to add a test for
mv88e6xxx_has_stu() inside mv88e6xxx_mst_put(), symmetric to the one
which already exists in mv88e6xxx_mst_get(). But that placement means
the caller will have to dereference vlan.sid, which means it will access
uninitialized memory, which is not nice even if it ignores it later.

So we end up making both modifications, in order to not rely just on the
sid == 0 coincidence, but also to avoid having uninitialized structure
fields which might get temporarily accessed.

Fixes: acaf4d2e36 ("net: dsa: mv88e6xxx: MST Offloading")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20250414212913.2955253-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-04-16 18:14:43 -07:00
..
Kconfig net: dsa: mv88e6xxx: Support LED control 2024-10-04 15:31:28 -07:00
Makefile net: dsa: mv88e6xxx: Support LED control 2024-10-04 15:31:28 -07:00
chip.c net: dsa: mv88e6xxx: fix -ENOENT when deleting VLANs and MST is unsupported 2025-04-16 18:14:43 -07:00
chip.h dsa: mv88e6xxx: Move available stats into info structure 2024-12-10 18:23:12 -08:00
devlink.c net: dsa: mv88e6xxx: avoid unregistering devlink regions which were never registered 2025-04-16 18:14:43 -07:00
devlink.h
global1.c net: dsa: mv88e6xxx: Avoid EEPROM timeout without EEPROM on 88E6250-family switches 2024-04-25 11:24:07 +01:00
global1.h net: dsa: mv88e6xxx: Avoid EEPROM timeout without EEPROM on 88E6250-family switches 2024-04-25 11:24:07 +01:00
global1_atu.c net: dsa: mv88e6xxx: Fix out-of-bound access 2024-08-20 16:53:21 -07:00
global1_vtu.c net: dsa: mv88e6xxx: Add FID map cache 2024-10-08 15:30:55 -07:00
global2.c net: dsa: mv88e6xxx: Avoid EEPROM timeout when EEPROM is absent 2023-10-02 07:26:48 +01:00
global2.h net: dsa: mv88e6xxx: add Amethyst specific SMI GPIO function 2024-02-29 10:16:39 +01:00
global2_avb.c
global2_scratch.c net: dsa: mv88e6xxx: Remove stale comment 2024-08-28 17:54:58 -07:00
hwtstamp.c net: Add struct kernel_ethtool_ts_info 2024-07-15 08:02:26 -07:00
hwtstamp.h net: Add struct kernel_ethtool_ts_info 2024-07-15 08:02:26 -07:00
leds.c net: dsa: mv88e6xxx: Support LED control 2024-10-04 15:31:28 -07:00
pcs-639x.c net: remove phylink_pcs .neg_mode boolean 2025-02-14 17:09:50 -08:00
pcs-6185.c net: remove phylink_pcs .neg_mode boolean 2025-02-14 17:09:50 -08:00
pcs-6352.c net: remove phylink_pcs .neg_mode boolean 2025-02-14 17:09:50 -08:00
phy.c treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
phy.h
port.c dsa: Use str_enable_disable-like helpers 2025-01-20 09:23:25 +00:00
port.h net: dsa: mv88e6xxx: Support LED control 2024-10-04 15:31:28 -07:00
port_hidden.c
ptp.c net: dsa: mv88e6xxx: support 4000ps cycle counter period 2024-10-24 12:57:46 +02:00
ptp.h
serdes.c net: dsa: use ethtool string helpers 2024-11-03 10:36:34 -08:00
serdes.h net: dsa: use ethtool string helpers 2024-11-03 10:36:34 -08:00
smi.c
smi.h
switchdev.c
switchdev.h
trace.c
trace.h tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00