netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] net: phy: allow phy_detach() before netdev registration
@ 2026-09-18  2:23 Chenguang Zhao
  2026-09-18  2:35 ` Andrew Lunn
  0 siblings, 1 reply; 2+ messages in thread
From: Chenguang Zhao @ 2026-09-18  2:23 UTC (permalink / raw)
  To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni
  Cc: netdev, chenguang.zhao, Chenguang Zhao,
	syzbot+694b49f41098a5df4fd7

From: Chenguang Zhao <zhaochenguang@kylinos.cn>

phylink_connect_phy() may be called from probe without RTNL while the
net_device is still NETREG_UNINITIALIZED. If phylink_bringup_phy()
fails, phy_detach() uses rtnl_dereference(dev->hwprov) and lockdep
reports suspicious RCU usage.

hwprov cannot have been assigned before register_netdevice(). Relax the
RCU check for that state only; registered devices still require RTNL.

Fixes: 35f7cad1743e ("net: Add the possibility to support a selected hwtstamp in netdevice")
Reported-by: syzbot+694b49f41098a5df4fd7@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=694b49f41098a5df4fd7

Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
---
v2:
 phy_attach() does not set dev->hwprov. It is only written by ethtool
 TSCONFIG after register_netdevice(). when calling phy_detach(), we
 need to check whether hwprov is NULL to clean up dangling pointers.

 This patch uses `NETREG_UNINITIALIZED` as a flag. When PHY registration
 fails, TSCONFIG remains unset; hence `dev->hwprov` should not be accessed.

v1:
 https://lore.kernel.org/all/20260916021505.238990-1-chenguang.zhao@linux.dev/

 drivers/net/phy/phy_device.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 94b2e85e00a3..a3a7d5c75970 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1941,11 +1941,13 @@ void phy_detach(struct phy_device *phydev)
 		/* hwprov may technically be protected by ops lock but
 		 * not for devices with a phydev, see phy_link_topo_add_phy()
 		 */
-		hwprov = rtnl_dereference(dev->hwprov);
-		/* Disable timestamp if it is the one selected */
-		if (hwprov && hwprov->phydev == phydev) {
-			rcu_assign_pointer(dev->hwprov, NULL);
-			kfree_rcu(hwprov, rcu_head);
+		if (dev->reg_state != NETREG_UNINITIALIZED) {
+			hwprov = rtnl_dereference(dev->hwprov);
+			/* Disable timestamp if it is the one selected */
+			if (hwprov && hwprov->phydev == phydev) {
+				rcu_assign_pointer(dev->hwprov, NULL);
+				kfree_rcu(hwprov, rcu_head);
+			}
 		}
 
 		phydev->attached_dev->phydev = NULL;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net v2] net: phy: allow phy_detach() before netdev registration
  2026-09-18  2:23 [PATCH net v2] net: phy: allow phy_detach() before netdev registration Chenguang Zhao
@ 2026-09-18  2:35 ` Andrew Lunn
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2026-09-18  2:35 UTC (permalink / raw)
  To: Chenguang Zhao
  Cc: hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev,
	Chenguang Zhao, syzbot+694b49f41098a5df4fd7

>  phy_attach() does not set dev->hwprov. It is only written by ethtool
>  TSCONFIG after register_netdevice().

Please could you point me at this code.

       Andrew

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-18  2:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-18  2:23 [PATCH net v2] net: phy: allow phy_detach() before netdev registration Chenguang Zhao
2026-09-18  2:35 ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).