summaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorMarek BehĂșn <kabel@kernel.org>2022-01-19 17:27:48 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-02-08 18:23:10 +0100
commit67d271760b037ce0806d687ee6057edc8afd4205 (patch)
tree3cf7b465ec8875406bd8b8b7592433ecde548384 /drivers/net
parent8b5c9de150c62f686ff274039b97fe3a2297ada6 (diff)
downloadlinux-stable-67d271760b037ce0806d687ee6057edc8afd4205.tar.gz
linux-stable-67d271760b037ce0806d687ee6057edc8afd4205.tar.bz2
linux-stable-67d271760b037ce0806d687ee6057edc8afd4205.zip
phylib: fix potential use-after-free
[ Upstream commit cbda1b16687580d5beee38273f6241ae3725960c ] Commit bafbdd527d56 ("phylib: Add device reset GPIO support") added call to phy_device_reset(phydev) after the put_device() call in phy_detach(). The comment before the put_device() call says that the phydev might go away with put_device(). Fix potential use-after-free by calling phy_device_reset() before put_device(). Fixes: bafbdd527d56 ("phylib: Add device reset GPIO support") Signed-off-by: Marek BehĂșn <kabel@kernel.org> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Link: https://lore.kernel.org/r/20220119162748.32418-1-kabel@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/phy/phy_device.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index b884b681d5c5..a03d0627efb0 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1166,6 +1166,9 @@ void phy_detach(struct phy_device *phydev)
phydev->mdio.dev.driver == &genphy_driver.mdiodrv.driver)
device_release_driver(&phydev->mdio.dev);
+ /* Assert the reset signal */
+ phy_device_reset(phydev, 1);
+
/*
* The phydev might go away on the put_device() below, so avoid
* a use-after-free bug by reading the underlying bus first.
@@ -1175,9 +1178,6 @@ void phy_detach(struct phy_device *phydev)
put_device(&phydev->mdio.dev);
if (ndev_owner != bus->owner)
module_put(bus->owner);
-
- /* Assert the reset signal */
- phy_device_reset(phydev, 1);
}
EXPORT_SYMBOL(phy_detach);