Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f39027cb authored by Marek Behún's avatar Marek Behún Committed by Greg Kroah-Hartman
Browse files

phylib: fix potential use-after-free



[ Upstream commit cbda1b16687580d5beee38273f6241ae3725960c ]

Commit bafbdd52 ("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: bafbdd52 ("phylib: Add device reset GPIO support")
Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20220119162748.32418-1-kabel@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 218cccb5
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1433,6 +1433,9 @@ void phy_detach(struct phy_device *phydev)
	    phy_driver_is_genphy_10g(phydev))
		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.
@@ -1444,9 +1447,6 @@ void phy_detach(struct phy_device *phydev)
		ndev_owner = dev->dev.parent->driver->owner;
	if (ndev_owner != bus->owner)
		module_put(bus->owner);

	/* Assert the reset signal */
	phy_device_reset(phydev, 1);
}
EXPORT_SYMBOL(phy_detach);