Skip to content

Commit 30b7483

Browse files
committed
Merge branch 'net-Use-strlcpy-for-ethtool-get_strings'
Florian Fainelli says: ==================== net: Use strlcpy() for ethtool::get_strings After turning on KASAN on one of my systems, I started getting lots of out of bounds errors while fetching a given port's statistics, and indeed using memcpy() is unsafe for copying strings which have not been declared as an array of ETH_GSTRING_LEN bytes, so let's use strlcpy() instead. This allows the best of both worlds: we still keep the efficient memory usage of variably sized strings, but we don't copy more than we need to. Changes in v2: - dropped the 3 other patches that were not necessary - use strlcpy() instead of strncpy() ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents ce38061 + 8a17eef commit 30b7483

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ void b53_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
814814
unsigned int i;
815815

816816
for (i = 0; i < mib_size; i++)
817-
memcpy(data + i * ETH_GSTRING_LEN,
818-
mibs[i].name, ETH_GSTRING_LEN);
817+
strlcpy(data + i * ETH_GSTRING_LEN,
818+
mibs[i].name, ETH_GSTRING_LEN);
819819
}
820820
EXPORT_SYMBOL(b53_get_strings);
821821

drivers/net/phy/bcm-phy-lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ void bcm_phy_get_strings(struct phy_device *phydev, u8 *data)
341341
unsigned int i;
342342

343343
for (i = 0; i < ARRAY_SIZE(bcm_phy_hw_stats); i++)
344-
memcpy(data + i * ETH_GSTRING_LEN,
345-
bcm_phy_hw_stats[i].string, ETH_GSTRING_LEN);
344+
strlcpy(data + i * ETH_GSTRING_LEN,
345+
bcm_phy_hw_stats[i].string, ETH_GSTRING_LEN);
346346
}
347347
EXPORT_SYMBOL_GPL(bcm_phy_get_strings);
348348

drivers/net/phy/marvell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,8 +1452,8 @@ static void marvell_get_strings(struct phy_device *phydev, u8 *data)
14521452
int i;
14531453

14541454
for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) {
1455-
memcpy(data + i * ETH_GSTRING_LEN,
1456-
marvell_hw_stats[i].string, ETH_GSTRING_LEN);
1455+
strlcpy(data + i * ETH_GSTRING_LEN,
1456+
marvell_hw_stats[i].string, ETH_GSTRING_LEN);
14571457
}
14581458
}
14591459

drivers/net/phy/micrel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ static void kszphy_get_strings(struct phy_device *phydev, u8 *data)
664664
int i;
665665

666666
for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) {
667-
memcpy(data + i * ETH_GSTRING_LEN,
668-
kszphy_hw_stats[i].string, ETH_GSTRING_LEN);
667+
strlcpy(data + i * ETH_GSTRING_LEN,
668+
kszphy_hw_stats[i].string, ETH_GSTRING_LEN);
669669
}
670670
}
671671

0 commit comments

Comments
 (0)