Skip to content

Commit b9f0f20

Browse files
vladimirolteangregkh
authored andcommitted
net: phy: prevent stale pointer dereference in phy_init()
[ Upstream commit 1c613be ] mdio_bus_init() and phy_driver_register() both have error paths, and if those are ever hit, ethtool will have a stale pointer to the phy_ethtool_phy_ops stub structure, which references memory from a module that failed to load (phylib). It is probably hard to force an error in this code path even manually, but the error teardown path of phy_init() should be the same as phy_exit(), which is now simply not the case. Fixes: 55d8f05 ("net: phy: Register ethtool PHY operations") Link: https://lore.kernel.org/netdev/[email protected]/ Suggested-by: Russell King (Oracle) <[email protected]> Signed-off-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent f311c76 commit b9f0f20

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

drivers/net/phy/phy_device.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,23 +3252,30 @@ static int __init phy_init(void)
32523252
{
32533253
int rc;
32543254

3255+
ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops);
3256+
32553257
rc = mdio_bus_init();
32563258
if (rc)
3257-
return rc;
3259+
goto err_ethtool_phy_ops;
32583260

3259-
ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops);
32603261
features_init();
32613262

32623263
rc = phy_driver_register(&genphy_c45_driver, THIS_MODULE);
32633264
if (rc)
3264-
goto err_c45;
3265+
goto err_mdio_bus;
32653266

32663267
rc = phy_driver_register(&genphy_driver, THIS_MODULE);
3267-
if (rc) {
3268-
phy_driver_unregister(&genphy_c45_driver);
3268+
if (rc)
3269+
goto err_c45;
3270+
3271+
return 0;
3272+
32693273
err_c45:
3270-
mdio_bus_exit();
3271-
}
3274+
phy_driver_unregister(&genphy_c45_driver);
3275+
err_mdio_bus:
3276+
mdio_bus_exit();
3277+
err_ethtool_phy_ops:
3278+
ethtool_set_ethtool_phy_ops(NULL);
32723279

32733280
return rc;
32743281
}

0 commit comments

Comments
 (0)