All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: phy: guard against accessing a NULL features bitmap
@ 2019-01-11 11:56 Camelia Groza
  2019-01-11 13:37 ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Camelia Groza @ 2019-01-11 11:56 UTC (permalink / raw)
  To: andrew, f.fainelli, hkallweit1, davem, oss
  Cc: netdev, linux-kernel, Camelia Groza

Since phy driver features became a link_mode bitmap, phy drivers that
don't have a list of features configured will cause the kernel to crash
when probed.

Fixes: 719655a14971 ("net: phy: Replace phy driver features u32 with link_mode bitmap")
Reported-by: Scott Wood <oss@buserror.net>
Signed-off-by: Camelia Groza <camelia.groza@nxp.com>
---
I'll submit a modified version of this patch to 4.20 stable once this
one is accepted.
---
 drivers/net/phy/phy_device.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 5199000..ddf04ab 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2154,7 +2154,8 @@ static int phy_probe(struct device *dev)
 	 * a controller will attach, and may modify one
 	 * or both of these values
 	 */
-	linkmode_copy(phydev->supported, phydrv->features);
+	if (phydrv->features)
+		linkmode_copy(phydev->supported, phydrv->features);
 	of_set_phy_supported(phydev);
 	linkmode_copy(phydev->advertising, phydev->supported);
 
@@ -2174,8 +2175,9 @@ static int phy_probe(struct device *dev)
 	 * (e.g. hardware erratum) where the driver wants to set only one
 	 * of these bits.
 	 */
-	if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features) ||
-	    test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydrv->features)) {
+	if (phydrv->features &&
+	    (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features) ||
+	     test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydrv->features))) {
 		linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT,
 				   phydev->supported);
 		linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: phy: guard against accessing a NULL features bitmap
  2019-01-11 11:56 [PATCH net] net: phy: guard against accessing a NULL features bitmap Camelia Groza
@ 2019-01-11 13:37 ` Andrew Lunn
  2019-01-11 14:09   ` Camelia Alexandra Groza
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2019-01-11 13:37 UTC (permalink / raw)
  To: Camelia Groza; +Cc: f.fainelli, hkallweit1, davem, oss, netdev, linux-kernel

On Fri, Jan 11, 2019 at 01:56:46PM +0200, Camelia Groza wrote:
> Since phy driver features became a link_mode bitmap, phy drivers that
> don't have a list of features configured will cause the kernel to crash
> when probed.

Hi Camelia

A NULL features is a driver bug. So i would prefer to solve this
differently.

Please make phy_driver_register() do a WARN_ON(!new_driver->features)
and return -EINVAL.

Do you know of a specific driver which as a NULL value? We should fix
that as well.

Thank
	Andrew

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH net] net: phy: guard against accessing a NULL features bitmap
  2019-01-11 13:37 ` Andrew Lunn
@ 2019-01-11 14:09   ` Camelia Alexandra Groza
  2019-01-11 14:19     ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Camelia Alexandra Groza @ 2019-01-11 14:09 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: f.fainelli, hkallweit1, davem, oss, netdev, linux-kernel

> -----Original Message-----
> From: Andrew Lunn <andrew@lunn.ch>
> Sent: Friday, January 11, 2019 15:38
> To: Camelia Alexandra Groza <camelia.groza@nxp.com>
> Cc: f.fainelli@gmail.com; hkallweit1@gmail.com; davem@davemloft.net;
> oss@buserror.net; netdev@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH net] net: phy: guard against accessing a NULL features
> bitmap
> 
> On Fri, Jan 11, 2019 at 01:56:46PM +0200, Camelia Groza wrote:
> > Since phy driver features became a link_mode bitmap, phy drivers that
> > don't have a list of features configured will cause the kernel to crash
> > when probed.
> 
> Hi Camelia
> 
> A NULL features is a driver bug. So i would prefer to solve this
> differently.
>
> Please make phy_driver_register() do a WARN_ON(!new_driver->features)
> and return -EINVAL.

I wasn't aware that features are mandatory. I'll make the change.

> Do you know of a specific driver which as a NULL value? We should fix
> that as well.

Yes, there are five drivers that don't have features configured: BCM8706, BCM8727, CS4340, TN2020 and KSZ8873MLL.

I'm planning to send patches on net-next for the Cortina and Teranetics ones at least, but fixing the generic crash was my priority.

Thanks,
Camelia

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: phy: guard against accessing a NULL features bitmap
  2019-01-11 14:09   ` Camelia Alexandra Groza
@ 2019-01-11 14:19     ` Andrew Lunn
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2019-01-11 14:19 UTC (permalink / raw)
  To: Camelia Alexandra Groza
  Cc: f.fainelli, hkallweit1, davem, oss, netdev, linux-kernel

> > Hi Camelia
> > 
> > A NULL features is a driver bug. So i would prefer to solve this
> > differently.
> >
> > Please make phy_driver_register() do a WARN_ON(!new_driver->features)
> > and return -EINVAL.
> 
> I wasn't aware that features are mandatory. I'll make the change.

It was not origionally, but really it should be now.

> Yes, there are five drivers that don't have features configured: BCM8706, BCM8727, CS4340, TN2020 and KSZ8873MLL.

> I'm planning to send patches on net-next for the Cortina and
> Teranetics ones at least, but fixing the generic crash was my
> priority.

O.K, will take the others.

Thanks
	Andrew

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-11 14:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 11:56 [PATCH net] net: phy: guard against accessing a NULL features bitmap Camelia Groza
2019-01-11 13:37 ` Andrew Lunn
2019-01-11 14:09   ` Camelia Alexandra Groza
2019-01-11 14:19     ` Andrew Lunn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.