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
Subject: Re: [PATCH net] net: dsa: clean up conduit state on setup failure
Date: Thu, 03 Dec 2026 03:31:53 +0000 [thread overview]
Message-ID: <179626871396.3146.6448387337235326256@kernel.org> (raw)
In-Reply-To: <6323744BEA8D6888+1796182219.53640-1-huxinyao@kylinsec.com.cn>
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
prev parent reply other threads:[~2026-12-03 3:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 3:30 [PATCH net] net: dsa: clean up conduit state on setup failure Hu Xinyao
2026-12-03 3:31 ` 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=179626871396.3146.6448387337235326256@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=huxinyao@kylinsec.com.cn \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--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