Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Russell King (Oracle) and committed by
Jakub Kicinski
19e6ad2c 1eea11e9

+2 -2
+2 -2
drivers/net/phy/phy_device.c
··· 1980 1980 const struct phy_driver *phydrv = phydev->drv; 1981 1981 int ret; 1982 1982 1983 - if (phydev->suspended) 1983 + if (phydev->suspended || !phydrv) 1984 1984 return 0; 1985 1985 1986 1986 phy_ethtool_get_wol(phydev, &wol); ··· 1990 1990 if (phydev->wol_enabled && !(phydrv->flags & PHY_ALWAYS_CALL_SUSPEND)) 1991 1991 return -EBUSY; 1992 1992 1993 - if (!phydrv || !phydrv->suspend) 1993 + if (!phydrv->suspend) 1994 1994 return 0; 1995 1995 1996 1996 ret = phydrv->suspend(phydev);