net: bridge: fix two MST bugs
Subsystems (3)
Nikolay Aleksandrov
maintainerv2 cover net: bridge: fix two MST bugs
Hi,
Patch 01 fixes a race condition that exists between expired fdb deletion and port deletion when MST is enabled. Learning can happen after the port's state has been changed to disabled which could lead to that port's memory being used after it's been freed. The issue was reported by syzbot, more information in patch 01. Patch 02 fixes an issue with MST's static key which Ido spotted, we can have multiple bridges with MST and a single bridge can erroneously disable it for all.
v2: dropped the selftest as it is useless with the new fix
patch 01 - new fix approach relying on port's vlan group patch 02 - new patch fixing an issue with MST's static key
Thanks,
Nik
Nikolay Aleksandrov (2):
net: bridge: fix use-after-free due to MST port state bypass
net: bridge: fix MST static key usage
net/bridge/br_forward.c | 2 +- net/bridge/br_if.c | 1 + net/bridge/br_input.c | 4 ++-- net/bridge/br_mst.c | 10 ++++++++-- net/bridge/br_private.h | 13 ++++++++++--- 5 files changed, 22 insertions(+), 8 deletions(-)
Signature · 1 line
2.51.0
Nikolay Aleksandrov
maintainerPATCH v2 1/2 net: bridge: fix use-after-free due to MST port state bypass
syzbot reported[1] a use-after-free when deleting an expired fdb. It is due to a race condition between learning still happening and a port being deleted, after all its fdbs have been flushed. The port's state has been toggled to disabled so no learning should happen at that time, but if we have MST enabled, it will bypass the port's state, that together with VLAN filtering disabled can lead to fdb learning at a time when it shouldn't happen while the port is being deleted. VLAN filtering must be disabled because we flush the port VLANs when it's being deleted which will stop learning. This fix adds a check for the port's vlan group which is initialized to NULL when the port is getting deleted, that avoids the port state bypass. When MST is enabled there would be a minimal new overhead in the fast-path because the port's vlan group pointer is cache-hot.
[1] https://syzkaller.appspot.com/bug?extid=dd280197f0f7ab3917be
---
v2: new fix approach using port's vlan group check when MST is enabled
we rely on the fact that the vlan group gets initialized to NULL when the port is getting deleted
net/bridge/br_forward.c | 2 +- net/bridge/br_input.c | 4 ++-- net/bridge/br_private.h | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-)
net/bridge/br_forward.c +1 -1
@@ -25,7 +25,7 @@ static inline int should_deliver(const struct net_bridge_port *p, vg =nbp_vlan_group_rcu (p);return ((p->flags &BR_HAIRPIN_MODE ) || skb->dev != p->dev) && - (br_mst_is_enabled (p->br) || p->state ==BR_STATE_FORWARDING ) && + (br_mst_is_enabled (p) || p->state ==BR_STATE_FORWARDING ) &&br_allowed_egress (vg, skb) &&nbp_switchdev_allowed_egress (p, skb) && !br_skb_isolated (p, skb); }
net/bridge/br_input.c +2 -2
@@ -94,7 +94,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb br = p->br; -if (br_mst_is_enabled (br)) { +if (br_mst_is_enabled (p)) { state =BR_STATE_FORWARDING ; }else {if (p->state ==BR_STATE_DISABLED ) {
@@ -429,7 +429,7 @@ static rx_handler_result_t br_handle_frame(struct sk_buff **pskb)return RX_HANDLER_PASS ; forward: -if (br_mst_is_enabled (p->br)) +if (br_mst_is_enabled (p)) goto defer_stp_filtering;switch (p->state) {
net/bridge/br_private.h +5 -3
@@ -1935,10 +1935,12 @@ static inline bool br_vlan_state_allowed(u8 state, bool learn_allow)/* br_mst.c */ #ifdef CONFIG_BRIDGE_VLAN_FILTERING DECLARE_STATIC_KEY_FALSE (br_mst_used); -static inline bool br_mst_is_enabled (struct net_bridge *br) +static inline bool br_mst_is_enabled (const struct net_bridge_port *p) { +/* check the port's vlan group to avoid racing with port deletion */ return static_branch_unlikely (&br_mst_used) && -br_opt_get (br,BROPT_MST_ENABLED ); +br_opt_get (p->br,BROPT_MST_ENABLED ) && +rcu_access_pointer (p->vlgrp); } int br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state,
@@ -1953,7 +1955,7 @@ int br_mst_fill_info(struct sk_buff *skb,int br_mst_process (struct net_bridge_port *p,const struct nlattr *mst_attr,struct netlink_ext_ack *extack);#else -static inline bool br_mst_is_enabled (struct net_bridge *br) +static inline bool br_mst_is_enabled (const struct net_bridge_port *p) {return false; }
Signature · 1 line
2.51.0
Re: [PATCH net v2 1/2] net: bridge: fix use-after-free due to MST port state bypass
Quoted 13 lines · Nikolay Aleksandrov
syzbot reported[1] a use-after-free when deleting an expired fdb. It is due to a race condition between learning still happening and a port being deleted, after all its fdbs have been flushed. The port's state has been toggled to disabled so no learning should happen at that time, but if we have MST enabled, it will bypass the port's state, that together with VLAN filtering disabled can lead to fdb learning at a time when it shouldn't happen while the port is being deleted. VLAN filtering must be disabled because we flush the port VLANs when it's being deleted which will stop learning. This fix adds a check for the port's vlan group which is initialized to NULL when the port is getting deleted, that avoids the port state bypass. When MST is enabled there would be a minimal new overhead in the fast-path because the port's vlan group pointer is cache-hot.
Quoted 6 lines
[1] https://syzkaller.appspot.com/bug?extid=dd280197f0f7ab3917be
Fixes ec7328b59176 ("net: bridge: mst: Multiple Spanning Tree (MST) mode")Reported-by [email protected]Signed-off-by Nikolay Aleksandrov <[email protected]>
Nikolay Aleksandrov
maintainerPATCH v2 2/2 net: bridge: fix MST static key usage
In reply to Nikolay AleksandrovAs 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.
---
v2: new fix
net/bridge/br_if.c | 1 + net/bridge/br_mst.c | 10 ++++++++-- net/bridge/br_private.h | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-)
net/bridge/br_if.c +1 -0
@@ -386,6 +386,7 @@ void br_dev_delete(struct net_device *dev, struct list_head *head)del_nbp (p); } +br_mst_uninit (br);br_recalculate_neigh_suppress_enabled (br);br_fdb_delete_by_port (br,NULL ,0 ,1 );
net/bridge/br_mst.c +8 -2
@@ -22,6 +22,12 @@ bool br_mst_enabled(const struct net_device *dev) }EXPORT_SYMBOL_GPL (br_mst_enabled); +void br_mst_uninit (struct net_bridge *br) +{ +if (br_opt_get (br,BROPT_MST_ENABLED )) +static_branch_dec (&br_mst_used); +} +int br_mst_get_info (const struct net_device *dev,u16 msti,unsigned long *vids) {const struct net_bridge_vlan_group *vg;
@@ -225,9 +231,9 @@ int br_mst_set_enabled(struct net_bridge *br, bool on,return err;if (on) -static_branch_enable (&br_mst_used); +static_branch_inc (&br_mst_used);else -static_branch_disable (&br_mst_used); +static_branch_dec (&br_mst_used);br_opt_toggle (br,BROPT_MST_ENABLED , on);return 0 ;
net/bridge/br_private.h +5 -0
@@ -1954,6 +1954,7 @@ int br_mst_fill_info(struct sk_buff *skb, const struct net_bridge_vlan_group *vg);int br_mst_process (struct net_bridge_port *p,const struct nlattr *mst_attr,struct netlink_ext_ack *extack); +void br_mst_uninit (struct net_bridge *br);#else static inline bool br_mst_is_enabled (const struct net_bridge_port *p) {
@@ -1989,6 +1990,10 @@ static inline int br_mst_process(struct net_bridge_port *p, {return -EOPNOTSUPP ; } + +static inline void br_mst_uninit (struct net_bridge *br) +{ +}#endif struct nf_br_ops {
Signature · 1 line
2.51.0
Re: [PATCH net v2 2/2] net: bridge: fix MST static key usage
Quoted 10 lines · Nikolay Aleksandrov
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 ec7328b59176 ("net: bridge: mst: Multiple Spanning Tree (MST) mode")Reported-by Ido Schimmel <[email protected]>Closes https://lore.kernel.org/netdev/[email protected]/T/#m6888d87658f94ed1725433940f4f4ebb00b5a68b open hereSigned-off-by Nikolay Aleksandrov <[email protected]>
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 5 Nov 2025 13:19:17 +0200 you wrote:
Hi,
Patch 01 fixes a race condition that exists between expired fdb deletion and port deletion when MST is enabled. Learning can happen after the port's state has been changed to disabled which could lead to that port's memory being used after it's been freed. The issue was reported by syzbot, more information in patch 01. Patch 02 fixes an issue with MST's static key which Ido spotted, we can have multiple bridges with MST and a single bridge can erroneously disable it for all.[...]
Here is the summary with links:
- [net,v2,1/2] net: bridge: fix use-after-free due to MST port state bypass
https://git.kernel.org/netdev/net/c/8dca36978aa8 - [net,v2,2/2] net: bridge: fix MST static key usage https://git.kernel.org/netdev/net/c/ee87c63f9b2a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html