Skip to content

Commit fdfdf86

Browse files
lunndavem330
authored andcommitted
net: phy: marvell: Fix buffer overrun with stats counters
marvell_get_sset_count() returns how many statistics counters there are. If the PHY supports fibre, there are 3, otherwise two. marvell_get_strings() does not make this distinction, and always returns 3 strings. This then often results in writing past the end of the buffer for the strings. Fixes: 2170fef ("Marvell phy: add field to get errors from fiber link.") Signed-off-by: Andrew Lunn <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4e43df3 commit fdfdf86

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/net/phy/marvell.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,9 +1489,10 @@ static int marvell_get_sset_count(struct phy_device *phydev)
14891489

14901490
static void marvell_get_strings(struct phy_device *phydev, u8 *data)
14911491
{
1492+
int count = marvell_get_sset_count(phydev);
14921493
int i;
14931494

1494-
for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) {
1495+
for (i = 0; i < count; i++) {
14951496
strlcpy(data + i * ETH_GSTRING_LEN,
14961497
marvell_hw_stats[i].string, ETH_GSTRING_LEN);
14971498
}
@@ -1519,9 +1520,10 @@ static u64 marvell_get_stat(struct phy_device *phydev, int i)
15191520
static void marvell_get_stats(struct phy_device *phydev,
15201521
struct ethtool_stats *stats, u64 *data)
15211522
{
1523+
int count = marvell_get_sset_count(phydev);
15221524
int i;
15231525

1524-
for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++)
1526+
for (i = 0; i < count; i++)
15251527
data[i] = marvell_get_stat(phydev, i);
15261528
}
15271529

0 commit comments

Comments
 (0)