mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-08 14:13:53 +00:00
ethtool: ioctl: Use array_size() helper in copy_{from,to}_user()
Use array_size() helper instead of the open-coded version in copy_{from,to}_user(). These sorts of multiplication factors need to be wrapped in array_size(). Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
4f948b3430
commit
ed717613f9
@ -89,7 +89,8 @@ static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
|
|||||||
if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
|
if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
useraddr += sizeof(cmd);
|
useraddr += sizeof(cmd);
|
||||||
if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
|
if (copy_to_user(useraddr, features,
|
||||||
|
array_size(copy_size, sizeof(*features))))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -799,7 +800,7 @@ static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
useraddr += offsetof(struct ethtool_sset_info, data);
|
useraddr += offsetof(struct ethtool_sset_info, data);
|
||||||
if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
|
if (copy_to_user(useraddr, info_buf, array_size(idx, sizeof(u32))))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -1022,7 +1023,7 @@ static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
|
if (copy_from_user(indir, useraddr, array_size(size, sizeof(indir[0]))))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
/* Validate ring indices */
|
/* Validate ring indices */
|
||||||
@ -1895,7 +1896,7 @@ static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
|
|||||||
if (copy_to_user(useraddr, &test, sizeof(test)))
|
if (copy_to_user(useraddr, &test, sizeof(test)))
|
||||||
goto out;
|
goto out;
|
||||||
useraddr += sizeof(test);
|
useraddr += sizeof(test);
|
||||||
if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
|
if (copy_to_user(useraddr, data, array_size(test.len, sizeof(u64))))
|
||||||
goto out;
|
goto out;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
@ -1937,7 +1938,8 @@ static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
|
|||||||
goto out;
|
goto out;
|
||||||
useraddr += sizeof(gstrings);
|
useraddr += sizeof(gstrings);
|
||||||
if (gstrings.len &&
|
if (gstrings.len &&
|
||||||
copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
|
copy_to_user(useraddr, data,
|
||||||
|
array_size(gstrings.len, ETH_GSTRING_LEN)))
|
||||||
goto out;
|
goto out;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user