netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] phy: fix null pointer issue in phy_attach_direct()
@ 2025-01-29 18:36 sreedevi.joshi
  2025-01-29 19:14 ` Andrew Lunn
  2025-01-29 19:29 ` Russell King (Oracle)
  0 siblings, 2 replies; 7+ messages in thread
From: sreedevi.joshi @ 2025-01-29 18:36 UTC (permalink / raw)
  To: andrew, hkallweit1; +Cc: linux, edumazet, kuba, pabeni, netdev, Sreedevi Joshi

From: Sreedevi Joshi <sreedevi.joshi@intel.com>

When attaching a fixed phy to devices like veth, it is
possible that there is no parent. The logic in
phy_attach_direct() tries to access the driver member
without checking for the null. This causes segfault in the
case of fixed phy.

Checks are in place now to ensure the parent is not null
before accessing to address this scenario.

Fixes: 2db2d9d1ac37 ("net: phy: Guard against the presence of a netdev")
Signed-off-by: Sreedevi Joshi <sreedevi.joshi@intel.com>
---
 drivers/net/phy/phy_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 46713d27412b..be813962cb89 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1471,7 +1471,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 	 * our own module->refcnt here, otherwise we would not be able to
 	 * unload later on.
 	 */
-	if (dev)
+	if (dev && dev->dev.parent)
 		ndev_owner = dev->dev.parent->driver->owner;
 	if (ndev_owner != bus->owner && !try_module_get(bus->owner)) {
 		phydev_err(phydev, "failed to get the bus module\n");
-- 
2.25.1


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

end of thread, other threads:[~2025-01-31 14:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-29 18:36 [PATCH net] phy: fix null pointer issue in phy_attach_direct() sreedevi.joshi
2025-01-29 19:14 ` Andrew Lunn
2025-01-30 19:10   ` Joshi, Sreedevi
2025-01-30 19:52     ` Andrew Lunn
2025-01-31 14:57       ` Joshi, Sreedevi
2025-01-29 19:29 ` Russell King (Oracle)
2025-01-30 19:18   ` Joshi, Sreedevi

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).