From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 695661F00896; Thu, 3 Dec 2026 03:31:54 +0000 (UTC) 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== Subject: Re: [PATCH net] net: dsa: clean up conduit state on setup failure From: netdev-bot+sashiko@kernel.org To: huxinyao@kylinsec.com.cn 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 Date: Thu, 03 Dec 2026 03:31:53 +0000 Message-ID: <179626871396.3146.6448387337235326256@kernel.org> In-Reply-To: <6323744BEA8D6888+1796182219.53640-1-huxinyao@kylinsec.com.cn> References: <6323744BEA8D6888+1796182219.53640-1-huxinyao@kylinsec.com.cn> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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