Skip to contentSkip to conversation

net: phy: Handle postive return codes in phy_connect

PATCH In review Michael Welling 3 participants 8 messages Sep 5, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: phy: Handle postive return codes in phy_connect

The function phy_connect_direct can possibly return a positive return code. Using ERR_PTR with a positive value can lead to deferencing of an invalid pointer.

---
 drivers/net/phy/phy_device.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/phy/phy_device.c +3 -0
index c0f2111..a7e14a6 100644
@@ -477,6 +477,9 @@ struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
 	phydev = to_phy_device(d);
 
 	rc = phy_connect_direct(dev, phydev, handler, interface);
+	if (rc > 0)
+		return ERR_PTR(-ENODEV);
+
 	if (rc)
 		return ERR_PTR(rc);
 
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 3 lines · Michael Welling

The function phy_connect_direct can possibly return a positive return code. Using ERR_PTR with a positive value can lead to deferencing of an invalid pointer.

Is this the correct fix? Would it not be better to find where the positive return code is from and fix that?

Andrew

Quoted 26 lines
---
 drivers/net/phy/phy_device.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/phy/phy_device.c +3 -0
index c0f2111..a7e14a6 100644
@@ -477,6 +477,9 @@ struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
 	phydev = to_phy_device(d);
 
 	rc = phy_connect_direct(dev, phydev, handler, interface);
+	if (rc > 0)
+		return ERR_PTR(-ENODEV);
+
 	if (rc)
 		return ERR_PTR(rc);
 
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 7 lines · Andrew Lunn
Quoted 3 lines · Michael Welling

The function phy_connect_direct can possibly return a positive return code. Using ERR_PTR with a positive value can lead to deferencing of an invalid pointer.

Is this the correct fix? Would it not be better to find where the positive return code is from and fix that?

I guess I can trace it back to find out where the positive return code is originating.

Is phy_connect_direct always supposed to return valid -errno?

Quoted 29 lines

Andrew

Quoted 26 lines
---
 drivers/net/phy/phy_device.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/phy/phy_device.c +3 -0
index c0f2111..a7e14a6 100644
@@ -477,6 +477,9 @@ struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
 	phydev = to_phy_device(d);
 
 	rc = phy_connect_direct(dev, phydev, handler, interface);
+	if (rc > 0)
+		return ERR_PTR(-ENODEV);
+
 	if (rc)
 		return ERR_PTR(rc);
 
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#3 lore raw
Quoted 6 lines · Michael Welling
Quoted 5 lines · Andrew Lunn
Quoted 3 lines · Michael Welling

The function phy_connect_direct can possibly return a positive return code. Using ERR_PTR with a positive value can lead to deferencing of an invalid pointer.

Quoted 7 lines
Quoted 2 lines

Is this the correct fix? Would it not be better to find where the positive return code is from and fix that?

I guess I can trace it back to find out where the positive return code is originating.

Is phy_connect_direct always supposed to return valid -errno?

I would look at this from a different angle. A positive ERRNO is probably a bug of some sort. So rather than papering over the cracks, go find what the real issue is.

It might not be an ERRNO. E.g. https://lkml.org/lkml/2015/9/3/534
fixed a bug where a positive value is returned which is not an indication of an error.

Andrew

#4 lore raw
Quoted 10 lines · Andrew Lunn
Quoted 9 lines · Michael Welling
Quoted 7 lines · Andrew Lunn
Quoted 3 lines · Michael Welling

The function phy_connect_direct can possibly return a positive return code. Using ERR_PTR with a positive value can lead to deferencing of an invalid pointer.

Is this the correct fix? Would it not be better to find where the positive return code is from and fix that?

Quoted 8 lines
Quoted 4 lines

I guess I can trace it back to find out where the positive return code is originating.

Is phy_connect_direct always supposed to return valid -errno?

I would look at this from a different angle. A positive ERRNO is probably a bug of some sort. So rather than papering over the cracks, go find what the real issue is.

Agreed, you could place a WARN_ON(rc > 0) and get the offending call trace leading to that problem. I suspect that one of the PHY drivers might be returning a positive value as part of a phy_read() call and that does not get properly filtered out.

Quoted 7 lines

It might not be an ERRNO. E.g. https://lkml.org/lkml/2015/9/3/534
fixed a bug where a positive value is returned which is not an indication of an error.

Andrew

Signature · 1 line
Florian
#6 lore raw
In reply to Andrew Lunn
Quoted 15 lines · Andrew Lunn
Quoted 6 lines · Michael Welling
Quoted 5 lines · Andrew Lunn
Quoted 3 lines · Michael Welling

The function phy_connect_direct can possibly return a positive return code. Using ERR_PTR with a positive value can lead to deferencing of an invalid pointer.

Quoted 7 lines
Quoted 2 lines

Is this the correct fix? Would it not be better to find where the positive return code is from and fix that?

I guess I can trace it back to find out where the positive return code is originating.

Is phy_connect_direct always supposed to return valid -errno?

Quoted 7 lines

I would look at this from a different angle. A positive ERRNO is probably a bug of some sort. So rather than papering over the cracks, go find what the real issue is.

It might not be an ERRNO. E.g. https://lkml.org/lkml/2015/9/3/534
fixed a bug where a positive value is returned which is not an indication of an error.

It appears that I have stumbled upon the exact same issue as is fixed in the patch above.

Good catch.

Quoted 2 lines

Andrew

maintainer
#7 lore raw
Quoted 6 lines
Quoted 3 lines

It might not be an ERRNO. E.g. https://lkml.org/lkml/2015/9/3/534
fixed a bug where a positive value is returned which is not an indication of an error.

It appears that I have stumbled upon the exact same issue as is fixed in the patch above.

Ah, sorry. I put that bug there :-(

The fix should be making its way into the kernel soon.

Andrew

#5 lore raw
In reply to Florian Fainelli
Quoted 16 lines · Florian Fainelli
Quoted 15 lines · Andrew Lunn
Quoted 13 lines · Michael Welling
Quoted 7 lines · Andrew Lunn
Quoted 3 lines · Michael Welling

The function phy_connect_direct can possibly return a positive return code. Using ERR_PTR with a positive value can lead to deferencing of an invalid pointer.

Is this the correct fix? Would it not be better to find where the positive return code is from and fix that?

I guess I can trace it back to find out where the positive return code is originating.

Is phy_connect_direct always supposed to return valid -errno?

Quoted 9 lines
Quoted 3 lines

I would look at this from a different angle. A positive ERRNO is probably a bug of some sort. So rather than papering over the cracks, go find what the real issue is.

Agreed, you could place a WARN_ON(rc > 0) and get the offending call trace leading to that problem. I suspect that one of the PHY drivers might be returning a positive value as part of a phy_read() call and that does not get properly filtered out.

Thanks for the feedback.

Does it hurt to always have a warning on positive return codes before using ERR_PTR?

Quoted 9 lines
Quoted 7 lines

It might not be an ERRNO. E.g. https://lkml.org/lkml/2015/9/3/534
fixed a bug where a positive value is returned which is not an indication of an error.

Andrew

Signature · 1 line
Florian