From: Gustavo Luiz Duarte <gustavold@gmail.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Ahern <dsahern@kernel.org>,
Breno Leitao <leitao@debian.org>,
Willem de Bruijn <willemb@google.com>,
linux-kernel@vger.kernel.org,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Subject: [PATCH] net: ipmr: Call ipmr_ioctl() directly from ipmr_sk_ioctl()
Date: Mon, 31 Jul 2023 07:57:13 -0700 [thread overview]
Message-ID: <20230731145713.178509-1-gustavold@gmail.com> (raw)
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@gmail.com>
Suggested-by: Willem de Bruijn <willemdebruijn.kernel@gmail.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
next reply other threads:[~2023-07-31 14:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 14:57 Gustavo Luiz Duarte [this message]
2023-07-31 18:27 ` [PATCH] net: ipmr: Call ipmr_ioctl() directly from ipmr_sk_ioctl() Willem de Bruijn
2023-08-09 3:26 ` kernel test robot
2023-08-09 22:25 ` kernel test robot
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=20230731145713.178509-1-gustavold@gmail.com \
--to=gustavold@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
--cc=willemdebruijn.kernel@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).