[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ca5b67cd-77f2-b19c-6aee-886e11fbe8bf@gmail.com>
Date: Wed, 8 Feb 2017 16:15:34 -0800
From: Florian Fainelli <f.fainelli@...il.com>
To: netdev@...r.kernel.org
Cc: maowenan <maowenan@...wei.com>, andrew@...n.ch,
rmk+kernel@...linux.org.uk, festevam@...il.com,
davem@...emloft.net, nikita.yoush@...entembedded.com
Subject: Re: [PATCH net v3 1/3] net: phy: Fix PHY module checks and NULL deref
in phy_attach_direct()
On 02/08/2017 04:13 PM, Florian Fainelli wrote:
> The Generic PHY drivers gets assigned after we checked that the current
> PHY driver is NULL, so we need to check a few things before we can
> safely dereference d->driver. This would be causing a NULL deference to
> occur when a system binds to the Generic PHY driver. Update
> phy_attach_direct() to do the following:
>
> - grab the driver module reference after we have assigned the Generic
> PHY drivers accordingly
>
> - update the error path to clean up the module reference in case the
> Generic PHY probe function fails
>
> Fixes: cafe8df8b9bc ("net: phy: Fix lack of reference count on PHY driver")
> Signed-off-by: Florian Fainelli <f.fainelli@...il.com>
> ---
> drivers/net/phy/phy_device.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 0d8f4d3847f6..d63d190a95ef 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -908,6 +908,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
> struct module *ndev_owner = dev->dev.parent->driver->owner;
> struct mii_bus *bus = phydev->mdio.bus;
> struct device *d = &phydev->mdio.dev;
> + bool using_genphy = false;
> int err;
>
> /* For Ethernet device drivers that register their own MDIO bus, we
> @@ -938,12 +939,22 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
> d->driver =
> &genphy_driver[GENPHY_DRV_1G].mdiodrv.driver;
>
> + using_genphy = true;
> + }
> +
> + if (!try_module_get(d->driver->owner)) {
> + dev_err(&dev->dev, "failed to get the device driver module\n");
> + err = -EIO;
> + goto error_put_device;
> + }
And still not correct, since we need to remove the other hunk, one day I
will learn how to properly rebase my work... will submit a v4 shortly.
--
Florian
Powered by blists - more mailing lists