Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 2170fef78a40 ("Marvell phy: add field to get errors from fiber link.")
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Andrew Lunn and committed by
David S. Miller
fdfdf867 4e43df38

+4 -2
+4 -2
drivers/net/phy/marvell.c
··· 1489 1489 1490 1490 static void marvell_get_strings(struct phy_device *phydev, u8 *data) 1491 1491 { 1492 + int count = marvell_get_sset_count(phydev); 1492 1493 int i; 1493 1494 1494 - for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) { 1495 + for (i = 0; i < count; i++) { 1495 1496 strlcpy(data + i * ETH_GSTRING_LEN, 1496 1497 marvell_hw_stats[i].string, ETH_GSTRING_LEN); 1497 1498 } ··· 1520 1519 static void marvell_get_stats(struct phy_device *phydev, 1521 1520 struct ethtool_stats *stats, u64 *data) 1522 1521 { 1522 + int count = marvell_get_sset_count(phydev); 1523 1523 int i; 1524 1524 1525 - for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) 1525 + for (i = 0; i < count; i++) 1526 1526 data[i] = marvell_get_stat(phydev, i); 1527 1527 } 1528 1528