diff mbox series

[net] net: phy: marvell: Fix buffer overrun with stats counters

Message ID 20190424223300.23727-1-andrew@lunn.ch
State Accepted
Delegated to: David Miller
Headers show
Series [net] net: phy: marvell: Fix buffer overrun with stats counters | expand

Commit Message

Andrew Lunn April 24, 2019, 10:33 p.m. UTC
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 passed 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>
---
 drivers/net/phy/marvell.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Florian Fainelli April 24, 2019, 10:48 p.m. UTC | #1
On 4/24/19 3:33 PM, Andrew Lunn wrote:
> 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 passed 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>
Sergei Shtylyov April 25, 2019, 9:44 a.m. UTC | #2
Hello!

On 25.04.2019 1:33, Andrew Lunn wrote:

> 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 passed the end

    s/passed/past/?

> 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>
[...]

MBR, Sergei
David Miller April 26, 2019, 4:06 p.m. UTC | #3
From: Andrew Lunn <andrew@lunn.ch>
Date: Thu, 25 Apr 2019 00:33:00 +0200

> 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 passed 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>

Applied and queued up for -stable, thanks!
diff mbox series

Patch

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 3ccba37bd6dd..f76c4048b978 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -1489,9 +1489,10 @@  static int marvell_get_sset_count(struct phy_device *phydev)
 
 static void marvell_get_strings(struct phy_device *phydev, u8 *data)
 {
+	int count = marvell_get_sset_count(phydev);
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) {
+	for (i = 0; i < count; i++) {
 		strlcpy(data + i * ETH_GSTRING_LEN,
 			marvell_hw_stats[i].string, ETH_GSTRING_LEN);
 	}
@@ -1519,9 +1520,10 @@  static u64 marvell_get_stat(struct phy_device *phydev, int i)
 static void marvell_get_stats(struct phy_device *phydev,
 			      struct ethtool_stats *stats, u64 *data)
 {
+	int count = marvell_get_sset_count(phydev);
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++)
+	for (i = 0; i < count; i++)
 		data[i] = marvell_get_stat(phydev, i);
 }