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=1796380484; b=zdt9tkuzvSLysnXcXeJvyG/0LsW+yw5fg12HotDw7GdwrjwF953pp7j/6fSpoUweR2le VTReVA5TKdYkRxDyOuw/gDJyXD8QGKuJ/5acjEGyCab7PCMr/r7iUZIDLUVQjsiYAV/2m LwR1VyFJoBCYoW4J9H+UCenqI3oEgUlXTzcpZ+fsOBhcz4jJvUAOowH86fB+NxS5BVW5g RYJfvk6VkeJO7hpkyDM4TBjXlNH8UcmPHvmfdOOkhI6MxTekt43cN7rp2AR9/78rxZIuv tkGq0+xujrwba1Lsmk4OfLXQKqR55FLeupp5j283soUGBZ56kyjebe0iLfUe3FI8YEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380484; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=eCV/thAQ1mWLTL+zU0b5psq7RPJ4/UUPPtsG4uZu8PQ=; b=C3HHTiHKszVjLa6aATSy3rNLNTV8VEoF4YXVTXe2U9uJX3TvqUfI6Y8o7uHB1DvoNTC9 qgR/pyYZTcTvJ65laa1q8NsB8VMGQ32HYDKS4jOsYWQKltZpNdBrilL1M9f7zv1eroJfr NVfE9+4B4z3wB+Dzt+y6hqktx7FxmurDRSTYNK72MlSiMF1EyEE7CbFVhAXTuAofVXYjf JJcfSnsY9/uq79BkNXE2cUNk32bxIxlLBptb0cBwLk+IgnO2Jmcefaj9ratKZDmes3MD2 4RCzkvb9ey2mXE5fXlJKzCIqh0zE02mOoe9KZ/RMV433U971DhEEPeeb1196p+hPKbQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nvl84kw9; 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 0678D606A697; Fri, 4 Dec 2026 10:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nvl84kw9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AA781F0092C; Fri, 4 Dec 2026 10:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380483; bh=eCV/thAQ1mWLTL+zU0b5psq7RPJ4/UUPPtsG4uZu8PQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nvl84kw9yYPhDZ/DF54c9LnADvxV12I88zTfdXkYQJVwF2Qx7kjAZ/uv4VM93xO4T aQMq7vEnr8aVSzVttwEWTCwwWrNRTOf70vvWitC7iov9kYJNTvkyPfyHIFunGziYgZ mjJU6QZXEP2R+VDlXuoPbvGnfSwPgAL7bKqDg8qY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Aristo Chen , Vladimir Oltean , Paolo Abeni , Sasha Levin Subject: [PATCH 7.3 266/742] net: dsa: felix: fix NULL pointer dereference in felix_port_enable() Date: Fri, 4 Dec 2026 19:02:10 +0900 Message-ID: <20261204100642.128513618@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Aristo Chen [ Upstream commit 469b61e4be88bc671dabe802e11f706b1ea7aa15 ] DSA registers the user ports in dsa_tree_setup_ports() before it sets conduit->dsa_ptr in dsa_tree_setup_conduit(). On teardown, it clears conduit->dsa_ptr in dsa_tree_teardown_conduit() before dsa_tree_teardown_ports() removes the user ports. RTNL is not held across either pair of steps, so user space can open a user port while conduit->dsa_ptr is NULL. In NPI mode, felix_port_enable() calls felix_cpu_port_for_conduit(). For a physical conduit, that function reads the CPU port index through conduit->dsa_ptr without checking for NULL. This caused an oops on an LS1028A RDB when systemd-networkd tried to open a user port while the switch was being probed again at runtime: [ 166.722423] Unable to handle kernel access to user memory outside uaccess routines at virtual address 0000000000000028 [ 166.816908] Internal error: Oops: 0000000096000004 [#1] SMP [ 166.961766] pc : felix_cpu_port_for_conduit.isra.0+0x90/0xb8 [mscc_felix_dsa_lib] [ 166.969289] lr : felix_port_enable+0x120/0x1a0 [mscc_felix_dsa_lib] The oops left RTNL locked. Later operations that waited for RTNL hung, and the board had to be power cycled. NPI mode uses one CPU port for the whole switch. Changing the conduit of a user port can move the NPI port to another CPU port, and the check in felix_port_enable() keeps user ports that still use the old CPU port down. For a physical conduit, compare dp->cpu_dp->index with the NPI port instead. DSA sets dp->cpu_dp before it registers the user port and clears it only after it removes the user port, so the check keeps working while conduit->dsa_ptr is NULL. As long as the physical conduit is set up, conduit->dsa_ptr and dp->cpu_dp point to the same CPU port, so the check gives the same result as before. LAG conduits keep using felix_cpu_port_for_conduit(), which does not read dsa_ptr for them. Fixes: eca70102cfb1 ("net: dsa: felix: add support for changing DSA master") Signed-off-by: Aristo Chen Reviewed-by: Vladimir Oltean Tested-by: Vladimir Oltean Link: https://patch.msgid.link/20261119100710.129379-1-aristo.chen@canonical.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/dsa/ocelot/felix.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index 84a95007825f7..dd471fff23bd0 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -1239,8 +1239,19 @@ static int felix_port_enable(struct dsa_switch *ds, int port, if (ocelot->npi >= 0) { struct net_device *conduit = dsa_port_to_conduit(dp); + int cpu; - if (felix_cpu_port_for_conduit(ds, conduit) != ocelot->npi) { + /* Do not use conduit->dsa_ptr for a physical conduit. It is + * NULL before DSA sets up the conduit and after it tears it + * down, and opening a user port can reach this check in both + * cases. + */ + if (netif_is_lag_master(conduit)) + cpu = felix_cpu_port_for_conduit(ds, conduit); + else + cpu = dp->cpu_dp->index; + + if (cpu != ocelot->npi) { dev_err(ds->dev, "Multiple conduits are not allowed\n"); return -EINVAL; } -- 2.53.0