dsa_switch_tag_8021q_vlan_add() walks the ports of a switch, adds the VLAN to the target user port and to every CPU and DSA port, and returns on the first error without undoing the ports already done. The caller treats the notification as failed and does not delete the VLAN, so a user port can keep a tag_8021q VLAN without its CPU and DSA port entries, and an earlier CPU or DSA port keeps an entry and a reference nobody drops. This happens when the second step fails after the first succeeded: a user port numbered below the CPU port, or a second CPU or DSA port. dsa_tag_8021q_register(), dsa_tag_8021q_bridge_join() and dsa_tag_8021q_bridge_leave() all add VLANs this way. On felix the standalone VLAN of a user port is a set of VCAP rules, which stay installed after felix falls back to its NPI tagger. Walk back over the ports already done and delete the VLAN from them, so that the notification either adds the VLAN to all matching ports of the switch or to none. Fixes: c64b9c05045a ("net: dsa: tag_8021q: add proper cross-chip notifier support") Signed-off-by: Julius Bairaktaris --- v2: new. Sashiko's review and Willem de Bruijn's review of v1 found that the partial add of the failing port is not undone. Reproduced in QEMU (x86_64, KASAN) with dsa_loop given the tag_8021q ops and a CPU-port tag_8021q_vlan_add() that fails once (test-only): without this patch, a failed tag_8021q register leaves VLAN 3073 on user port 1 and a failed bridge join leaves VLAN 3088 on user port 0, both added and never deleted; with the series every VLAN the driver added is deleted again (one run each). net/dsa/tag_8021q.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index f91646e6024..78c9fe735e8 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -239,11 +239,18 @@ int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds, err = dsa_port_do_tag_8021q_vlan_add(dp, info->vid, flags); if (err) - return err; + goto rollback; } } return 0; + +rollback: + dsa_switch_for_each_port_continue_reverse(dp, ds) + if (dsa_port_tag_8021q_vlan_match(dp, info)) + dsa_port_do_tag_8021q_vlan_del(dp, info->vid); + + return err; } int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds, -- 2.53.0