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-next>] [day] [month] [year] [list]
Message-Id: <20230731145713.178509-1-gustavold@gmail.com>
Date: Mon, 31 Jul 2023 07:57:13 -0700
From: Gustavo Luiz Duarte <gustavold@...il.com>
To: netdev@...r.kernel.org
Cc: "David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	David Ahern <dsahern@...nel.org>,
	Breno Leitao <leitao@...ian.org>,
	Willem de Bruijn <willemb@...gle.com>,
	linux-kernel@...r.kernel.org,
	Willem de Bruijn <willemdebruijn.kernel@...il.com>
Subject: [PATCH] net: ipmr: Call ipmr_ioctl() directly from ipmr_sk_ioctl()

Call ipmr_ioctl()/ip6mr_ioctl() directly from ipmr_sk_ioctl()/ip6mr_sk_ioctl()
and avoid sk_prot->ioctl function pointer indirection.

Also, delete the sock_ioctl_inout() helper as it is no longer needed.

Signed-off-by: Gustavo Luiz Duarte <gustavold@...il.com>
Suggested-by: Willem de Bruijn <willemdebruijn.kernel@...il.com>
---
 include/linux/mroute6.h | 33 ++++++++++++++++++++++++++-------
 include/net/sock.h      |  2 --
 net/core/sock.c         | 20 --------------------
 net/ipv4/ipmr.c         | 33 ++++++++++++++++++++++++++-------
 4 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/include/linux/mroute6.h b/include/linux/mroute6.h
index 63ef5191cc57..1ed34264bb72 100644
--- a/include/linux/mroute6.h
+++ b/include/linux/mroute6.h
@@ -103,19 +103,38 @@ extern int ip6mr_sk_done(struct sock *sk);
 static inline int ip6mr_sk_ioctl(struct sock *sk, unsigned int cmd,
 				 void __user *arg)
 {
+	int ret;
+
 	switch (cmd) {
-	/* These userspace buffers will be consumed by ip6mr_ioctl() */
 	case SIOCGETMIFCNT_IN6: {
-		struct sioc_mif_req6 buffer;
+		struct sioc_mif_req6 karg;
+
+		if (copy_from_user(&karg, arg, sizeof(karg)))
+			return -EFAULT;
+
+		ret = ip6mr_ioctl(sk, cmd, &karg);
+		if (ret)
+			return ret;
+
+		if (copy_to_user(arg, &karg, sizeof(karg)))
+			return -EFAULT;
 
-		return sock_ioctl_inout(sk, cmd, arg, &buffer,
-					sizeof(buffer));
+		return 0;
 		}
 	case SIOCGETSGCNT_IN6: {
-		struct sioc_sg_req6 buffer;
+		struct sioc_sg_req6 karg;
+
+		if (copy_from_user(&karg, arg, sizeof(karg)))
+			return -EFAULT;
+
+		ret = ip6mr_ioctl(sk, cmd, &karg);
+		if (ret)
+			return ret;
+
+		if (copy_to_user(arg, &karg, sizeof(karg)))
+			return -EFAULT;
 
-		return sock_ioctl_inout(sk, cmd, arg, &buffer,
-					sizeof(buffer));
+		return 0;
 		}
 	}
 
diff --git a/include/net/sock.h b/include/net/sock.h
index 2eb916d1ff64..0df582e3776a 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2969,8 +2969,6 @@ int sock_get_timeout(long timeo, void *optval, bool old_timeval);
 int sock_copy_user_timeval(struct __kernel_sock_timeval *tv,
 			   sockptr_t optval, int optlen, bool old_timeval);
 
-int sock_ioctl_inout(struct sock *sk, unsigned int cmd,
-		     void __user *arg, void *karg, size_t size);
 int sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
 static inline bool sk_is_readable(struct sock *sk)
 {
diff --git a/net/core/sock.c b/net/core/sock.c
index 9370fd50aa2c..e0002805ecbd 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -4129,26 +4129,6 @@ int sock_bind_add(struct sock *sk, struct sockaddr *addr, int addr_len)
 }
 EXPORT_SYMBOL(sock_bind_add);
 
-/* Copy 'size' bytes from userspace and return `size` back to userspace */
-int sock_ioctl_inout(struct sock *sk, unsigned int cmd,
-		     void __user *arg, void *karg, size_t size)
-{
-	int ret;
-
-	if (copy_from_user(karg, arg, size))
-		return -EFAULT;
-
-	ret = READ_ONCE(sk->sk_prot)->ioctl(sk, cmd, karg);
-	if (ret)
-		return ret;
-
-	if (copy_to_user(arg, karg, size))
-		return -EFAULT;
-
-	return 0;
-}
-EXPORT_SYMBOL(sock_ioctl_inout);
-
 /* This is the most common ioctl prep function, where the result (4 bytes) is
  * copied back to userspace if the ioctl() returns successfully. No input is
  * copied from userspace as input argument.
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 3f0c6d602fb7..0144da36e6c0 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -1550,19 +1550,38 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, sockptr_t optval,
 /* Execute if this ioctl is a special mroute ioctl */
 int ipmr_sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg)
 {
+	int ret;
+
 	switch (cmd) {
-	/* These userspace buffers will be consumed by ipmr_ioctl() */
 	case SIOCGETVIFCNT: {
-		struct sioc_vif_req buffer;
+		struct sioc_vif_req karg;
+
+		if (copy_from_user(&karg, arg, sizeof(karg)))
+			return -EFAULT;
+
+		ret = ipmr_ioctl(sk, cmd, &karg);
+		if (ret)
+			return ret;
+
+		if (copy_to_user(arg, &karg, sizeof(karg)))
+			return -EFAULT;
 
-		return sock_ioctl_inout(sk, cmd, arg, &buffer,
-				      sizeof(buffer));
+		return 0;
 		}
 	case SIOCGETSGCNT: {
-		struct sioc_sg_req buffer;
+		struct sioc_sg_req karg;
+
+		if (copy_from_user(&karg, arg, sizeof(karg)))
+			return -EFAULT;
+
+		ret = ipmr_ioctl(sk, cmd, &karg);
+		if (ret)
+			return ret;
 
-		return sock_ioctl_inout(sk, cmd, arg, &buffer,
-				      sizeof(buffer));
+		if (copy_to_user(arg, &karg, sizeof(karg)))
+			return -EFAULT;
+
+		return 0;
 		}
 	}
 	/* return code > 0 means that the ioctl was not executed */
-- 
2.40.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ