Skip to contentSkip to conversation

ethtool: ioctl: Use array_size() in copy_to_user()

PATCH Applied Gustavo A. R. Silva 2 participants 2 messages Jun 15, 2020 – Jun 17, 2020

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

PATCH 1/1 ethtool: ioctl: Use array_size() in copy_to_user()

Use array_size() helper instead of the open-coded version in copy_to_user(). These sorts of multiplication factors need to be wrapped in array_size().

This issue was found with the help of Coccinelle and, audited and fixed manually.

Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83

---
 net/ethtool/ioctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ethtool/ioctl.c +2 -2
index b5df90c981c2..be3ed24bfe03 100644
@@ -1918,7 +1918,7 @@ static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
 	if (copy_to_user(useraddr, &stats, sizeof(stats)))
 		goto out;
 	useraddr += sizeof(stats);
-	if (n_stats && copy_to_user(useraddr, data, n_stats * sizeof(u64)))
+	if (n_stats && copy_to_user(useraddr, data, array_size(n_stats, sizeof(u64))))
 		goto out;
 	ret = 0;
 
@@ -1973,7 +1973,7 @@ static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr)
 	if (copy_to_user(useraddr, &stats, sizeof(stats)))
 		goto out;
 	useraddr += sizeof(stats);
-	if (n_stats && copy_to_user(useraddr, data, n_stats * sizeof(u64)))
+	if (n_stats && copy_to_user(useraddr, data, array_size(n_stats, sizeof(u64))))
 		goto out;
 	ret = 0;
 
Signature · 1 line
2.27.0
maintainer Applied
#1 lore raw

From: "Gustavo A. R. Silva" <[email protected]>
Date: Mon, 15 Jun 2020 18:01:07 -0500

Quoted 9 lines

Use array_size() helper instead of the open-coded version in copy_to_user(). These sorts of multiplication factors need to be wrapped in array_size().

This issue was found with the help of Coccinelle and, audited and fixed manually.

Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83

Applied to net-next.