Skip to content

Commit 37e2d99

Browse files
Eugenia Emantayevdavem330
authored andcommitted
ethtool: Ensure new ring parameters are within bounds during SRINGPARAM
Add a sanity check to ensure that all requested ring parameters are within bounds, which should reduce errors in driver implementation. Signed-off-by: Eugenia Emantayev <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 709af18 commit 37e2d99

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

net/core/ethtool.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,14 +1693,23 @@ static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
16931693

16941694
static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
16951695
{
1696-
struct ethtool_ringparam ringparam;
1696+
struct ethtool_ringparam ringparam, max = { .cmd = ETHTOOL_GRINGPARAM };
16971697

1698-
if (!dev->ethtool_ops->set_ringparam)
1698+
if (!dev->ethtool_ops->set_ringparam || !dev->ethtool_ops->get_ringparam)
16991699
return -EOPNOTSUPP;
17001700

17011701
if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
17021702
return -EFAULT;
17031703

1704+
dev->ethtool_ops->get_ringparam(dev, &max);
1705+
1706+
/* ensure new ring parameters are within the maximums */
1707+
if (ringparam.rx_pending > max.rx_max_pending ||
1708+
ringparam.rx_mini_pending > max.rx_mini_max_pending ||
1709+
ringparam.rx_jumbo_pending > max.rx_jumbo_max_pending ||
1710+
ringparam.tx_pending > max.tx_max_pending)
1711+
return -EINVAL;
1712+
17041713
return dev->ethtool_ops->set_ringparam(dev, &ringparam);
17051714
}
17061715

0 commit comments

Comments
 (0)