Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: bridge: mdb: restart port group walk after deletion
@ 2026-09-20 11:08 Fourie Zhang
  2026-09-21 14:14 ` Nikolay Aleksandrov
  2026-09-24  0:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Fourie Zhang @ 2026-09-20 11:08 UTC (permalink / raw)
  To: netdev
  Cc: TencentOS Corvus AI, stable, Nikolay Aleksandrov, Ido Schimmel,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Petr Machata, bridge

br_mdb_flush_pgs() keeps a pointer-to-pointer cursor while walking
mp->ports. br_multicast_del_pg() can re-enter the same MDB entry through
br_multicast_sg_del_exclude_ports() and unlink other port groups. If the
cursor points into one of those groups, the next iteration dereferences a
stale cursor and can leave mp->ports pointing at freed memory.

A following RTM_GETMDB exposes the dangling pointer:

  BUG: KASAN: slab-use-after-free in br_mdb_dump
  Read of size 8
    br_mdb_dump
    rtnl_mdb_dump
    rtnl_dumpit
    netlink_dump

Reset the cursor to mp->ports after every deletion. The deletion removes at
least the selected group, so the restarted walk always makes progress.

Fixes: a6acb535afb2 ("bridge: mdb: Add MDB bulk deletion support")
Cc: stable@vger.kernel.org
Assisted-by: tencentos-corvus-ai:hy4-preview
Signed-off-by: Fourie Zhang <fouriezhang@tencent.com>
---
A reproducer for this issue is available if requested.

 net/bridge/br_mdb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
index e0c7020b1..a01bd280c 100644
--- a/net/bridge/br_mdb.c
+++ b/net/bridge/br_mdb.c
@@ -1523,6 +1523,8 @@ static void br_mdb_flush_pgs(struct net_bridge *br,
 		}
 
 		br_multicast_del_pg(mp, p, pp);
+		/* br_multicast_del_pg() can remove other groups from this list. */
+		pp = &mp->ports;
 	}
 }
 
-- 
2.43.7

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

* Re: [PATCH net] net: bridge: mdb: restart port group walk after deletion
  2026-09-20 11:08 [PATCH net] net: bridge: mdb: restart port group walk after deletion Fourie Zhang
@ 2026-09-21 14:14 ` Nikolay Aleksandrov
  2026-09-24  0:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Aleksandrov @ 2026-09-21 14:14 UTC (permalink / raw)
  To: Fourie Zhang, netdev
  Cc: TencentOS Corvus AI, stable, Ido Schimmel, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Petr Machata, bridge

On 20/09/2026 14:08, Fourie Zhang wrote:
> br_mdb_flush_pgs() keeps a pointer-to-pointer cursor while walking
> mp->ports. br_multicast_del_pg() can re-enter the same MDB entry through
> br_multicast_sg_del_exclude_ports() and unlink other port groups. If the
> cursor points into one of those groups, the next iteration dereferences a
> stale cursor and can leave mp->ports pointing at freed memory.
> 
> A following RTM_GETMDB exposes the dangling pointer:
> 
>    BUG: KASAN: slab-use-after-free in br_mdb_dump
>    Read of size 8
>      br_mdb_dump
>      rtnl_mdb_dump
>      rtnl_dumpit
>      netlink_dump
> 
> Reset the cursor to mp->ports after every deletion. The deletion removes at
> least the selected group, so the restarted walk always makes progress.
> 
> Fixes: a6acb535afb2 ("bridge: mdb: Add MDB bulk deletion support")
> Cc: stable@vger.kernel.org
> Assisted-by: tencentos-corvus-ai:hy4-preview
> Signed-off-by: Fourie Zhang <fouriezhang@tencent.com>
> ---
> A reproducer for this issue is available if requested.
> 
>   net/bridge/br_mdb.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
> index e0c7020b1..a01bd280c 100644
> --- a/net/bridge/br_mdb.c
> +++ b/net/bridge/br_mdb.c
> @@ -1523,6 +1523,8 @@ static void br_mdb_flush_pgs(struct net_bridge *br,
>   		}
>   
>   		br_multicast_del_pg(mp, p, pp);
> +		/* br_multicast_del_pg() can remove other groups from this list. */
> +		pp = &mp->ports;
>   	}
>   }
>   

Yeah, this seems like the simplest fix for stable. I will post my conversion to
standard list primitives and will remove these issues altogether with it in
net-next.

Acked-by: Nikolay Aleksandrov <razor@blackwall.org>


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

* Re: [PATCH net] net: bridge: mdb: restart port group walk after deletion
  2026-09-20 11:08 [PATCH net] net: bridge: mdb: restart port group walk after deletion Fourie Zhang
  2026-09-21 14:14 ` Nikolay Aleksandrov
@ 2026-09-24  0:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-24  0:00 UTC (permalink / raw)
  To: Fourie Zhang
  Cc: netdev, corvus, stable, razor, idosch, davem, edumazet, kuba,
	pabeni, horms, petrm, bridge

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sun, 20 Sep 2026 19:08:43 +0800 you wrote:
> br_mdb_flush_pgs() keeps a pointer-to-pointer cursor while walking
> mp->ports. br_multicast_del_pg() can re-enter the same MDB entry through
> br_multicast_sg_del_exclude_ports() and unlink other port groups. If the
> cursor points into one of those groups, the next iteration dereferences a
> stale cursor and can leave mp->ports pointing at freed memory.
> 
> A following RTM_GETMDB exposes the dangling pointer:
> 
> [...]

Here is the summary with links:
  - [net] net: bridge: mdb: restart port group walk after deletion
    https://git.kernel.org/netdev/net/c/ab1404ac8115

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-09-24  0:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-20 11:08 [PATCH net] net: bridge: mdb: restart port group walk after deletion Fourie Zhang
2026-09-21 14:14 ` Nikolay Aleksandrov
2026-09-24  0:00 ` patchwork-bot+netdevbpf

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