From: Tariq Toukan <tariqt@mellanox.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, Eran Ben Elisha <eranbe@mellanox.com>,
Eugenia Emantayev <eugenia@mellanox.com>,
Tariq Toukan <tariqt@mellanox.com>
Subject: [PATCH net-next 1/3] ethtool: Ensure new ring parameters are within bounds during SRINGPARAM
Date: Mon, 8 Jan 2018 16:00:24 +0200 [thread overview]
Message-ID: <1515420026-11970-2-git-send-email-tariqt@mellanox.com> (raw)
In-Reply-To: <1515420026-11970-1-git-send-email-tariqt@mellanox.com>
From: Eugenia Emantayev <eugenia@mellanox.com>
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 <eugenia@mellanox.com>
Signed-off-by: Tariq Toukan <tariqt@mellanox.com>
---
net/core/ethtool.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 50a79203043b..9ea7cd52fde0 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -1704,14 +1704,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);
}
--
1.8.3.1
next prev parent reply other threads:[~2018-01-08 14:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-08 14:00 [PATCH net-next 0/3] ethtool ringparam upper bound Tariq Toukan
2018-01-08 14:00 ` Tariq Toukan [this message]
2018-01-09 2:23 ` [PATCH net-next 1/3] ethtool: Ensure new ring parameters are within bounds during SRINGPARAM Jakub Kicinski
2018-01-09 7:30 ` Tariq Toukan
2018-01-09 7:35 ` Jakub Kicinski
2018-01-08 14:00 ` [PATCH net-next 2/3] net/mlx4_en: Align behavior of set ring size flow via ethtool Tariq Toukan
2018-01-08 14:00 ` [PATCH net-next 3/3] net/mlx5e: Remove redundant checks in set_ringparam Tariq Toukan
2018-01-09 16:55 ` [PATCH net-next 0/3] ethtool ringparam upper bound David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1515420026-11970-2-git-send-email-tariqt@mellanox.com \
--to=tariqt@mellanox.com \
--cc=davem@davemloft.net \
--cc=eranbe@mellanox.com \
--cc=eugenia@mellanox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox