net: phy: Unbind fixes
Subsystems (3)
cover net: phy: Unbind fixes
This patch series fixes a couple of issues with the unbinding of the PHY drivers and then bringing down a network interface. The first is a NULL pointer de-reference and the second was an incorrect warning being triggered.
Florian Fainelli (2):
net: phy: Avoid NPD upon phy_detach() when driver is unbound
net: phy: Do not warn in phy_stop() on PHY_DOWN
drivers/net/phy/phy.c | 2 +- drivers/net/phy/phy_device.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 net: phy: Avoid NPD upon phy_detach() when driver is unbound
If we have unbound the PHY driver prior to calling phy_detach() (often via phy_disconnect()) then we can cause a NULL pointer de-reference accessing the driver owner member. The steps to reproduce are:
echo unimac-mdio-0:01 > /sys/class/net/eth0/phydev/driver/unbind ip link set eth0 down
--- drivers/net/phy/phy_device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/phy_device.c +2 -1
@@ -1682,7 +1682,8 @@ void phy_detach(struct phy_device *phydev)phy_led_triggers_unregister (phydev); -module_put (phydev->mdio.dev.driver->owner); +if (phydev->mdio.dev.driver) +module_put (phydev->mdio.dev.driver->owner);/* If the device had no specific driver before (i.e. - it * was using the generic driver), we unbind the device
Signature · 1 line
2.25.1
Andrew Lunn
maintainerRe: [PATCH net 1/2] net: phy: Avoid NPD upon phy_detach() when driver is unbound
Quoted 6 lines · Florian Fainelli
If we have unbound the PHY driver prior to calling
phy_detach()(often viaphy_disconnect()) then we can cause a NULL pointer de-reference accessing the driver owner member. The steps to reproduce are:echo unimac-mdio-0:01 >
/sys/class/net/eth0/phydev/driver/unbindip link set eth0 down
Hi Florian
How forceful is this unbind? Can we actually block it while the interface is up? Or returning -EBUSY would make sense.
Andrew
Re: [PATCH net 1/2] net: phy: Avoid NPD upon phy_detach() when driver is unbound
Quoted 5 lines · Andrew Lunn
Quoted 4 lines · Florian Fainelli
If we have unbound the PHY driver prior to calling
phy_detach()(often viaphy_disconnect()) then we can cause a NULL pointer de-reference accessing the driver owner member. The steps to reproduce are:
Quoted 7 lines
Quoted 2 lines
echo unimac-mdio-0:01 >
/sys/class/net/eth0/phydev/driver/unbindip link set eth0 downHi Florian
How forceful is this unbind? Can we actually block it while the interface is up? Or returning
-EBUSYwould make sense.
It it not forceful, you can unbind the PHY driver from underneath the net_device and nothing bad happens, really. This is not a very realistic or practical use case, but several years ago, I went into making sure we would not create NPD if that happened.
Signature · 1 line
Florian
Re: [PATCH net 1/2] net: phy: Avoid NPD upon phy_detach() when driver is unbound
In reply to Florian FainelliQuoted 9 lines · Florian Fainelli
If we have unbound the PHY driver prior to calling
phy_detach()(often viaphy_disconnect()) then we can cause a NULL pointer de-reference accessing the driver owner member. The steps to reproduce are:echo unimac-mdio-0:01 >
/sys/class/net/eth0/phydev/driver/unbindip link set eth0 downFixes cafe8df8b9bc ("net: phy: Fix lack of reference count on PHY driver")Signed-off-by Florian Fainelli <[email protected]>
Andrew
PATCH 2/2 net: phy: Do not warn in phy_stop() on PHY_DOWN
In reply to Florian FainelliWhen phy_is_started() was added to catch incorrect PHY states, phy_stop() would not be qualified against PHY_DOWN. It is possible to reach that state when the PHY driver has been unbound and the network device is then brought down.
--- drivers/net/phy/phy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/phy.c +1 -1
@@ -996,7 +996,7 @@ void phy_stop(struct phy_device *phydev) {struct net_device *dev = phydev->attached_dev; -if (!phy_is_started (phydev)) { +if (!phy_is_started (phydev) && phydev->state !=PHY_DOWN ) {WARN (1 ,"called from state %s\n" ,phy_state_to_str (phydev->state));return ;
Signature · 1 line
2.25.1
Re: [PATCH net 2/2] net: phy: Do not warn in phy_stop() on PHY_DOWN
Quoted 7 lines · Florian Fainelli
When
phy_is_started()was added to catch incorrect PHY states,phy_stop()would not be qualified againstPHY_DOWN. It is possible to reach that state when the PHY driver has been unbound and the network device is then brought down.Fixes 2b3e88ea6528 ("net: phy: improve phy state checking")Signed-off-by Florian Fainelli <[email protected]>
Andrew
David Miller
maintainerFrom: Florian Fainelli <[email protected]>
Date: Wed, 16 Sep 2020 20:43:08 -0700
Quoted 4 lines
This patch series fixes a couple of issues with the unbinding of the PHY drivers and then bringing down a network interface. The first is a NULL pointer de-reference and the second was an incorrect warning being triggered.
Series applied and queued up for -stable, thanks.