]> git.itanic.dy.fi Git - linux-stable/commit
net: phy: prevent stale pointer dereference in phy_init()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Thu, 20 Jul 2023 00:02:31 +0000 (03:02 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jul 2023 06:44:43 +0000 (08:44 +0200)
commite3da59f428200bf109fda878e95d1023647a5bd7
treef9791b54bbae27edd0d3dd4b192e41b62faa6320
parente0ac63e194f49a5b5e7b79b8017635b3c49f1994
net: phy: prevent stale pointer dereference in phy_init()

[ Upstream commit 1c613beaf877c0c0d755853dc62687e2013e55c4 ]

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: 55d8f053ce1b ("net: phy: Register ethtool PHY operations")
Link: https://lore.kernel.org/netdev/ZLaiJ4G6TaJYGJyU@shell.armlinux.org.uk/
Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20230720000231.1939689-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/phy/phy_device.c