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=1796468932; b=0Ur6OBGW7+NF4IzMakZe632IHLCVVo5DEq5dHe41BS6ZnQdcktBwkGwxINRKFvHTexxY eBrGVEToDgmiXP9ckxdvGGbSoT5xDrrwdTAL6D3TBiyFg/mkCmt6UbdP45jgA37dv5cI4 sCFvy4s2fqGyIWqfiwxWn0p5tqtSngQrO1NDHZoVZ2HMgJSB292HonPh6H/ybF8LfqoKH aRbef2O9VP9KbnUBcgNfRbU5bHh+JSku5XhNvYw6ROZCYfcvQGGxo48nR72rmV8Wzii3k kaOi0du3AK8Ks4xn3Su2t2bPhyLZtFCwd4pZyQkyKq7C3zRO/7ay0JUcPyf3u33amWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796468932; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=irJVXYGFNYI7RhrqpbSD3jOuRWoe/x6HZOD/KUFGiSw=; b=EnrdYewiGXO7vIpYwFX7akRd/P1gcxLlCaLRtqbykhs5EkHwUi9UI4w0gdCfB6GkDrE4 LWNET0ePXOlQqITbzLHkuhtKFt7b7/Wm4eLQ5sIOltWICgmjPEzh1cZiQmKs3qwItsw2+ FEZ0q/bZBl+4cWtlzKjfm9RhnpUDdDvO5XQ0XFUA+lojkEgH+SQbNhUyz5HhixbJXagHN 4vElepjw3XbJzRoRCBzgXJLIsM4mgkmNQu5q9ExEXiw/dAa78hDKWuEfGCSncFQu5TuKN m/MfgCneZsbIBvvPlK0J+cengA7bMsTmTlGKIYU7Lrfyvlae6kCbkFrGqkMuezDkDmQ== 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=FEja22yg; 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 835F0606A322 for ; Sat, 5 Dec 2026 11:08:52 +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=FEja22yg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E40C1F0092B; Sat, 5 Dec 2026 11:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796468932; bh=irJVXYGFNYI7RhrqpbSD3jOuRWoe/x6HZOD/KUFGiSw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=FEja22ygSut/7/UE20nQyGupC79o/hkJXwgC0l9xJZrhf/aYBxGLJZVqdNIEAwa2b MooQxC7REPLQOM/FvWmyVwRpBEVwk0BdlD7GlleB21RsR0a2JkOxnm9KMBnJbRymAk hatlVNsRNxKD9c7pCmcVFpae/15D7z9fhd9lFoLw2wpWQkxhw2mw6tc+HWaMJ6Ea4v BNooL03lq+qWgma60XpqOPOi/y1h+ETn5YyocfQLSR49QNkgxxNyO+A/9mz+IclChO yYP+BcA7/VXcSvNXegbndxwq4zt429GXxNOYmw7Dx7BBgOINE8rpuInEbx5XLUIZ4j 9Sfth1m3wA8nQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver Reply-To: sashiko-reviews@lists.linux.dev To: "Maxime Chevallier" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204110622.1106492-12-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-1-maxime.chevallier@bootlin.com> <20261204110622.1106492-12-maxime.chevallier@bootlin.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 11:08:51 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] net: phy: mux: unsynchronized mii_mux_auto_remove() vs phy_mux_detach() - [Medium] net: phy: unsynchronized pl->mux access and detach vs phy_mux_unregister() -- commit 3ddf01a7f8c108024edc40420dc253bccef488c1 Author: Maxime Chevallier net: phy: mux: Add the mii-mux-auto driver This commit adds the mii-mux-auto platform driver for hardware-switched two-port MII multiplexers, validating the port fwnodes, registering the mux with the phy_mux core, and unregistering and freeing it on removal. > diff --git a/drivers/net/phy/mux/mii_mux_auto.c b/drivers/net/phy/mux/mii= _mux_auto.c > new file mode 100644 > index 0000000000000..980cc2c242ba7 > --- /dev/null > +++ b/drivers/net/phy/mux/mii_mux_auto.c > @@ -0,0 +1,99 @@ [ ... ] > +static void mii_mux_auto_remove(struct platform_device *pdev) > +{ > + struct phy_mux *mux =3D platform_get_drvdata(pdev); > + > + phy_mux_unregister(mux); > + phy_mux_free(mux); > +} [Severity: Medium] Can mii_mux_auto_remove() race with an unlocked phy_mux_detach() and cause a use-after-free on struct phy_mux or struct phylink? phy_mux_attach() adds a DL_FLAG_STATELESS device link, which does not force consumers to unbind when mii-mux-auto is removed. phy_mux_unregister() only holds rtnl_lock() around mux->pops->detach(), and phy_mux_free() immediately destroys the ports and frees mux. phy_mux_detach() takes neither rtnl_lock() nor phy_mux_mutex. phylink_destroy() calls phylink_detach_mux() -> phy_mux_detach() unlocked before freeing pl, which is reachable with pl->mux set if mvpp2_open() fails in request_irq() and mvpp2_port_remove() later runs: CPU0 CPU1 mii_mux_auto_remove() mvpp2_port_remove() phy_mux_unregister(mux) phylink_destroy(pl) rtnl_lock() phylink_detach_mux(pl) mux->pops->detach(mux, pl) phy_mux_detach(mux) phy_mux_stop(mux) rtnl_unlock() phy_mux_free(mux) phy_mux_port_destroy(port) kfree(mux) phy_mux_detach_phys(mux) <-- use-after-free In the reverse ordering, phylink_destroy() can free pl while phy_mux_unregister() calls mux->pops->detach(mux, pl), or both paths can double-detach the PHYs and devlink. Using a managed device link or serializing teardown with phy_mux_mutex would prevent this. [Severity: Medium] Can mii_mux_auto_remove() also race with the unlocked pl->mux check in phylink_fwnode_phy_connect()? Callers such as ocelot_port_phylink_create() and dsa_user_phy_setup() invoke phylink_of_phy_connect() -> phylink_fwnode_phy_connect() without holding rtnl_lock(). phylink_attach_mux() sets pl->mux under phy_mux_mutex and then drops it before phylink_fwnode_phy_connect() checks if (pl->mux): CPU0 CPU1 phylink_fwnode_phy_connect() mii_mux_auto_remove() phylink_attach_mux() phy_mux_unregister(mux) mutex_lock(&phy_mux_mutex) pl->mux =3D mux mutex_unlock(&phy_mux_mutex) mutex_lock(&phy_mux_mutex) list_del(&mux->node) mutex_unlock(&phy_mux_mutex) rtnl_lock() phylink_mux_detach() pl->mux =3D NULL rtnl_unlock() if (pl->mux) <-- reads NULL fwnode_get_phy_node(fwnode) Because pl->mux is read as NULL, phylink_fwnode_phy_connect() falls through to fwnode_get_phy_node() and can fail probe with -ENODEV, return 0 without an attached mux or PHY, or attach a fallback phy-handle while pl->sfp_behind_mux remains set. Separately, phylink_destroy() calls phylink_detach_mux() unlocked before kfree(pl), which can race with mii_mux_auto_remove() -> phy_mux_unregister() and phy_mux_free() to cause a use-after-free on mux or pl. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204110622.1106= 492-1-maxime.chevallier@bootlin.com?part=3D11