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=1796382077; b=026zW+7I34wLR7wMa8MWIvqUQognZmdjCiyBIEgB9ILAsIGVHG0oM5kjBpPJe64AV9py 1fRcbOSiB7BncJeEqsuT5KSLlf8gU8pzjgrkYsX0eX4ug89gnH+Q/UBOjiGBFLKxVo2Lj GK0FLe0z3i+9WZ8nxfG/AHVQfCHgcYs7DSUz0SDblwnkgIw6JLK981MvgwrTEmv68x4o6 QdGOaWj1oGNso2m/f3kokGLcAeaHGEqlxoVYvGxeC6H7x/YoQNrINMm1zxBQa5A5xgk48 ZuZXPbo+1N3X8XcQ94K8H+sQxr/fcGTdJxD/iw9SNQj3fEOkojpBE6OKvhNVfRPhahQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382077; 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=tt9ijLZfPzZK0wGthgdNflJmsB2RpgoD65d7xXMZ8jw=; b=o+auOeaUDlGu9/ZkfsbBAWN5VhtlBXKWTBRul59DLzfJKRLI0rj00a5NADoI5FEc2Pvn sISPSBlUcrBhLXQzLL5Rxx9OPUbdu4GOD61x7GEC0zuPA8+ba91scnMkXLogqLGd55HND uU9kwXS0pcnrqEP1IOiNzuTBtzU/ujk48UY8Yd7CHOtAOAGtfVwqgZt/CWvSXcAwGTzA2 gmoZ2ZG6UJuD+GA9F7jm5G3rtNnFU96XFoQgw0JNyL8drY1e7QxPDvh2OKfhM/FdtIa2p e2rEdq+dnuceHJ4eAr3ZH8fFGL0dLG68VbBTA6mxW/vImFCbFtpu7H+UbbOSGj3Cpcw== 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="1/J+ylu7"; 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 EC839606A335; Fri, 4 Dec 2026 11:01:16 +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=1/J+ylu7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6877E1F0092C; Fri, 4 Dec 2026 11:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382076; bh=tt9ijLZfPzZK0wGthgdNflJmsB2RpgoD65d7xXMZ8jw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1/J+ylu7gmRZt8R/yV78GP+S97cVGYtE7qHOZ8rHc7nt4D5I24ZEKbKyy1pDdgSQD knYA/IHORhGzKcD9+TrqdlHJAWe6bgUMdMdZViMVlcXwOoErhHpOkr7aRIuSDO81H2 hIH8sNJq9uaTUkycJUBDZ6S1h9Q+5EQ0/lwat5ZE= 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 6.18 298/703] net: dsa: felix: fix NULL pointer dereference in felix_port_enable() Date: Fri, 4 Dec 2026 19:03:17 +0900 Message-ID: <20261204100635.709525107@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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 20ab558fde247..4a4fc26cfdc0b 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