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=1796468929; b=S3QZvA3MdacX0bP843/dRXyz9H2z383ngwunoqNl1p+H2ke3DriymBzv2jUgWV1XRnzC uua7oXLbidQ6VySbMP/IFVuHD8Np0TiBrzs9SraN9Q54jPnlo95oRbMg9tY2EjurfR+zD jLozcEN8RT9EhHCiozKuZXepzkjqzjQ80UqjKKFwfKnweohxAzEdO7itiPcFW0dGYqerU qdsV9V0Iz3SSqnFW3iH1bwRLkuV/VtLO4pX44/krTpIlTzOxkRWuHN6PoKYHtGrlf81Hz LMuAL7C0QjSEfVIMU4AcGBV82pRsHm949QwgopGSlpYGOirxRf8Py5aSxAmRZ8LU1FQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796468929; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=hEr5WOfQhBDWBCrij9wqagVgjp+PPoLLcFDxDdA3oWs=; b=zG9WDSIeL7sFbex4PchpVYJ5xemgjghyHGoEoD0sDdC2lIIEfUTonwmSGyXAU41IMWRg eA184kwJBLO3L5kCTbCXDVAG7dfpaS62vEtPp6/TaQzCruzcOKAFFwh/V/dw4vMu7+lEm eQj669f8njAdfpVzA/TUlqIJN3ggee6AHNosNyfteHAUVPuPnz9ux0btds0ZWSzvKlOnI LKVg3BxDAlcpBB74LL/2rj1TgrGsodve5dwSbhJ6YgUD6QIt2NeneNl6zGgheD4nEiwiZ ZDqFUGzm6e7ndA5KFIzUOADYj4+wvh6uhBVGpqFJvZbaCcJHwEOOKIhNxtgJqHLSIvA== 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=GpmApI8L; 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 C5CF1606A330 for ; Sat, 5 Dec 2026 11:08:49 +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=GpmApI8L Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80FAD1F0092B; Sat, 5 Dec 2026 11:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796468929; bh=hEr5WOfQhBDWBCrij9wqagVgjp+PPoLLcFDxDdA3oWs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=GpmApI8LdRQ1LRSsu0w8weN+BVdOkpj0IGo/v6LNnRQvPcSJacGfInQB/7fHB1602 Bfzm1KhX1ywhSbLbjQnN0449etZ8c/v9dtC+SnVfuX/HbNgba4XFCqAzryUGqunAxB MQzmKpZt9FhLETX13jC2ZJOMAhBwUfqC6EfFBmr6GdttnB6sJBTzunSAk6hranAB3R xvt0VTVs9gEkwkPrP/sC+Zh8EQRStpu8txxu+uqZ3yUUke9t9ZEmPTYbLglQZI8lx5 vF7XVuH8G+HSLbXfNmazd7CgzFPb1d1rAkBVsHVn1s+9ComyvJfng7defGwi4k8eKg Q4iefAu1VqWTA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device 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-5-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-1-maxime.chevallier@bootlin.com> <20261204110622.1106492-5-maxime.chevallier@bootlin.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 11:08:49 +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 3 potential issues to consider: - [Medium] net: phy: unsynchronized phy_mux_detach() races with unregister and attach - [Medium] net: phy: phy_mux: phy_mux_attach() clobbers dev->sfp_bus - [Medium] net: phy: phy_mux_detach_phys() omits phy_stop_machine() before phy_detach() -- commit 5ec0ab0887a678472a4f565b6b693b7e69aef8df Author: Maxime Chevallier net: phy: phy_mux: Allow attaching a mux to a net_device This commit adds support for attaching a phy_mux to a net_device and its parent, binding and attaching the PHYs behind the mux and introducing parent_ops attach and detach callbacks. > diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c > index e259eb4e271a0..691bca09e0af1 100644 > --- a/drivers/net/phy/phy_mux.c > +++ b/drivers/net/phy/phy_mux.c [ ... ] > +static void phy_mux_detach_phys(struct phy_mux *mux) > +{ > + struct phy_mux_port *port; > + unsigned long id; > + > + xa_for_each(&mux->ports, id, port) { > + if (!port->attached) > + continue; > + > + phy_detach(port->phydev); > + phy_mux_port_unbind_phy(port); > + port->attached =3D false; > + } > +} [Severity: Medium] Should phy_mux_detach_phys() call phy_stop_machine() before phy_detach()? phy_mux_attach() sets port->phydev->phy_link_change to phy_mux_phy_link_change, which causes phy_uses_state_machine() to return true even for unselected mux PHYs. On MAC drivers without mac_managed_pm (such as mvneta), mdio_bus_phy_resume() then calls phy_start_machine() and queues phydev->state_queue. For non-genphy drivers, phy_detach() does not cancel state_queue. If a deselected PHY is in PHY_HALTED with phydev->suspended still false (for example, with WoL enabled), a queued phy_state_machine() work item can race with detach and netdev teardown: CPU0 CPU1 (kworker) phy_state_machine() _phy_state_machine() /* PHY_HALTED */ mutex_unlock(&phydev->lock) phy_suspend() netdev =3D phydev->attached_dev phy_mux_detach() phy_mux_detach_phys() phy_detach() phydev->attached_dev =3D NULL phy_device_reset(phydev, 1) free_netdev(netdev) netdev->ethtool->wol_enabled <-- use-after-free Even without WoL, a pending phy_suspend() can run after phy_device_reset(phydev, 1) or race with a subsequent re-attach and power down an active PHY. [ ... ] > + ret =3D phy_attach_direct(dev, port->phydev, phy_flags, > + port->interface); > + if (ret) { > + phy_mux_port_unbind_phy(port); > + goto err_detach; > + } > + > + port->phydev->phy_link_change =3D phy_mux_phy_link_change; > + port->attached =3D true; > + has_phys =3D true; > + } > + > + if (has_phys) > + dev->phydev =3D NULL; [Severity: Medium] Can attaching a muxed PHY here clobber dev->sfp_bus? Unlike phy_sysfs_create_links(), phy_attach_direct() unconditionally sets dev->sfp_bus =3D phydev->sfp_bus when phydev->sfp_bus_attached is true, even when phydev->mux_port is set. Because deselected mux PHYs keep phydev->attached_dev set to dev, later phy_sfp_attach() and phy_sfp_detach() calls also overwrite or clear dev->sfp_bus. On a mux where a PHY has a downstream SFP cage, this overwrites any existing dev->sfp_bus (such as an SFP cage on another mux port), causing ethtool -m to query the wrong cage. In addition, phy_detach_internal() clears phydev->attached_dev without clearing dev->sfp_bus, leaving a dangling dev->sfp_bus pointer if the PHY and its SFP socket are later unbound while dev stays registered. [ ... ] > +void phy_mux_detach(struct phy_mux *mux) > +{ > + if (!mux->netdev) > + return; > + > + phy_mux_detach_phys(mux); > + > + if (mux->devlink) { > + device_link_del(mux->devlink); > + mux->devlink =3D NULL; > + } > + > + mux->pops =3D NULL; > + mux->parent_priv =3D NULL; > + mux->netdev =3D NULL; > +} > +EXPORT_SYMBOL_GPL(phy_mux_detach); [ ... ] > void phy_mux_unregister(struct phy_mux *mux) > { > mutex_lock(&phy_mux_mutex); > list_del(&mux->node); > mutex_unlock(&phy_mux_mutex); > + > + rtnl_lock(); > + if (mux->netdev && mux->pops && mux->pops->detach) > + mux->pops->detach(mux, mux->parent_priv); > + rtnl_unlock(); > } [Severity: Medium] Can phy_mux_detach() race with phy_mux_unregister() and phy_mux_free()? phy_mux_attach() adds mux->devlink with DL_FLAG_STATELESS, so unbinding the mux does not unbind the MAC first. phy_mux_unregister() drops phy_mux_mutex and relies on rtnl_lock() to serialize mux->pops->detach() before the mux driver calls phy_mux_free(mux), whereas phy_mux_detach() acquires neither phy_mux_mutex nor rtnl_lock(). When phylink_destroy() calls phy_mux_detach() without RTNL (for instance in mvpp2_port_remove() or ucc_geth_remove() after an open-time failure leaves the mux attached), it can run concurrently with mux removal: CPU0 CPU1 phylink_destroy() /* no RTNL */ phy_mux_unregister() phy_mux_detach(mux) mutex_lock(&phy_mux_mutex) if (!mux->netdev) /* false */ list_del(&mux->node) mutex_unlock(&phy_mux_mutex) rtnl_lock() if (mux->netdev && mux->pops->detach) mux->pops->detach(mux, priv) phy_mux_detach(mux) rtnl_unlock() phy_mux_free(mux) kfree(mux) phy_mux_detach_phys(mux) <-- use-after-free / double detach If CPU0 finishes phy_mux_detach() and frees phylink while CPU1 is past the mux->netdev check, CPU1 can likewise dereference NULL mux->pops or call pops->detach() on freed parent state. Similarly, fwnode_phy_mux_attach() holds only phy_mux_mutex and is called without RTNL by drivers such as dsa_user_create() and ocelot_probe_port(), sharing no common lock with phy_mux_detach(). Calling phy_mux_detach() without RTNL while dev is still registered (as in ucc_geth_remove()) also violates the rcu_dereference_protected() check on dev->hwprov in phy_detach_internal(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204110622.1106= 492-1-maxime.chevallier@bootlin.com?part=3D4