mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-06 22:55:11 +00:00
ethtool: ensure channel counts are within bounds during SCHANNELS
Add a sanity check to ensure that all requested channel sizes are within bounds, which should reduce errors in driver implementation. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
d4ab428627
commit
8bf3686204
1 changed files with 11 additions and 2 deletions
|
@ -1274,15 +1274,24 @@ static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
|
||||||
static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
|
static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
|
||||||
void __user *useraddr)
|
void __user *useraddr)
|
||||||
{
|
{
|
||||||
struct ethtool_channels channels;
|
struct ethtool_channels channels, max;
|
||||||
u32 max_rx_in_use = 0;
|
u32 max_rx_in_use = 0;
|
||||||
|
|
||||||
if (!dev->ethtool_ops->set_channels)
|
if (!dev->ethtool_ops->set_channels || !dev->ethtool_ops->get_channels)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
if (copy_from_user(&channels, useraddr, sizeof(channels)))
|
if (copy_from_user(&channels, useraddr, sizeof(channels)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
|
dev->ethtool_ops->get_channels(dev, &max);
|
||||||
|
|
||||||
|
/* ensure new counts are within the maximums */
|
||||||
|
if ((channels.rx_count > max.max_rx) ||
|
||||||
|
(channels.tx_count > max.max_tx) ||
|
||||||
|
(channels.combined_count > max.max_combined) ||
|
||||||
|
(channels.other_count > max.max_other))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
/* ensure the new Rx count fits within the configured Rx flow
|
/* ensure the new Rx count fits within the configured Rx flow
|
||||||
* indirection table settings */
|
* indirection table settings */
|
||||||
if (netif_is_rxfh_configured(dev) &&
|
if (netif_is_rxfh_configured(dev) &&
|
||||||
|
|
Loading…
Add table
Reference in a new issue