]> www.infradead.org Git - users/jedix/linux-maple.git/commit
net: phy: fix potential use of NULL pointer in phy_suspend()
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Fri, 28 Jun 2024 10:32:11 +0000 (11:32 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 2 Jul 2024 03:14:13 +0000 (20:14 -0700)
commit19e6ad2c75782bd15b3df24df7982da457d702c5
tree3fba92eb2a8951a1f7f657f108288866e5edfc3d
parent1eea11e937db67b5417934974e825c7101324b23
net: phy: fix potential use of NULL pointer in phy_suspend()

phy_suspend() checks the WoL status, and then dereferences
phydrv->flags if (and only if) we decided that WoL has been enabled
on either the PHY or the netdev.

We then check whether phydrv was NULL, but we've potentially already
dereferenced the pointer.

If phydrv is NULL, then phy_ethtool_get_wol() will return an error
and leave wol.wolopts set to zero. However, if netdev->wol_enabled
is true, then we would dereference a NULL pointer.

Checking the PHY drivers, the only place that phydev->wol_enabled is
checked by them is in their suspend/resume callbacks and nowhere else
(which is correct, because phylib only updates this in phy_suspend()).

So, move the NULL pointer check earlier to avoid a NULL pointer
dereference. Leave the check for phydrv->suspend in place as a driver
may populate the .resume method but not the .suspend method.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/E1sN8tn-00GDCZ-Jj@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/phy_device.c