Skip to contentSkip to conversation

tg3: copy only needed fields from userspace-provided EEE data

PATCH Applied Heiner Kallweit 3 participants 4 messages Feb 18, 2024 – Feb 21, 2024

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

PATCH 1/1 tg3: copy only needed fields from userspace-provided EEE data

The current code overwrites fields in tp->eee with unchecked data from edata, e.g. the bitmap with supported modes. ethtool properly returns the received data from get_eee() call, but we have no guarantee that other users of the ioctl set_eee() interface behave properly too. Therefore copy only fields which are actually needed.

---
 drivers/net/ethernet/broadcom/tg3.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/tg3.c +3 -1
index 51685cd29..7a07c5216 100644
@@ -14200,7 +14200,9 @@ static int tg3_set_eee(struct net_device *dev, struct ethtool_keee *edata)
 		return -EINVAL;
 	}
 
-	tp->eee = *edata;
+	tp->eee.eee_enabled = edata->eee_enabled;
+	tp->eee.tx_lpi_enabled = edata->tx_lpi_enabled;
+	tp->eee.tx_lpi_timer = edata->tx_lpi_timer;
 
 	tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED;
 	tg3_warn_mgmt_link_flap(tp);
Signature · 1 line
2.43.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Heiner Kallweit

The current code overwrites fields in tp->eee with unchecked data from edata, e.g. the bitmap with supported modes. ethtool properly returns the received data from get_eee() call, but we have no guarantee that other users of the ioctl set_eee() interface behave properly too. Therefore copy only fields which are actually needed.

This one needed some time for me to understand. I missed that when programming the PHY to advertise, it is hard coded what it actually advertises. So there is no need to copy the advertise linkmode from edata.

I suspect this driver is broken in that it does not wait for the result of the auto-neg to enable/disable EEE in the hardware. But it could be hiding somewhere in the code and i also missed that.

Andrew

#2 lore raw
Quoted 7 lines · Andrew Lunn
Quoted 6 lines · Heiner Kallweit

The current code overwrites fields in tp->eee with unchecked data from edata, e.g. the bitmap with supported modes. ethtool properly returns the received data from get_eee() call, but we have no guarantee that other users of the ioctl set_eee() interface behave properly too. Therefore copy only fields which are actually needed.

Quoted 7 lines
Quoted 1 line

This one needed some time for me to understand. I missed that when programming the PHY to advertise, it is hard coded what it actually advertises. So there is no need to copy the advertise linkmode from edata.

Especially as we have the following a few lines earlier:

    if (!linkmode_equal(edata->advertised, tp->eee.advertised)) {
                netdev_warn(tp->dev,
                            "Direct manipulation of EEE advertisement is not supported\n");
                return -EINVAL;
        }
Quoted 7 lines

I suspect this driver is broken in that it does not wait for the result of the auto-neg to enable/disable EEE in the hardware. But it could be hiding somewhere in the code and i also missed that.

Andrew

#3 lore raw
In reply to Heiner Kallweit
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 9 lines · On Sun, 18 Feb 2024 15:49:55 +0100 you wrote:

The current code overwrites fields in tp->eee with unchecked data from edata, e.g. the bitmap with supported modes. ethtool properly returns the received data from get_eee() call, but we have no guarantee that other users of the ioctl set_eee() interface behave properly too. Therefore copy only fields which are actually needed.

[...]

Here is the summary with links:
- [net-next] tg3: copy only needed fields from userspace-provided EEE data

    https://git.kernel.org/netdev/net-next/c/8306ee08c0ff

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html