๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9465

Re: [PATCH net v3] net: bridge: disable MRP ports before the FDB flush in del_nbp()

#9465
From: netdev-bot+sashiko
Date: Mon, 02 Nov 2026 04:50
181 lines
14239 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 2 ยท 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] The fix leaves the use-after-free reachable when
  CONFIG_BRIDGE_VLAN_FILTERING=n.
- [High] The reorder only clears BR_MRP_AWARE_BIT when br_mrp_find_port()
  can still find the port in an MRP instance.

--

net: bridge: disable MRP ports before the FDB flush in del_nbp()

This patch moves br_mrp_port_del() and br_cfm_port_del() ahead of
br_stp_disable_port() in del_nbp(). The idea is to clear
BR_MRP_AWARE_BIT before the port is moved to BR_STATE_DISABLED. That
should stop frames received during port removal from learning FDB entries
that still point at the port after the final FDB flush.

Link: https://lore.kernel.org/netdev/20261012123051.GA714215@shredder/
Closes: https://lore.kernel.org/netdev/20261022090431.3641707-1-teel4res@gmail.com/

> diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
> index 2c05ebc1299d1..fb25ce3e5e646 100644
> --- a/net/bridge/br_if.c
> +++ b/net/bridge/br_if.c
> @@ -341,13 +341,13 @@ static void del_nbp(struct net_bridge_port *p)
>  
>  	nbp_delete_promisc(p);
>  
> +	br_mrp_port_del(br, p);
> +	br_cfm_port_del(br, p);
> +

[Severity: High]

Does this reorder cover a port that is still MRP-aware but is no longer
referenced by any MRP instance?

br_mrp_port_del() only clears BR_MRP_AWARE_BIT when br_mrp_find_port()
finds an instance whose p_port, s_port or i_port is this port:

br_mrp_port_del() {
	struct br_mrp *mrp = br_mrp_find_port(br, p);

	/* If the port is not part of a MRP instance just bail out */
	if (!mrp)
		return;
    ...
}

br_mrp_set_port_role() overwrites the role pointer. It does not clear the
displaced port's bit, and it does not swap the roles:

br_mrp_set_port_role() {
    ...
	switch (role) {
	case BR_MRP_PORT_ROLE_PRIMARY:
		rcu_assign_pointer(mrp->p_port, p);
		break;
	case BR_MRP_PORT_ROLE_SECONDARY:
		rcu_assign_pointer(mrp->s_port, p);
		break;
    ...
}

Take an instance with p_port=A and s_port=B. An IFLA_BRIDGE_MRP_PORT_ROLE
request that makes B primary leaves p_port == s_port == B. Port A stays in
BR_STATE_FORWARDING with BR_MRP_AWARE_BIT set. A follow-up request to make
A secondary fails with -EINVAL, because br_mrp_find_port(A) returns NULL.

When A is later removed through br_del_if()->del_nbp(), br_mrp_port_del()
returns early. br_stp_disable_port()->br_set_state() then still skips the
state change:

br_set_state() {
	if (test_bit(BR_MRP_AWARE_BIT, &p->flags))
		return;
    ...
}

With runtime VLAN filtering off, br_allowed_ingress() still returns true
after the VLAN group is unpublished. So br_handle_frame_finish() can keep
learning on A after the final br_fdb_cleanup_by_dst(), up until
netdev_rx_handler_unregister(). That window includes the
netdev_upper_dev_unlink() notifier chain that the reproducer delays. The
learned entries outlive destroy_nbp_rcu(), and a later frame to those MACs
would hit the same br_forward() use-after-free.

The commit message says the reorder means that "br_stp_disable_port()
actually transitions it to BR_STATE_DISABLED". Does that hold for this
state?

The role bookkeeping in br_mrp_set_port_role() predates this patch. Still,
should del_nbp() clear BR_MRP_AWARE_BIT (or force BR_STATE_DISABLED)
unconditionally? Or should br_mrp_set_port_role() be changed so it cannot
leave a port orphaned like this?

>  	spin_lock_bh(&br->lock);
>  	br_stp_disable_port(p);
>  	spin_unlock_bh(&br->lock);

[Severity: High]

Can the use-after-free still happen when CONFIG_BRIDGE_VLAN_FILTERING=n?

The commit message relies on nbp_vlan_group_unpublish() to drain the
receive path:

  With CONFIG_BRIDGE_VLAN_FILTERING=y, synchronize_net() in
  nbp_vlan_group_unpublish() also drains receive paths that could still
  learn with the old state before the final FDB cleanup.

When VLAN filtering is compiled out, that function is an empty stub in
br_private.h:

static inline void nbp_vlan_group_unpublish(struct net_bridge_port *port)
{
}

CONFIG_BRIDGE_MRP only depends on CONFIG_BRIDGE, and
CONFIG_BRIDGE_VLAN_FILTERING defaults to n. So a build with MRP=y and
VLAN_FILTERING=n is valid.

In that build, br_mrp_del_impl() sets the port back to BR_STATE_FORWARDING
(if the bridge is up) before it clears BR_MRP_AWARE_BIT. A reader in
br_handle_frame_finish() can read p->state without a lock, see FORWARDING,
and only reach br_fdb_update() later:

br_handle_frame_finish() {
    ...
		if (p->state == BR_STATE_DISABLED) {
			reason = SKB_DROP_REASON_BRIDGE_INGRESS_STP_STATE;
			goto drop;
		}

		state = p->state;
    ...
		br_fdb_update(br, p, vlan, eth_hdr(skb)->h_source, 0);
    ...
}

Between the DISABLED store and the final flush, del_nbp() never waits for
such a reader:

del_nbp()
  br_stp_disable_port()          /* p->state = BR_STATE_DISABLED */
  br_ifinfo_notify(RTM_DELLINK, ...)
  list_del_rcu(&p->list)
  nbp_vlan_group_unpublish(p)    /* empty stub, no synchronize_net() */
  br_fdb_cleanup_by_dst(br, br_port_to_dst(p), 0, 1)
  ...
  netdev_rx_handler_unregister(dev)
  call_rcu(&p->rcu, destroy_nbp_rcu)

br_fdb_update() does not check whether the source port is being removed.
If the reader gets to fdb_create() after br_fdb_cleanup_by_dst() has run,
the new entry points at the dying port. The same happens if the reader was
spinning on br->hash_lock while the cleanup held it.

netdev_rx_handler_unregister() only waits for the reader to finish. It
does not remove the entry. A later frame to the learned MAC would then
reach br_forward() through the freed port. In this configuration, the same
window seems to apply to ordinary ports as well.

Would an unconditional synchronize_net() between br_stp_disable_port() and
the final br_fdb_cleanup_by_dst() be needed here, instead of relying on a
side effect of VLAN filtering?

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261101044840.1595584-1-1020691186%40qq.com
Technical Details
Message-ID: <179359505012.3131.7814662128826235179@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354459-linux-kernel-netdev=dewy.ru
References: <20261101044840.1595584-1-1020691186@qq.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354459-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3] net: bridge: disable MRP ports before the FDB
 flush in del_nbp()
Date: Mon, 02 Nov 2026 04:50:50 +0000
Organization: Usenet Network
Message-ID: <179359505012.3131.7814662128826235179@kernel.org>
References: <20261101044840.1595584-1-1020691186@qq.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2847594"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:FEKr26xQlVMXq/SQevtN7n+9u3s= sha256:0UyFsnqJwMKcd3hkEEbzBX6G+UcJ4qHN3raRlim0+ps=
	sha1:47BCIHlNIYAawBi5Qf3HJkIVWoA= sha256:0nGahRq6HQ0oROJ13q+XOCmZr8fJcqDDwbUw8RUgEVw=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 242BC125CCE; Mon,  2 Nov 2026 07:51:19 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id zHHm4RDnk4vJ;
	Mon,  2 Nov 2026 07:51:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354459-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id BA8AD125CC6; Mon,  2 Nov 2026 07:51:06 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 8BE162A84D; Mon,  2 Nov 2026 04:50:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793595055;
	b=C5topi5SkwbKLh5lJbnxEyfF3JcPN54SZuPRoSq3CsDWEfLbdSKblWxNEn6MxsWxxBIj
	 Iz7supyoRNZcvHmgUxbYwsKgPUFjrcMt7O9WfsnflSgstiWMYED2toPVls5DfbAWinshf
	 dFy+7D1R1+hcrHbMRAFwzJ6gohGmrpzt/XMfqbkcx0qzsQkUs352xrpgn98elnfJX5JCt
	 klKeRw2wcYIfjOj65nsnyr0nDlrQAiAvJAgl5iSKOkFrzK/320Uf5iho9zITSCkderUWo
	 IF0nAUkkeYRFA0mNq+xTfW2wgokp8dBP+T70ifLc8s031oYxLow2RfyVvyahDcCpSeQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793595055;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=9NjwTKigzXyJcNab5AKVuwtkEGTVfIQKZBQ4FCtvQwA=;
	b=ZKYSfS531jU4bmWM1sxkWTcLb+hdeu6qY0nCkx3BditkJthojAlnqVFyfSYk9BKbwKqo
	 ds5eazKNzQAazzFYvvoCwc6qw5tsZGXXNMtlaiUrjx9X9jd4yJJxf1MLh6pZlEPBipLaQ
	 q/dJSAPWp3f8WMZeU9cyTlWSl0mgo1LQ75KGLNrKmlOzfIlPBAjI+myVaubWXQy0iFIuR
	 GPKHkQ4gOAPrGRJFVJzckfatSTtvNE/LMqSLl3AfFdv4CP5CDPWROKS+M3ezKk5ULx0Vf
	 o1TYhFLX79f2X/lkaKexhKXpArwEsOLfDXxw2femsx84L/n+ASMLbmm3doaXprSQNzg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IOLSLxfQ;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 638C9606A330;
	Mon,  2 Nov 2026 04:50:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IOLSLxfQ
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793595052;
	b=cG2mvkU09gEqOEkDVSsPt6LQwKm1WH8IPF9YtGWmM+9qz1YCdRbLUJVbaePs/8xussTn
	 K7RRiY9Jueg3FuVbf+SDp3vzDZz+ORFTpVmDuJYIdx7nLCtqthcMdCHSt/arjPxbKYLKt
	 /bRZk3gaNwvWBLxNGFVdWxEDqs8wNTUhW3v8cZT2/6xSJ0BH7PPPPqCVvNwf4RWrTXpQw
	 lw911Ya0Bxa5I0r1SqXwq7yrhBK/cK8UppxmyHN65DUI2Q5TXws3a3tlYqNLiRo7koCzD
	 9khWyJUTQ5u0Zm8nOrJ36K+7SXP0k/NhqzpQFlWfYxsN0vQlVM7Dxa/K0hJJPFoZfWQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793595052;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=9NjwTKigzXyJcNab5AKVuwtkEGTVfIQKZBQ4FCtvQwA=;
	b=ddpSFxh+83u8S27Pi2l3OvlWt5OSk1wFV9Sv2P4xyZVTPgM8EFf/MXc7g4oAITUmgfmj
	 Noj3O3BPPy33s5xUeAprd4mnlazysvIeudz/A5Aqn8J36Yn3Xgt0CQjuGwBd62K0sx2HQ
	 msHz0dp3z9EDydm6yjXQel66kc7VOOpGQXmajmSgLMjrojbXOoulraXztkVhPUMHNAwbB
	 Fe6nVSf63sx3kfHbmlQJC60B3FmDKPQVuOa8Wfm2vQncO3GZX33a30QtlX1Wgf5Mq2E+u
	 DKGOgcKzUOaMquUMMjtEbngVugxAcFuAf1maxoA8d60Q7whfCRej2MpfKHRKI+WFX6g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IOLSLxfQ;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DE38606A324;
	Mon,  2 Nov 2026 04:50:51 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91A701F000C1;
	Mon,  2 Nov 2026 04:50:50 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793595051;
	bh=9NjwTKigzXyJcNab5AKVuwtkEGTVfIQKZBQ4FCtvQwA=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=IOLSLxfQGXSJq1mJoNmIBhj1iuVg335HttuJX0YH0goMJX9+RTkhuipnqvh3VzmRa
	 nUN3UFGqRlYvmAL4655Eq9Pu0n9Flfk0B+EiIFyzGq9IcovHkkpu6OxjzHGQxLu4yl
	 wAUgQi6C7iTa/IfMQk9GPSIQd2zuDHtq6U4EdaglhoihP9V5c3/0fJklIsbc/a3+FU
	 gzK4JQC0KjTLq25/pmRAdGjRdgOcq1oLyH3RKtgnS8u3IJn+0iI88E4FzlbOCUXQfd
	 zQoUk+6mi1yZaSqjuz6o6oFN1GsGIvt/Dz8yrYZkOdPfdcRh3JT12N/BKSYtzN0SJs
	 f0GYmxuA//bxA==
X-Cc: idosch@nvidia.com, razor@blackwall.org, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
 horatiu.vultur@microchip.com, bridge@lists.linux.dev, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261101044840.1595584-1-1020691186@qq.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list