🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26122

Re: [PATCH net] net: dsa: clean up conduit state on setup failure

#26122
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 03:31
130 lines
12648 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

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] On failure, dsa_conduit_setup() (net/dsa/conduit.c:470-476) now
  always resets the conduit MTU to ETH_DATA_LEN and writes `dev->dsa_ptr…
- [Low] The new error-path comment in dsa_conduit_setup()
  (net/dsa/conduit.c:473-475) is inaccurate and claims more than the…

--

net: dsa: clean up conduit state on setup failure

This patch clears dev->dsa_ptr and resets the conduit MTU on the
dsa_conduit_setup() error path. It also adds a teardown loop in
dsa_tree_setup_conduit(), so CPU conduits that were already set up are
torn down when a later one fails. The goal is to avoid a use-after-free
of cpu_dp once dsa_switch_release_ports() has freed it.

> diff --git a/net/dsa/conduit.c b/net/dsa/conduit.c
> index 1470885d5a5ee..4a56585531bd4 100644
> --- a/net/dsa/conduit.c
> +++ b/net/dsa/conduit.c
> @@ -467,7 +467,13 @@ int dsa_conduit_setup(struct net_device *dev, struct dsa_port *cpu_dp)
>  out_err_ethtool_teardown:
>  	dsa_conduit_ethtool_teardown(dev);
>  out_err_reset_promisc:
> +	dsa_conduit_reset_mtu(dev);
>  	dsa_conduit_set_promiscuity(dev, -1);
> +	dev->dsa_ptr = NULL;

[Severity: High]

Can this wipe out state that belongs to another CPU port?

The error path now always resets the MTU to ETH_DATA_LEN and writes NULL
to dev->dsa_ptr. It does not restore the value dsa_ptr had before
dsa_conduit_setup() was called.

dsa_port_parse_cpu() does not seem to reject a conduit that another CPU
port already uses, whether in the same tree or in a different one. In
that setup the second dsa_conduit_setup() always fails, because the "dsa"
sysfs group already exists on the conduit:

	ret = sysfs_create_group(&dev->dev.kobj, &dsa_group);
	if (ret)
		goto out_err_ethtool_teardown;

sysfs_create_group() returns -EEXIST, and this error path then sets the
shared conduit's dsa_ptr to NULL. Back in dsa_tree_setup_conduit(), the
new teardown loop runs for the earlier CPU port on the same conduit:

	dsa_tree_conduit_admin_state_change(dst, conduit, false);
	dsa_conduit_teardown(conduit);

dsa_tree_conduit_admin_state_change() then does:

	struct dsa_port *cpu_dp = conduit->dsa_ptr;
	...
	if ((dsa_port_conduit_is_operational(cpu_dp)) !=
	    (up && cpu_dp->conduit_oper_up))

Wouldn't this dereference NULL through
dsa_port_conduit_is_operational()->dsa_port_is_cpu(), with rtnl_lock and
dsa2_mutex held?

Even if that call were skipped, dsa_conduit_teardown() would hit the same
NULL in dsa_conduit_ethtool_teardown() and dsa_conduit_set_promiscuity().

The cross-tree case has a similar problem. If tree B fails to probe on a
conduit that tree A is using, tree A's dsa_ptr is cleared and its MTU is
dropped, so tree A's tagged traffic goes through the normal receive path.
Tree A's later dsa_tree_teardown_conduit() would then hit the same NULL
dereference.

Before this patch, this setup left a dangling dsa_ptr. With the patch it
crashes every time inside the new teardown loop.

Could the previous dsa_ptr and MTU be saved and restored here? Another
option is to reject a conduit that already has dsa_ptr set before this
point.

> +	/* Pair with wmb() above so packets stop entering the DSA
> +	 * receive path before cpu_dp is freed by the caller.
> +	 */
> +	wmb();

[Severity: Low]

Is this comment accurate?

The wmb() above, before dev->dsa_ptr = cpu_dp, is also a write barrier
on the same CPU, so the two cannot pair with each other. A barrier pairs
with a read barrier or address dependency on another CPU.

Also, a wmb() after the NULL store does not wait for receive paths that
have already loaded the old pointer. dsa_switch_rcv() uses a plain load:

	struct dsa_port *cpu_dp = dev->dsa_ptr;

and netdev_uses_dsa() does:

	return dev->dsa_ptr && dev->dsa_ptr->rcv;

Either one may still be using cpu_dp when the caller frees it in
dsa_switch_release_ports():

		list_del(&dp->list);
		kfree(dp);

The matching barrier in dsa_conduit_teardown() only claims that later
packets take the regular receive path. Could this comment be reworded to
say the same thing? Protecting readers that are already in flight would
need something else, such as an RCU grace period.

>  	return ret;
>  }

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/6323744BEA8D6888%2B1796182219.53640-1-huxinyao%40kylinsec.com.cn
Technical Details
Message-ID: <179626871396.3146.6448387337235326256@kernel.org>
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376258-linux-kernel-netdev=dewy.ru
References: <6323744BEA8D6888+1796182219.53640-1-huxinyao@kylinsec.com.cn>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376258-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: dsa: clean up conduit state on setup failure
Date: Thu, 03 Dec 2026 03:31:53 +0000
Organization: Usenet Network
Message-ID: <179626871396.3146.6448387337235326256@kernel.org>
References: <6323744BEA8D6888+1796182219.53640-1-huxinyao@kylinsec.com.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2132178"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:M+URGqG5d6vEFpwZylb1zEO/51U= sha256:KnvmK6g0FChTGD9Ipf9fNQmBi4dsK2yrf/EN8HdSDpU=
	sha1:0D7pFQvOYCfs7E2jhpGSVCL/qQY= sha256:aHcbIXWh0pe/SyI0NrjdNfL6eLbQJvmNVG+8ouweAwk=
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 8DBF0117800; Thu,  3 Dec 2026 06:32:16 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[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]
	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 JuI0vE5oEMqd;
	Thu,  3 Dec 2026 06:32:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376258-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 36D6A1177FC; Thu,  3 Dec 2026 06:32:03 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 49BB226FB3; Thu,  3 Dec 2026 03:32:01 +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=1796268721;
	b=ahtdMsND5Sp/n7MgArHKvMNVV1e2++76n/9G1WXIBvausfhrsKxfrq0EYKjOnnHF/CLp
	 EVVgordAWlRFd9wQKJxi65lmwcromgOxIfvNRTI6JInocIOFfnv5/wZvXKuSSA8Qhlpxe
	 1zwazl0ldxIEXalAy0uIOmTpTA6+P3kLWIBbbrvLfV+BtGmDbLCn4CA44FhBOiga3oXDf
	 u6xqThxgy8YPanriOnjmRDLl4Y5kbopmKsnHlp07yu81ZhVggCMEnLxaGK0DktwFOL1MT
	 XpZxWOkN8bfDhRsNEgFz1R+yqXjEwTQa4Uu+7zzs+8I/0j33i2WAEZFCyPZmRpUocWA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796268721;
	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=Mww6hhCaeC+6LztnNWl/jzkjZsWaWIsKGG8Ove/OlXA=;
	b=YeXUUmnQijOOYI/t3eEyuScZXB7PhN0qBhkPxNPu9K4ziMoGnAgtKVtfns0gnCHCSEu/
	 EZcJ4eYaHK4k9z4IhfAQsSZQtf9rg8pxUBaYzGNMv7Xpk8npXgGgl7U7LyymYuL2Y6maa
	 qPUTzvUw+3nh2u24kg4OZzl83xhIXVJAia/glXZ/3qB0MRoZuq7NmUfiaezJDqvmruvpZ
	 GM0tSmdkg/h972XvIBXHdDuY3VP/dPIGSrzxqNtmeI2+o8nc3+ZQPB/xh0dY+G8h68ncl
	 qEqSyme9zIBQfx3Bz+PWpT603AOI6UluEPSJplqTm+jbJabdOGKUig3pIb8tzsyIacQ==
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=mQucvEig;
	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 0C56D606A322;
	Thu,  3 Dec 2026 03:32:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mQucvEig
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=1796268715;
	b=FSBKa0tdMaDg/6BnLsY4CddnuJP8wLZbyV/NAPUtRa4VQkD8wKGRqwpc4MtkRbfd6sHG
	 DknKgLg4dz5gccrwqpaeCqgN5HneWV99sMVAFUtO6MklWSoQ+lvaGhZ90LL2KS4TxlUEK
	 Ys6/ZTo09fGrw7K/0j4HmJ2vhSyApkMoKhGv7fJ+W5JD2+PIclkJf91eS4Pg1gRl8ywuI
	 QL+j/Q4xX8cYfL04Fzuz+E15uARNUvb9eNBeP+E3GfZC2h1uDtGIQxYQJNWkcdIvJ8OVy
	 wyasZtSnrfaDwWFCL4lOU/th3NJPdqyrkpVVgR2uu9YWhFnAIPdCxDclnY2/92mv2Ww==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796268715;
	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=Mww6hhCaeC+6LztnNWl/jzkjZsWaWIsKGG8Ove/OlXA=;
	b=r1rHd5Q35/cPAWTyvXWk0Ncj9D15+y3ekXDSTWYrc5GxDl3LlQLqDbsMNGTFdSxDjXE6
	 qdpdNbGKOUImwpJWtO4Bih9zNpqqNjTTQU9lNkmD5kWvRwAazaPQOHswxQPIZphfGTKZO
	 7tc9AeJ0Znj2aOpJwbf95m2d2jne+vmGYKKkTF/Y0IEfkSRghp4gJg6jgyJTQdWYgZ5cT
	 3SlwsnnV5aHIdLvnMDP97dfsZu5qmz/3cfMG28RKpGGy4CALIQcUIOe6OwCXl9AHNLSax
	 Bnv6bANctmU3GEcTgf3pe7MEzr2Ex1gICnP5yKlBhWOltTr/7cGtXhFDX1qdgavq2yw==
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=mQucvEig;
	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 28954606A330;
	Thu,  3 Dec 2026 03:31:55 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 695661F00896;
	Thu,  3 Dec 2026 03:31:54 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796268715;
	bh=Mww6hhCaeC+6LztnNWl/jzkjZsWaWIsKGG8Ove/OlXA=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=mQucvEigtRVDSbX3M72nXylMuSwQUrkTgWKG7Ii+nVum0wXLMdq++LEVzZ6W6WlFF
	 wQIAOZR2eufOhHsgX+Wg2QTrPRBdipnx3NFSohegXWrDE/BsizO7m7vaks7Zx1W93G
	 c8uHhsdw7LBuSAtipFYsEcNouJAWviYIH0uYsGzBDuo8XVaNUGPPrhSWoMY6c2s4Is
	 6HtgZlZ5mm4UrtbYIEcjEn6XDVRWFdY4GoTLn4Y3momaoTJTdo+R3ek3xIvv7jJdGg
	 uTbzxC/Z14VKa0w8ZsGgDhbcsljKcI/G3L+ykaIrH2UoE7YhMjkC93GtyTZazlucFl
	 eExoQ+sr9IiIA==
X-Cc: andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
 horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <6323744BEA8D6888+1796182219.53640-1-huxinyao@kylinsec.com.cn>
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