Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: idosch@nvidia.com
Cc: netdev@vger.kernel.org, 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
Subject: Re: [PATCH net 1/2] bridge: mcast: Fix source list rollback on failure
Date: Mon, 23 Nov 2026 07:28:02 +0000	[thread overview]
Message-ID: <179541888207.3135.7176816464038643772@kernel.org> (raw)
In-Reply-To: <20261122072504.2623702-1-idosch@nvidia.com>

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.

Closes: https://lore.kernel.org/netdev/179489219555.3099318.10297266282803881244@gmail.com/

> diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
> index 0adcd1524ab24..be65976c2f32f 100644
> --- a/net/bridge/br_mdb.c
> +++ b/net/bridge/br_mdb.c

[ ... ]

> @@ -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;
>  }

[ ... ]

> @@ -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);
> +	}

[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.

>  	return err;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122072504.2623702-1-idosch%40nvidia.com

      parent reply	other threads:[~2026-11-23  7:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22  7:25 [PATCH net 1/2] bridge: mcast: Fix source list rollback on failure Ido Schimmel
2026-11-22  7:25 ` [PATCH net 2/2] selftests: bridge_mdb: Test failed source list replace Ido Schimmel
2026-11-22 10:23   ` Nikolay Aleksandrov
2026-11-23  7:28   ` netdev-bot+sashiko
2026-11-22 10:23 ` [PATCH net 1/2] bridge: mcast: Fix source list rollback on failure Nikolay Aleksandrov
2026-11-23  7:28 ` netdev-bot+sashiko [this message]

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=179541888207.3135.7176816464038643772@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=bridge@lists.linux.dev \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --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=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