bridge: mcast: Fix source list rollback on failure
Subsystems (6)
Ido Schimmel
maintainerPATCH 1/2 bridge: mcast: Fix source list rollback on failure
When the bridge fails to add or replace an MDB entry with a source list, br_mdb_add_group_srcs() rolls back the operation by looking up and deleting the source entries of all the sources that were already processed. This is wrong for two reasons.
First, with NLM_F_REPLACE, a source can appear more than once in the source list. Its source entry is deleted when rolling back one occurrence and the lookup fails for the other, triggering a WARN_ON_ONCE() [1].
Second, when replacing an existing entry fails, sources from the new source list that already existed before the replace are deleted together with their (S, G) entries instead of being kept.
Fix by marking source entries that were created by the current operation and only deleting them on failure.
[1]
WARNING: net/bridge/br_mdb.c:901 at br_mdb_add_group_srcs+0x310/0x440, CPU#10: repro/304 [...] RIP: 0010:br_mdb_add_group_srcs (net/bridge/br_mdb.c:901 (discriminator 2) net/bridge/br_mdb.c:924 (discriminator 2)) [...] Call Trace: <TASK> br_mdb_add_group_star_g (net/bridge/br_mdb.c:1021) br_mdb_add_group (net/bridge/br_mdb.c:1082) br_mdb_add (net/bridge/br_mdb.c:1097 net/bridge/br_mdb.c:1360) rtnl_mdb_add (net/core/rtnetlink.c:6925) rtnetlink_rcv_msg (net/core/rtnetlink.c:7178) [...]
--- net/bridge/br_mdb.c | 29 ++++++++++++++--------------- net/bridge/br_private.h | 1 + 2 files changed, 15 insertions(+), 15 deletions(-)
net/bridge/br_mdb.c +14 -15
@@ -867,6 +867,7 @@ static int br_mdb_add_group_src(const struct br_mdb_config *cfg,NL_SET_ERR_MSG_MOD (extack,"Failed to add new source entry" );return -ENOSPC ; } + ent->flags |=BR_SGRP_F_NEW ; }else if (!(cfg->nlflags &NLM_F_REPLACE )) {NL_SET_ERR_MSG_MOD (extack,"Source entry already exists" );return -EEXIST ;
@@ -883,31 +884,24 @@ static int br_mdb_add_group_src(const struct br_mdb_config *cfg,if (err) goto err_del_sg; - ent->flags =BR_SGRP_F_INSTALLED |BR_SGRP_F_USER_ADDED ; + ent->flags =BR_SGRP_F_INSTALLED |BR_SGRP_F_USER_ADDED | + (ent->flags &BR_SGRP_F_NEW );return 0 ; err_del_sg: -__br_multicast_del_group_src (ent); +if (ent->flags &BR_SGRP_F_NEW ) +__br_multicast_del_group_src (ent);return err; } -static void br_mdb_del_group_src (struct net_bridge_port_group *pg, -struct br_mdb_src_entry *src) -{ -struct net_bridge_group_src *ent; - - ent =br_multicast_find_group_src (pg, &src->addr); -if (WARN_ON_ONCE (!ent)) -return ; -br_multicast_del_group_src (ent, false); -} -static int br_mdb_add_group_srcs (const struct br_mdb_config *cfg,struct net_bridge_port_group *pg,struct net_bridge_mcast *brmctx,struct netlink_ext_ack *extack) { +struct net_bridge_group_src *ent; +struct hlist_node *tmp;int i, err;for (i =0 ; i < cfg->num_src_entries; i++) {
@@ -917,11 +911,16 @@ static int br_mdb_add_group_srcs(const struct br_mdb_config *cfg, goto err_del_group_srcs; } +hlist_for_each_entry (ent, &pg->src_list, node) + ent->flags &= ~BR_SGRP_F_NEW ; +return 0 ; err_del_group_srcs: -for (i--; i >=0 ; i--) -br_mdb_del_group_src (pg, &cfg->src_entries[i]); +hlist_for_each_entry_safe (ent, tmp, &pg->src_list, node) { +if (ent->flags &BR_SGRP_F_NEW ) +br_multicast_del_group_src (ent, false); + }return err; }
net/bridge/br_private.h +1 -0
@@ -347,6 +347,7 @@ struct net_bridge_fdb_flush_desc {#define BR_SGRP_F_SEND BIT(1)#define BR_SGRP_F_INSTALLED BIT(2)#define BR_SGRP_F_USER_ADDED BIT(3) +#define BR_SGRP_F_NEW BIT(4)struct net_bridge_mcast_gc {struct hlist_node gc_node;
Signature · 1 line
2.56.0
Ido Schimmel
maintainerPATCH 2/2 selftests: bridge_mdb: Test failed source list replace
Add a test case for the issues that were fixed in "bridge: mcast: Fix source list rollback on failure". Check that a failed replace of a (*, G) entry does not change its source list, with one of the existing sources specified twice and a new source.
Output without the fix:
# ./bridge_mdb.sh
[...]
TEST: IPv4 (*, G) port group entries configuration tests [FAIL]
(S, G) entry for source 192.0.2.1 deleted after failed replace
TEST: IPv6 (*, G) port group entries configuration tests [FAIL]
(S, G) entry for source 2001:db8:1::1 deleted after failed replace
[...]Output with the fix:
# ./bridge_mdb.sh [...] TEST: IPv4 (*, G) port group entries configuration tests [ OK ] TEST: IPv6 (*, G) port group entries configuration tests [ OK ] [...]
--- .../selftests/net/forwarding/bridge_mdb.sh | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
tools/testing/selftests/net/forwarding/bridge_mdb.sh +21 -2
@@ -293,6 +293,7 @@ __cfg_test_port_ip_star_g() local grp=$1; shift local invalid_grp=$1; shift local src_prefix=$1; shift + local invalid_src=$1; shift local src1=${src_prefix}1 local src2=${src_prefix}2 local src3=${src_prefix}3
@@ -487,6 +488,23 @@ __cfg_test_port_ip_star_g() bridge mdb del dev br0 port $swp1 grp $grp vid 10 + # Check that a failed replace does not change the source list. + bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \ + filter_mode exclude source_list $src1,$src2 + + bridge mdb replace dev br0 port $swp1 grp $grp temp vid 10 \ + filter_mode exclude source_list $src1,$src1,$src3,$invalid_src \ + &> /dev/null + check_fail $? "Managed to replace source list with an invalid source" + bridge -d mdb get dev br0 grp $grp src $src1 vid 10 &> /dev/null + check_err $? "(S, G) entry for source $src1 deleted after failed replace" + bridge -d mdb get dev br0 grp $grp src $src2 vid 10 &> /dev/null + check_err $? "(S, G) entry for source $src2 deleted after failed replace" + bridge -d mdb get dev br0 grp $grp src $src3 vid 10 &> /dev/null + check_fail $? "(S, G) entry for source $src3 created after failed replace" + + bridge mdb del dev br0 port $swp1 grp $grp vid 10 + # Check that protocol can be modified. bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \ filter_mode exclude source_list $src1 proto zebra
@@ -568,8 +586,9 @@ cfg_test_port_ip_star_g() cfg_test_port_common "IPv4 (*, G)" "grp 239.1.1.1" cfg_test_port_common "IPv6 (*, G)" "grp ff0e::1" - __cfg_test_port_ip_star_g "IPv4" "239.1.1.1" "224.0.0.1" "192.0.2." - __cfg_test_port_ip_star_g "IPv6" "ff0e::1" "ff02::1" "2001:db8:1::" + __cfg_test_port_ip_star_g "IPv4" "239.1.1.1" "224.0.0.1" "192.0.2." \ + "0.0.0.0" + __cfg_test_port_ip_star_g "IPv6" "ff0e::1" "ff02::1" "2001:db8:1::" "::" } __cfg_test_port_ip_sg()
Signature · 1 line
2.56.0
Re: [PATCH net 2/2] selftests: bridge_mdb: Test failed source list replace
Quoted 23 lines · Ido Schimmel
Add a test case for the issues that were fixed in "bridge: mcast: Fix source list rollback on failure". Check that a failed replace of a (*, G) entry does not change its source list, with one of the existing sources specified twice and a new source.
Output without the fix:
# ./bridge_mdb.sh [...] TEST: IPv4 (*, G) port group entries configuration tests [FAIL] (S, G) entry for source 192.0.2.1 deleted after failed replace TEST: IPv6 (*, G) port group entries configuration tests [FAIL] (S, G) entry for source 2001:db8:1::1 deleted after failed replace [...]Output with the fix:
# ./bridge_mdb.sh [...] TEST: IPv4 (*, G) port group entries configuration tests [ OK ] TEST: IPv6 (*, G) port group entries configuration tests [ OK ] [...]
Quoted 5 lines
Signed-off-by Ido Schimmel <[email protected]>--- .../selftests/net/forwarding/bridge_mdb.sh | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
[email protected]
AI reviewRe: [PATCH net 2/2] selftests: bridge_mdb: Test failed source list replace
In reply to Ido SchimmelThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] A failed (*, G) replace still leaves the existing sources partly changed, and the new test cannot see it.
--
selftests: bridge_mdb: Test failed source list replace
This commit adds a test case to __cfg_test_port_ip_star_g() in bridge_mdb.sh for the fix in "bridge: mcast: Fix source list rollback on failure". The replace request lists an existing source twice, then a new source, then an invalid source. The test checks that after the failed replace the existing (S, G) entries are still present and the new one was not created.
Quoted 4 lines
tools/testing/selftests/net/forwarding/bridge_mdb.sh +0
-0
[ ... ]
Quoted 8 lines
tools/testing/selftests/net/forwarding/bridge_mdb.sh +4
-0@@ -487,6 +488,23 @@ __cfg_test_port_ip_star_g() bridge mdb del dev br0 port $swp1 grp $grp vid 10 + # Check that a failed replace does not change the source list. + bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \ + filter_mode exclude source_list $src1,$src2 +
tools/testing/selftests/net/forwarding/bridge_mdb.sh __cfg_test_port_ip_star_g() · line 504
Quoted 10 lines
tools/testing/selftests/net/forwarding/bridge_mdb.sh +10
-0+ bridge mdb replace dev br0 port $swp1 grp $grp temp vid 10 \ + filter_mode exclude source_list $src1,$src1,$src3,$invalid_src \ + &> /dev/null + check_fail $? "Managed to replace source list with an invalid source" + bridge -d mdb get dev br0 grp $grp src $src1 vid 10 &> /dev/null + check_err $? "(S, G) entry for source $src1 deleted after failed replace" + bridge -d mdb get dev br0 grp $grp src $src2 vid 10 &> /dev/null + check_err $? "(S, G) entry for source $src2 deleted after failed replace" + bridge -d mdb get dev br0 grp $grp src $src3 vid 10 &> /dev/null + check_fail $? "(S, G) entry for source $src3 created after failed replace"
[Severity: Medium]
The add and the failed replace both use temp, filter_mode exclude and the default proto. The test then only checks whether the (S, G) entries exist. Would a partly applied replace of an existing source be caught here?
In net/bridge/br_mdb.c the replace path is:
br_mdb_replace_group_star_g()
br_mdb_replace_group_srcs()
br_mdb_add_group_srcs()
br_mdb_add_group_src() <- once per source, in order
For a source that already exists, br_mdb_add_group_src() changes its timer and replaces its (S, G) entry before the later sources are processed:
net/bridge/br_mdb.c:br_mdb_add_group_src() {
...
if (cfg->filter_mode == MCAST_INCLUDE &&
cfg->entry->state == MDB_TEMPORARY)
mod_timer(&ent->timer, now + br_multicast_gmi(brmctx));
else
timer_delete(&ent->timer);
/* Install a (S, G) forwarding entry for the source. */
err = br_mdb_add_group_src_fwd(cfg, &src->addr, brmctx, extack);
...
}br_mdb_add_group_src_fwd()->br_mdb_add_group_sg()->br_mdb_replace_group_sg() then rewrites the existing (S, G) port group and notifies userspace:
net/bridge/br_mdb.c:br_mdb_replace_group_sg() {
...
pg->flags = flags;
pg->rt_protocol = cfg->rt_protocol;
...
br_mdb_notify(cfg->br->dev, mp, pg, RTM_NEWMDB);
...
}A later source can fail. In this test that is 0.0.0.0 or ::, where br_multicast_new_group_src() returns NULL and the call returns -ENOSPC. The rollback then only removes BR_SGRP_F_NEW entries and clears BR_SGRP_F_DELETE:
br_mdb_add_group_srcs():err_del_group_srcs:
hlist_for_each_entry_safe(ent, tmp, &pg->src_list, node) {
if (ent->flags & BR_SGRP_F_NEW)
br_multicast_del_group_src(ent, false);
}
return err;br_mdb_replace_group_srcs():err_clear_delete:
hlist_for_each_entry(ent, &pg->src_list, node) ent->flags &= ~BR_SGRP_F_DELETE; return err;
br_mdb_replace_group_star_g() then returns early. The (*, G) port group keeps its old flags, filter_mode and protocol. Its existing sources and their (S, G) entries keep the new settings.
For example:
bridge mdb add ... temp filter_mode include source_list S1 bridge mdb replace ... permanent filter_mode include source_list S1,0.0.0.0
Does this delete S1's source timer, so the temporary INCLUDE entry never ages out? Does it also leave the (S, G) entry PERMANENT while the (*, G) entry is still temporary? Userspace would also get an RTM_NEWMDB notification for a request that failed.
Before this series, the rollback deleted every source it had processed, so the changed state did not survive. "bridge: mcast: Fix source list rollback on failure" now keeps the existing entries, which leaves the changed state in place.
Should that fix also restore the timer and (S, G) state of the existing sources? Could the replace in this test also use different attributes, for example permanent, filter_mode include or a different proto? It could then check that the existing (S, G) entries keep their original flags, protocol and timer.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122072504.2623702-1-idosch%40nvidia.com
Ido Schimmel
maintainerRe: [PATCH net 2/2] selftests: bridge_mdb: Test failed source list replace
tl;dr - I believe the patch is fine as-is.
Quoted 4 lines · On Mon, Nov 23, 2026 at 07:28:03AM +0000, [email protected] wrote:
[Severity: Medium]
The add and the failed replace both use temp,filter_modeexclude and the default proto. The test then only checks whether the (S, G) entries exist. Would a partly applied replace of an existing source be caught here?
Does the patch claim to fix that? Does the selftest claim to catch this? No.
Quoted 36 lines · Ido Schimmel
When the bridge fails to add or replace an MDB entry with a source list,
br_mdb_add_group_srcs()rolls back the operation by looking up and deleting the source entries of all the sources that were already processed. This is wrong for two reasons.First, with
NLM_F_REPLACE, a source can appear more than once in the source list. Its source entry is deleted when rolling back one occurrence and the lookup fails for the other, triggering aWARN_ON_ONCE()[1].Second, when replacing an existing entry fails, sources from the new source list that already existed before the replace are deleted together with their (S, G) entries instead of being kept.
Fix by marking source entries that were created by the current operation and only deleting them on failure.
[1]
WARNING: net/bridge/br_mdb.c:901 at br_mdb_add_group_srcs+0x310/0x440, CPU#10: repro/304 [...] RIP: 0010:br_mdb_add_group_srcs (net/bridge/br_mdb.c:901 (discriminator 2) net/bridge/br_mdb.c:924 (discriminator 2)) [...] Call Trace: <TASK> br_mdb_add_group_star_g (net/bridge/br_mdb.c:1021) br_mdb_add_group (net/bridge/br_mdb.c:1082) br_mdb_add (net/bridge/br_mdb.c:1097 net/bridge/br_mdb.c:1360) rtnl_mdb_add (net/core/rtnetlink.c:6925) rtnetlink_rcv_msg (net/core/rtnetlink.c:7178) [...]Fixes 61f2183512a7 ("bridge: mcast: Support replacement of MDB port group entries")Reported-by Kyuwon Cho <[email protected]>Signed-off-by Ido Schimmel <[email protected]>
Quoted 5 lines
--- net/bridge/br_mdb.c | 29 ++++++++++++++--------------- net/bridge/br_private.h | 1 + 2 files changed, 15 insertions(+), 15 deletions(-)
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] This patch makes a failed NLM_F_REPLACE keep the (*, G) source entries that existed before the request, but it keeps them in the…
--
bridge: mcast: Fix source list rollback on failure
This commit changes the rollback in br_mdb_add_group_srcs(). On failure, it now deletes only the source entries that the current add or replace operation created, marked with a new BR_SGRP_F_NEW flag. Source entries that existed before an NLM_F_REPLACE request are kept, which also avoids a WARN_ON_ONCE() when a source appears more than once in the list.
Quoted 4 lines
net/bridge/br_mdb.c +0
-0
[ ... ]
Quoted 16 lines
net/bridge/br_mdb.c +4
-2@@ -883,31 +884,24 @@ static int br_mdb_add_group_src(const struct br_mdb_config *cfg,if (err) goto err_del_sg; - ent->flags =BR_SGRP_F_INSTALLED |BR_SGRP_F_USER_ADDED ; + ent->flags =BR_SGRP_F_INSTALLED |BR_SGRP_F_USER_ADDED | + (ent->flags &BR_SGRP_F_NEW );return 0 ; err_del_sg: -__br_multicast_del_group_src (ent); +if (ent->flags &BR_SGRP_F_NEW ) +__br_multicast_del_group_src (ent);return err; }
[ ... ]
Quoted 6 lines
net/bridge/br_mdb.c +2
-0@@ -917,11 +911,16 @@ static int br_mdb_add_group_srcs(const struct br_mdb_config *cfg, goto err_del_group_srcs; } +hlist_for_each_entry (ent, &pg->src_list, node) + ent->flags &= ~BR_SGRP_F_NEW ;
net/bridge/br_mdb.c static int br_mdb_add_group_srcs(const struct br_mdb_config *cfg, · line 923
Quoted 10 lines
net/bridge/br_mdb.c +5
-2+return 0 ; err_del_group_srcs: -for (i--; i >=0 ; i--) -br_mdb_del_group_src (pg, &cfg->src_entries[i]); +hlist_for_each_entry_safe (ent, tmp, &pg->src_list, node) { +if (ent->flags &BR_SGRP_F_NEW ) +br_multicast_del_group_src (ent, false); + }
[Severity: High]
With NLM_F_REPLACE, the pre-existing sources that are now kept on failure were already changed by br_mdb_add_group_src() earlier in the loop. Is that state ever restored?
For each pre-existing source in the new list, br_mdb_add_group_src() first changes the source timer:
if (cfg->filter_mode == MCAST_INCLUDE && cfg->entry->state == MDB_TEMPORARY) mod_timer(&ent->timer, now + br_multicast_gmi(brmctx)); else timer_delete(&ent->timer);
Then this call chain rewrites the existing (S, G) port group and notifies user space:
br_mdb_add_group_src_fwd()
br_mdb_add_group_sg()
br_mdb_replace_group_sg() pg->flags = flags; pg->rt_protocol = cfg->rt_protocol; ... br_mdb_notify(cfg->br->dev, mp, pg, RTM_NEWMDB);
Finally, the ent->flags assignment above overwrites the source flags and drops bits such as BR_SGRP_F_SEND.
If a later source fails, this loop deletes only the BR_SGRP_F_NEW entries. br_mdb_replace_group_star_g() then returns before it updates the parent:
err = br_mdb_replace_group_srcs(cfg, pg, brmctx, extack); if (err) return err; pg->flags = flags; pg->filter_mode = cfg->filter_mode; ...
So the (*, G) keeps its old configuration, but the kept sources and their (S, G) entries carry the new one. User space has also already received RTM_NEWMDB for the (S, G) changes.
This failure is easy to trigger. A source of 0.0.0.0 or :: passes is_valid_mdb_source(), but br_multicast_new_group_src() rejects it, so the request fails with -ENOSPC. The selftest in the next patch ("selftests:bridge_mdb: Test failed source list replace") uses this trigger. It only checks that the (S, G) entries still exist, not their flags or timers.
Some states this can leave behind:
(a) A permanent INCLUDE (*, G) {S1} is replaced with a temporary INCLUDE source list S1,0.0.0.0. S1's timer is now armed on a permanent pg, and (S1, G) has lost MDB_PG_FLAGS_PERMANENT. After GMI, br_multicast_group_src_expired() sees INCLUDE mode and does this:
if (pg->filter_mode == MCAST_INCLUDE) {
br_multicast_del_group_src(src, false);
if (!hlist_empty(&pg->src_list))
goto out;
br_multicast_find_del_pg(br, pg);That deletes S1 and its (S1, G) entry, and then the permanent (*, G) entry.
(b) A temporary INCLUDE (*, G) {S1} is replaced with a permanent S1,0.0.0.0. S1's timer is deleted, and the pg timer is only armed in EXCLUDE mode, so the temporary entry never ages out.
(c) An EXCLUDE (*, G) {S1} is replaced with INCLUDE S1,0.0.0.0. (S1, G) loses MDB_PG_FLAGS_BLOCKED while (*, G) is still EXCLUDE with S1 listed. Traffic from S1 is then forwarded to a port that should exclude it.
The commit message says this patch fixes the case where:
sources from the new source list that already existed before the replace are deleted together with their (S, G) entries instead of being kept.
In case (a), aren't those sources and their (S, G) entries still deleted, only one GMI later, together with the permanent (*, G) entry?
Could the replace path validate or allocate everything before it touches existing entries? Alternatively, it could save the per-source and (S, G) state and restore it on failure.
Quoted 2 lines
net/bridge/br_mdb.c +0
-0return err; }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122072504.2623702-1-idosch%40nvidia.com
Ido Schimmel
maintainertl;dr - I believe the patch is fine as-is.
Quoted 4 lines · On Mon, Nov 23, 2026 at 07:28:02AM +0000, [email protected] wrote:
[Severity: High]
WithNLM_F_REPLACE, the pre-existing sources that are now kept on failure were already changed bybr_mdb_add_group_src()earlier in the loop. Is that state ever restored?
No, but before that they were deleted (and a warning was emitted when a source was specified twice), which is worse. Making the replace fully atomic is a much bigger change that is not suitable for net and it's not worth the complexity given the failure is very unlikely in practice.