Skip to content

Commit ee87c63

Browse files
NikAleksandrovkuba-moo
authored andcommitted
net: bridge: fix MST static key usage
As Ido pointed out, the static key usage in MST is buggy and should use inc/dec instead of enable/disable because we can have multiple bridges with MST enabled which means a single bridge can disable MST for all. Use static_branch_inc/dec to avoid that. When destroying a bridge decrement the key if MST was enabled. Fixes: ec7328b ("net: bridge: mst: Multiple Spanning Tree (MST) mode") Reported-by: Ido Schimmel <idosch@nvidia.com> Closes: https://lore.kernel.org/netdev/20251104120313.1306566-1-razor@blackwall.org/T/#m6888d87658f94ed1725433940f4f4ebb00b5a68b Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20251105111919.1499702-3-razor@blackwall.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 8dca369 commit ee87c63

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

net/bridge/br_if.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ void br_dev_delete(struct net_device *dev, struct list_head *head)
386386
del_nbp(p);
387387
}
388388

389+
br_mst_uninit(br);
389390
br_recalculate_neigh_suppress_enabled(br);
390391

391392
br_fdb_delete_by_port(br, NULL, 0, 1);

net/bridge/br_mst.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ bool br_mst_enabled(const struct net_device *dev)
2222
}
2323
EXPORT_SYMBOL_GPL(br_mst_enabled);
2424

25+
void br_mst_uninit(struct net_bridge *br)
26+
{
27+
if (br_opt_get(br, BROPT_MST_ENABLED))
28+
static_branch_dec(&br_mst_used);
29+
}
30+
2531
int br_mst_get_info(const struct net_device *dev, u16 msti, unsigned long *vids)
2632
{
2733
const struct net_bridge_vlan_group *vg;
@@ -225,9 +231,9 @@ int br_mst_set_enabled(struct net_bridge *br, bool on,
225231
return err;
226232

227233
if (on)
228-
static_branch_enable(&br_mst_used);
234+
static_branch_inc(&br_mst_used);
229235
else
230-
static_branch_disable(&br_mst_used);
236+
static_branch_dec(&br_mst_used);
231237

232238
br_opt_toggle(br, BROPT_MST_ENABLED, on);
233239
return 0;

net/bridge/br_private.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,7 @@ int br_mst_fill_info(struct sk_buff *skb,
19541954
const struct net_bridge_vlan_group *vg);
19551955
int br_mst_process(struct net_bridge_port *p, const struct nlattr *mst_attr,
19561956
struct netlink_ext_ack *extack);
1957+
void br_mst_uninit(struct net_bridge *br);
19571958
#else
19581959
static inline bool br_mst_is_enabled(const struct net_bridge_port *p)
19591960
{
@@ -1989,6 +1990,10 @@ static inline int br_mst_process(struct net_bridge_port *p,
19891990
{
19901991
return -EOPNOTSUPP;
19911992
}
1993+
1994+
static inline void br_mst_uninit(struct net_bridge *br)
1995+
{
1996+
}
19921997
#endif
19931998

19941999
struct nf_br_ops {

0 commit comments

Comments
 (0)