Skip to contentSkip to conversation

net: phy: dp83869: fix memory corruption when enabling fiber

PATCH In review Ingo van Lil 3 participants 6 messages Oct 1, 2024 – Oct 2, 2024

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

PATCH 1/1 net: phy: dp83869: fix memory corruption when enabling fiber

When configuring the fiber port, the DP83869 PHY driver incorrectly calls linkmode_set_bit() with a bit mask (1 << 10) rather than a bit number (10). This corrupts some other memory location -- in case of arm64 the priv pointer in the same structure.

---
 drivers/net/phy/dp83869.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/dp83869.c +1 -1
index d7aaefb5226b..9c5ac5d6a9fd 100644
@@ -645,7 +645,7 @@ static int dp83869_configure_fiber(struct phy_device *phydev,
 		     phydev->supported);
 
 	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->supported);
-	linkmode_set_bit(ADVERTISED_FIBRE, phydev->advertising);
+	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->advertising);
 
 	if (dp83869->mode == DP83869_RGMII_1000_BASE) {
 		linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,

--
2.46.1

#1 lore raw

Hi Ingo!

Quoted 15 lines · Ingo van Lil

When configuring the fiber port, the DP83869 PHY driver incorrectly calls linkmode_set_bit() with a bit mask (1 << 10) rather than a bit number (10). This corrupts some other memory location -- in case of arm64 the priv pointer in the same structure.

---
 drivers/net/phy/dp83869.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/dp83869.c +0 -0
index d7aaefb5226b..9c5ac5d6a9fd 100644

drivers/net/phy/dp83869.c static int dp83869_configure_fiber(struct phy_device *phydev, · line 648

Quoted 5 lines
drivers/net/phy/dp83869.c +1 -1
@@ -645,7 +645,7 @@ static int dp83869_configure_fiber(struct phy_device *phydev,
  		     phydev->supported);
 
  	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->supported);
-	linkmode_set_bit(ADVERTISED_FIBRE, phydev->advertising);
+	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->advertising);

Are you sure this linkmode_set_bit() is required at all?

If we consider the following code at the very end of the same function?

        /* Update advertising from supported */
        linkmode_or(phydev->advertising, phydev->advertising,
                    phydev->supported);
Quoted 3 lines
drivers/net/phy/dp83869.c +0 -0
  	if (dp83869->mode == DP83869_RGMII_1000_BASE) {
  		linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
Signature · 3 lines
Alexander Sverdlin
Siemens AG
www.siemens.com
#2 lore raw
Quoted 7 lines · Alexander
Quoted 7 lines
drivers/net/phy/dp83869.c +0 -0
index d7aaefb5226b..9c5ac5d6a9fd 100644
@@ -645,7 +645,7 @@ static int dp83869_configure_fiber(struct phy_device *phydev,
  		     phydev->supported);
 
Quoted 5 lines

drivers/net/phy/dp83869.c static int dp83869_configure_fiber(struct phy_device *phydev, · line 648

Quoted 3 lines
drivers/net/phy/dp83869.c +1 -1
  	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->supported);
-	linkmode_set_bit(ADVERTISED_FIBRE, phydev->advertising);
+	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->advertising);

Are you sure this linkmode_set_bit() is required at all?

You're right, it's probably not required. I just tracked a weird bug down to this clear mistake and wanted to change as little as possible.

The logic of the function seems a bit odd to me: At the beginning, advertising is ANDed with supported, and at the end it's ORed again. Inside the function they are mostly manipulated together.

Couldn't that be replaced with a simple "phydev->advertising = phydev->supported;" at the end?

Regards,
Ingo

#3 lore raw

Hi Ingo!

Quoted 9 lines · Ingo van Lil
Quoted 7 lines · Alexander
Quoted 7 lines
drivers/net/phy/dp83869.c +0 -0
index d7aaefb5226b..9c5ac5d6a9fd 100644
@@ -645,7 +645,7 @@ static int dp83869_configure_fiber(struct phy_device *phydev,
    		     phydev->supported);
 
Quoted 8 lines
Quoted 5 lines

drivers/net/phy/dp83869.c static int dp83869_configure_fiber(struct phy_device *phydev, · line 648

Quoted 3 lines
drivers/net/phy/dp83869.c +1 -1
    	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->supported);
-	linkmode_set_bit(ADVERTISED_FIBRE, phydev->advertising);
+	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->advertising);

Are you sure this linkmode_set_bit() is required at all?

You're right, it's probably not required. I just tracked a weird bug down to this clear mistake and wanted to change as little as possible.

As little as possible would be not to add yet another bit set. Obviously it has been working (if it was at all) without a proper write, but dispite the incorrect write.

Quoted 6 lines

The logic of the function seems a bit odd to me: At the beginning, advertising is ANDed with supported, and at the end it's ORed again. Inside the function they are mostly manipulated together.

Couldn't that be replaced with a simple "phydev->advertising = phydev->supported;" at the end?

Yes, the function looks strange.
But as this is for -stable, maybe complete rework is undesired. IMO, just delete the bogus write.

Signature · 3 lines
Alexander Sverdlin
Siemens AG
www.siemens.com
maintainer
#4 lore raw
Quoted 29 lines · Alexander

Hi Ingo!

Quoted 9 lines · Ingo van Lil
Quoted 7 lines · Alexander
Quoted 7 lines
drivers/net/phy/dp83869.c +0 -0
index d7aaefb5226b..9c5ac5d6a9fd 100644
@@ -645,7 +645,7 @@ static int dp83869_configure_fiber(struct phy_device *phydev,
    		     phydev->supported);
 
Quoted 8 lines
Quoted 5 lines

drivers/net/phy/dp83869.c static int dp83869_configure_fiber(struct phy_device *phydev, · line 648

Quoted 3 lines
drivers/net/phy/dp83869.c +1 -1
    	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->supported);
-	linkmode_set_bit(ADVERTISED_FIBRE, phydev->advertising);
+	linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->advertising);

Are you sure this linkmode_set_bit() is required at all?

You're right, it's probably not required. I just tracked a weird bug down to this clear mistake and wanted to change as little as possible.

As little as possible would be not to add yet another bit set. Obviously it has been working (if it was at all) without a proper write, but dispite the incorrect write.

Quoted 4 lines

The logic of the function seems a bit odd to me: At the beginning, advertising is ANDed with supported, and at the end it's ORed again. Inside the function they are mostly manipulated together.

Quoted 6 lines
Quoted 2 lines

Couldn't that be replaced with a simple "phydev->advertising = phydev->supported;" at the end?

Yes, the function looks strange.
But as this is for -stable, maybe complete rework is undesired. IMO, just delete the bogus write.

+1 KISS for stable.

For net-next, as far as i can see, dp83869->mode is fixed at probe time. As a lot of the code here should be moved into .get_features.

Andrew