From: Ido Schimmel <idosch@nvidia.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
edumazet@kernel.org, willemb@google.com, horms@kernel.org,
razor@blackwall.org, dsahern@kernel.org, shuah@kernel.org,
bridge@lists.linux.dev, linux-kselftest@vger.kernel.org,
kyuwoncho18@gmail.com, Ido Schimmel <idosch@nvidia.com>,
stable@vger.kernel.org
Subject: [PATCH net 1/2] bridge: mcast: Fix source list rollback on failure
Date: Sun, 22 Nov 2026 09:25:03 +0200 [thread overview]
Message-ID: <20261122072504.2623702-1-idosch@nvidia.com> (raw)
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)
[...]
Fixes: 61f2183512a7 ("bridge: mcast: Support replacement of MDB port group entries")
Cc: stable@vger.kernel.org
Reported-by: Kyuwon Cho <kyuwoncho18@gmail.com>
Closes: https://lore.kernel.org/netdev/179489219555.3099318.10297266282803881244@gmail.com/
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
net/bridge/br_mdb.c | 29 ++++++++++++++---------------
net/bridge/br_private.h | 1 +
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
index 0adcd1524ab2..be65976c2f32 100644
--- a/net/bridge/br_mdb.c
+++ b/net/bridge/br_mdb.c
@@ -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;
}
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 014d0b8db8c7..97ad9d7bab27 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -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;
--
2.56.0
next reply other threads:[~2026-11-22 7:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 7:25 Ido Schimmel [this message]
2026-11-22 7:25 ` [PATCH net 2/2] selftests: bridge_mdb: Test failed source list replace Ido Schimmel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261122072504.2623702-1-idosch@nvidia.com \
--to=idosch@nvidia.com \
--cc=bridge@lists.linux.dev \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kyuwoncho18@gmail.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox