All of lore.kernel.org
 help / color / mirror / Atom feed
* request for 4.4-stable: d733f7542ad4 ("drivers: net: cpsw: fix segfault in case of bad phy-handle")
@ 2018-09-14 15:24 SZ Lin (林上智)
  2018-09-17 11:29 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: SZ Lin (林上智) @ 2018-09-14 15:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: stable

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

Hi Greg,

This patch is not marked for 4.4-stable, but it's already in 4.9 and 4.14 stable.

Please apply to 4.4-stable.

This patch adds error handling to avoid segfault situation, I've tweaked
patch to use original print function of dev_info() instead of phy_attached_info()
which is in commit 2220943a21e26d97d7fd8f83c004b947326b469d upstream.
-- 
SZ Lin (林上智)

[-- Attachment #2: 0001-drivers-net-cpsw-fix-segfault-in-case-of-bad-phy-han.patch --]
[-- Type: text/x-diff, Size: 3120 bytes --]

>From 194f912f0303146bffe8a1fd0d0c8a5b9208752c Mon Sep 17 00:00:00 2001
From: David Rivshin <drivshin@allworx.com>
Date: Wed, 27 Apr 2016 21:32:31 -0400
Subject: [PATCH] drivers: net: cpsw: fix segfault in case of bad phy-handle

commit d733f7542ad47cf73e033c90cf55158587e1d060 upstream

If an emac node has a phy-handle property that points to something
which is not a phy, then a segmentation fault will occur when the
interface is brought up. This is because while phy_connect() will
return ERR_PTR() on failure, of_phy_connect() will return NULL.
The common error check uses IS_ERR(), and so missed when
of_phy_connect() fails. The NULL pointer is then dereferenced.

Also, the common error message referenced slave->data->phy_id,
which would be empty in the case of phy-handle. Instead, use the
name of the device_node as a useful identifier. And in the phy_id
case add the error code for completeness.

Fixes: 9e42f715264f ("drivers: net: cpsw: add phy-handle parsing")
Signed-off-by: David Rivshin <drivshin@allworx.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[SZ Lin (林上智): Tweak the patch to use original print function of dev_info()]
Signed-off-by: SZ Lin (林上智) <sz.lin@moxa.com>
---
 drivers/net/ethernet/ti/cpsw.c | 38 +++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index c21c80a228d9..c1a4425b54e7 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -1164,25 +1164,35 @@ static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
 		cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
 				   1 << slave_port, 0, 0, ALE_MCAST_FWD_2);
 
-	if (slave->data->phy_node)
+	if (slave->data->phy_node) {
 		slave->phy = of_phy_connect(priv->ndev, slave->data->phy_node,
 				 &cpsw_adjust_link, 0, slave->data->phy_if);
-	else
+		if (!slave->phy) {
+			dev_err(priv->dev, "phy \"%s\" not found on slave %d\n",
+				slave->data->phy_node->full_name,
+				slave->slave_num);
+			return;
+		}
+	} else {
 		slave->phy = phy_connect(priv->ndev, slave->data->phy_id,
 				 &cpsw_adjust_link, slave->data->phy_if);
-	if (IS_ERR(slave->phy)) {
-		dev_err(priv->dev, "phy %s not found on slave %d\n",
-			slave->data->phy_id, slave->slave_num);
-		slave->phy = NULL;
-	} else {
-		dev_info(priv->dev, "phy found : id is : 0x%x\n",
-			 slave->phy->phy_id);
-		phy_start(slave->phy);
-
-		/* Configure GMII_SEL register */
-		cpsw_phy_sel(&priv->pdev->dev, slave->phy->interface,
-			     slave->slave_num);
+		if (IS_ERR(slave->phy)) {
+			dev_err(priv->dev,
+				"phy \"%s\" not found on slave %d, err %ld\n",
+				slave->data->phy_id, slave->slave_num,
+				PTR_ERR(slave->phy));
+			slave->phy = NULL;
+			return;
+		}
 	}
+
+	dev_info(priv->dev, "phy found : id is : 0x%x\n",
+		 slave->phy->phy_id);
+
+	phy_start(slave->phy);
+
+	/* Configure GMII_SEL register */
+	cpsw_phy_sel(&priv->pdev->dev, slave->phy->interface, slave->slave_num);
 }
 
 static inline void cpsw_add_default_vlan(struct cpsw_priv *priv)
-- 
2.19.0


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

* Re: request for 4.4-stable: d733f7542ad4 ("drivers: net: cpsw: fix segfault in case of bad phy-handle")
  2018-09-14 15:24 request for 4.4-stable: d733f7542ad4 ("drivers: net: cpsw: fix segfault in case of bad phy-handle") SZ Lin (林上智)
@ 2018-09-17 11:29 ` Greg Kroah-Hartman
  2018-09-20  9:46   ` SZ Lin (林上智)
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2018-09-17 11:29 UTC (permalink / raw)
  To: SZ Lin (林上智); +Cc: stable

On Fri, Sep 14, 2018 at 11:24:42PM +0800, SZ Lin (林上智) wrote:
> Hi Greg,
> 
> This patch is not marked for 4.4-stable, but it's already in 4.9 and 4.14 stable.
> 
> Please apply to 4.4-stable.
> 
> This patch adds error handling to avoid segfault situation, I've tweaked
> patch to use original print function of dev_info() instead of phy_attached_info()
> which is in commit 2220943a21e26d97d7fd8f83c004b947326b469d upstream.

This patch does not apply against the latest 4.4.y tree.  Can you please
rebase/refresh it and resend?

thanks,

greg k-h

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

* Re: request for 4.4-stable: d733f7542ad4 ("drivers: net: cpsw: fix segfault in case of bad phy-handle")
  2018-09-17 11:29 ` Greg Kroah-Hartman
@ 2018-09-20  9:46   ` SZ Lin (林上智)
  2018-09-24 10:56     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: SZ Lin (林上智) @ 2018-09-20  9:46 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: stable

[-- Attachment #1: Type: text/plain, Size: 770 bytes --]

Hi Greg,

On Mon, Sep 17, 2018 at 01:29:11PM +0200, Greg Kroah-Hartman wrote:
> On Fri, Sep 14, 2018 at 11:24:42PM +0800, SZ Lin (林上智) wrote:
> > Hi Greg,
> > 
> > This patch is not marked for 4.4-stable, but it's already in 4.9 and 4.14 stable.
> > 
> > Please apply to 4.4-stable.
> > 
> > This patch adds error handling to avoid segfault situation, I've tweaked
> > patch to use original print function of dev_info() instead of phy_attached_info()
> > which is in commit 2220943a21e26d97d7fd8f83c004b947326b469d upstream.
> 
> This patch does not apply against the latest 4.4.y tree.  Can you please
> rebase/refresh it and resend?

I've rebased the attached patch based on 4.4.157, please apply it.

Thanks.

> 
> thanks,
> 
> greg k-h

-- 
SZ Lin (林上智)

[-- Attachment #2: 0001-drivers-net-cpsw-fix-segfault-in-case-of-bad-phy-han.patch --]
[-- Type: text/x-diff, Size: 3116 bytes --]

>From 76aa771afa9068449b4c1974bcb63e188d6bc180 Mon Sep 17 00:00:00 2001
From: David Rivshin <drivshin@allworx.com>
Date: Wed, 27 Apr 2016 21:32:31 -0400
Subject: [PATCH] drivers: net: cpsw: fix segfault in case of bad phy-handle

commit d733f7542ad47cf73e033c90cf55158587e1d060 upstream

If an emac node has a phy-handle property that points to something
which is not a phy, then a segmentation fault will occur when the
interface is brought up. This is because while phy_connect() will
return ERR_PTR() on failure, of_phy_connect() will return NULL.
The common error check uses IS_ERR(), and so missed when
of_phy_connect() fails. The NULL pointer is then dereferenced.

Also, the common error message referenced slave->data->phy_id,
which would be empty in the case of phy-handle. Instead, use the
name of the device_node as a useful identifier. And in the phy_id
case add the error code for completeness.

Fixes: 9e42f715264f ("drivers: net: cpsw: add phy-handle parsing")
Signed-off-by: David Rivshin <drivshin@allworx.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[SZ Lin (林上智): Tweak the patch to use original print function of dev_info()]
Signed-off-by: SZ Lin (林上智) <sz.lin@moxa.com>
---
 drivers/net/ethernet/ti/cpsw.c | 37 +++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index c2e110b2549b..c1217a87d535 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -1164,25 +1164,34 @@ static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
 		cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
 				   1 << slave_port, 0, 0, ALE_MCAST_FWD_2);
 
-	if (slave->data->phy_node)
+	if (slave->data->phy_node) {
 		slave->phy = of_phy_connect(priv->ndev, slave->data->phy_node,
 				 &cpsw_adjust_link, 0, slave->data->phy_if);
-	else
+		if (!slave->phy) {
+			dev_err(priv->dev, "phy \"%s\" not found on slave %d\n",
+				slave->data->phy_node->full_name,
+				slave->slave_num);
+			return;
+		}
+	} else {
 		slave->phy = phy_connect(priv->ndev, slave->data->phy_id,
 				 &cpsw_adjust_link, slave->data->phy_if);
-	if (IS_ERR(slave->phy)) {
-		dev_err(priv->dev, "phy %s not found on slave %d\n",
-			slave->data->phy_id, slave->slave_num);
-		slave->phy = NULL;
-	} else {
-		dev_info(priv->dev, "phy found : id is : 0x%x\n",
-			 slave->phy->phy_id);
-		phy_start(slave->phy);
-
-		/* Configure GMII_SEL register */
-		cpsw_phy_sel(&priv->pdev->dev, slave->phy->interface,
-			     slave->slave_num);
+		if (IS_ERR(slave->phy)) {
+			dev_err(priv->dev,
+				"phy \"%s\" not found on slave %d, err %ld\n",
+				slave->data->phy_id, slave->slave_num,
+				PTR_ERR(slave->phy));
+			slave->phy = NULL;
+			return;
+		}
 	}
+
+	dev_info(priv->dev, "phy found : id is : 0x%x\n", slave->phy->phy_id);
+
+	phy_start(slave->phy);
+
+	/* Configure GMII_SEL register */
+	cpsw_phy_sel(&priv->pdev->dev, slave->phy->interface, slave->slave_num);
 }
 
 static inline void cpsw_add_default_vlan(struct cpsw_priv *priv)
-- 
2.19.0


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

* Re: request for 4.4-stable: d733f7542ad4 ("drivers: net: cpsw: fix segfault in case of bad phy-handle")
  2018-09-20  9:46   ` SZ Lin (林上智)
@ 2018-09-24 10:56     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2018-09-24 10:56 UTC (permalink / raw)
  To: SZ Lin (林上智); +Cc: stable

On Thu, Sep 20, 2018 at 05:46:31PM +0800, SZ Lin (林上智) wrote:
> Hi Greg,
> 
> On Mon, Sep 17, 2018 at 01:29:11PM +0200, Greg Kroah-Hartman wrote:
> > On Fri, Sep 14, 2018 at 11:24:42PM +0800, SZ Lin (林上智) wrote:
> > > Hi Greg,
> > > 
> > > This patch is not marked for 4.4-stable, but it's already in 4.9 and 4.14 stable.
> > > 
> > > Please apply to 4.4-stable.
> > > 
> > > This patch adds error handling to avoid segfault situation, I've tweaked
> > > patch to use original print function of dev_info() instead of phy_attached_info()
> > > which is in commit 2220943a21e26d97d7fd8f83c004b947326b469d upstream.
> > 
> > This patch does not apply against the latest 4.4.y tree.  Can you please
> > rebase/refresh it and resend?
> 
> I've rebased the attached patch based on 4.4.157, please apply it.

Thanks, that worked!

greg k-h

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

end of thread, other threads:[~2018-09-24 16:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-14 15:24 request for 4.4-stable: d733f7542ad4 ("drivers: net: cpsw: fix segfault in case of bad phy-handle") SZ Lin (林上智)
2018-09-17 11:29 ` Greg Kroah-Hartman
2018-09-20  9:46   ` SZ Lin (林上智)
2018-09-24 10:56     ` Greg Kroah-Hartman

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.