lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240620114711.777046-3-edumazet@google.com>
Date: Thu, 20 Jun 2024 11:47:07 +0000
From: Eric Dumazet <edumazet@...gle.com>
To: "David S . Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>, 
	Paolo Abeni <pabeni@...hat.com>
Cc: Ziwei Xiao <ziweixiao@...gle.com>, Praveen Kaligineedi <pkaligineedi@...gle.com>, 
	Harshitha Ramamurthy <hramamurthy@...gle.com>, Willem de Bruijn <willemb@...gle.com>, 
	Jeroen de Borst <jeroendb@...gle.com>, Shailend Chand <shailend@...gle.com>, netdev@...r.kernel.org, 
	eric.dumazet@...il.com, Eric Dumazet <edumazet@...gle.com>
Subject: [PATCH net-next 2/6] net: ethtool: add dev_ethtool_cap_check()

Perform capability check in a dedicated helper, before grabbing RTNL.

Signed-off-by: Eric Dumazet <edumazet@...gle.com>
---
 net/ethtool/ioctl.c | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 01c52159aef7a47165ef11aab2c599ffe4ad345d..45e7497839389bad9c6a6b238429b7534bfd6085 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -2850,21 +2850,8 @@ static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr)
 
 /* The main entry point in this file.  Called from net/core/dev_ioctl.c */
 
-static int
-__dev_ethtool(struct net *net, struct net_device *dev, struct ifreq *ifr,
-	      void __user *useraddr, u32 ethcmd,
-	      struct ethtool_devlink_compat *devlink_state)
+static int dev_ethtool_cap_check(struct net *net, u32 sub_cmd)
 {
-	u32 sub_cmd;
-	int rc;
-	netdev_features_t old_features;
-
-	if (ethcmd == ETHTOOL_PERQUEUE) {
-		if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd)))
-			return -EFAULT;
-	} else {
-		sub_cmd = ethcmd;
-	}
 	/* Allow some commands to be done by anyone */
 	switch (sub_cmd) {
 	case ETHTOOL_GSET:
@@ -2908,6 +2895,16 @@ __dev_ethtool(struct net *net, struct net_device *dev, struct ifreq *ifr,
 		if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
 			return -EPERM;
 	}
+	return 0;
+}
+
+static int
+__dev_ethtool(struct net_device *dev, struct ifreq *ifr,
+	      void __user *useraddr, u32 ethcmd, u32 sub_cmd,
+	      struct ethtool_devlink_compat *devlink_state)
+{
+	netdev_features_t old_features;
+	int rc;
 
 	if (dev->dev.parent)
 		pm_runtime_get_sync(dev->dev.parent);
@@ -3151,7 +3148,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr)
 	struct ethtool_devlink_compat *state;
 	netdevice_tracker dev_tracker;
 	struct net_device *dev;
-	u32 ethcmd;
+	u32 ethcmd, sub_cmd;
 	int rc;
 
 	if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
@@ -3171,13 +3168,23 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr)
 		break;
 	}
 
+	if (ethcmd == ETHTOOL_PERQUEUE) {
+		if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd)))
+			return -EFAULT;
+	} else {
+		sub_cmd = ethcmd;
+	}
+	rc = dev_ethtool_cap_check(net, sub_cmd);
+	if (rc)
+		goto exit_free;
+
 	rc = -ENODEV;
 	dev = netdev_get_by_name(net, ifr->ifr_name, &dev_tracker, GFP_KERNEL);
 	if (!dev)
 		goto exit_free;
 
 	rtnl_lock();
-	rc = __dev_ethtool(net, dev, ifr, useraddr, ethcmd, state);
+	rc = __dev_ethtool(dev, ifr, useraddr, ethcmd, sub_cmd, state);
 	rtnl_unlock();
 	netdev_put(dev, &dev_tracker);
 
-- 
2.45.2.627.g7a2c4fd464-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ