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=1796383596; b=y+RaQlwmB3PBr48PkyhzG3zzRR8rBt6S+cafHCJ2hSAukeV+hjwbVBC2FZVUONVd+8r4 JGiy1dOzUPMM5bxzJ17lHLiYQodDDmxkivduLp0Ap7qlXyMF8oqNO5iROciKRPq7UrdTp xVHgZpQqtX2oG1XKN4+ghK48O/Abnhv1/gg5vUCOgWuPneewBa5INsPl9meAtd/2gzqlb zGXWUeAPvVPsqNzhERqcCWirORShvBZF2UUBmcc4oGyHMl0UiZHcVoxYsk5IBrMeXgeqS gxZx3j4Wfit6lG3slndjJXuRk3UVdlQRw/42GbN+LwmCvq1ske8ScSZqvc0O+7Zo45A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383596; 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=jvH9xvm2FOFrKhdMQiOvut9RVWMexaQR53CV0D6bxxg=; b=lM+1PamvcvZQKwRObgbDMYZBeCNk73Vp6WaAxw4/X4mcy7fBztESAOih4v84iKZItj5A CqSyo0oMo9u3ojChRIIc6LfXRPWq+U0msbi8UkoPWcC0/NTKcLpVNx/EnaD8j35xnVvF+ zFBl/mXN3+cnZN7AmKHXtJ/pvpcXjdvCZ2k2CUPrK66IoADtcqYBFN6/a9LbUIc3VzqJX 6jUkAu6FdZvQHzTovYuQNXB4nMZcQ2FYs08nxE6pPTxdtTaKgkvcFuHQwnoS9ctYtUlzH T2z/UCqzWshNXOAeQLV11bKwDphQyh6vdOwxrLHqtMqpUS5OHsZs/IIFzlrWQ32gAfg== 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=u4q5Wadf; 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 31FBD606A32C; Fri, 4 Dec 2026 11:26:36 +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=u4q5Wadf Received: by smtp.kernel.org (Postfix) with ESMTPSA id A39BA1F000C2; Fri, 4 Dec 2026 11:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383596; bh=jvH9xvm2FOFrKhdMQiOvut9RVWMexaQR53CV0D6bxxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=u4q5Wadf8nF5SSH4uQm5lmv+JCHwWN2dWfWreV2tQ7Yg0x/k8l9ZJB2TwWbPjfXlT wRz4ov5Yj+KxY4QZZrSzGmWw3wIHxlHTm7vMxVFbcT//IpHypQuc/380x+FSLr9Qzy N7gWAseG8wPJ2t01c/jnTDol+FtzJRmwcPuThXaA= 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.12 290/555] net: dsa: felix: fix NULL pointer dereference in felix_port_enable() Date: Fri, 4 Dec 2026 19:05:33 +0900 Message-ID: <20261204100620.149780859@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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 72fb6594331e9..e43b0862d701b 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