Commit b5d1ad79 authored by Eugenia Emantayev's avatar Eugenia Emantayev Committed by Khalid Elmously

ethtool: Ensure new ring parameters are within bounds during SRINGPARAM

BugLink: https://bugs.launchpad.net/bugs/1874444

Add a sanity check to ensure that all requested ring parameters
are within bounds, which should reduce errors in driver implementation.
Signed-off-by: default avatarEugenia Emantayev <eugenia@mellanox.com>
Signed-off-by: default avatarTariq Toukan <tariqt@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
(cherry picked from commit 37e2d99b)
Signed-off-by: default avatarGuilherme G. Piccoli <gpiccoli@canonical.com>
Acked-by: default avatarKleber Souza <kleber.souza@canonical.com>
Acked-by: default avatarKamal Mostafa <kamal@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 67e423f5
......@@ -1663,14 +1663,23 @@ static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
{
struct ethtool_ringparam ringparam;
struct ethtool_ringparam ringparam, max = { .cmd = ETHTOOL_GRINGPARAM };
if (!dev->ethtool_ops->set_ringparam)
if (!dev->ethtool_ops->set_ringparam || !dev->ethtool_ops->get_ringparam)
return -EOPNOTSUPP;
if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
return -EFAULT;
dev->ethtool_ops->get_ringparam(dev, &max);
/* ensure new ring parameters are within the maximums */
if (ringparam.rx_pending > max.rx_max_pending ||
ringparam.rx_mini_pending > max.rx_mini_max_pending ||
ringparam.rx_jumbo_pending > max.rx_jumbo_max_pending ||
ringparam.tx_pending > max.tx_max_pending)
return -EINVAL;
return dev->ethtool_ops->set_ringparam(dev, &ringparam);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment