move the SIOCDELRT and SIOCADDRT compat_ioctl handlers
Subsystems (6)
Hi Dave,
this series moves the compat_ioctl handlers into the protocol handlers, avoiding the need to override the address space limited as in the current handler.
PATCH 1/4 ipv6: lift copy_from_user out of ipv6_route_ioctl
Prepare for better compat ioctl handling by moving the user copy out of ipv6_route_ioctl.
--- include/net/ip6_route.h | 3 ++- net/ipv6/af_inet6.c | 16 +++++++++------ net/ipv6/route.c | 44 +++++++++++++++-------------------------- 3 files changed, 28 insertions(+), 35 deletions(-)
include/net/ip6_route.h +2 -1
@@ -118,7 +118,8 @@ void ip6_route_init_special_entries(void);int ip6_route_init (void );void ip6_route_cleanup (void ); -int ipv6_route_ioctl (struct net *net,unsigned int cmd,void __user *arg); +int ipv6_route_ioctl (struct net *net,unsigned int cmd, +struct in6_rtmsg *rtmsg);int ip6_route_add (struct fib6_config *cfg,gfp_t gfp_flags,struct netlink_ext_ack *extack);
net/ipv6/af_inet6.c +10 -6
@@ -542,19 +542,23 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) {struct sock *sk = sock->sk;struct net *net =sock_net (sk); +void __user *argp = (void __user *)arg;switch (cmd) {case SIOCADDRT : -case SIOCDELRT : - -return ipv6_route_ioctl (net, cmd, (void __user *)arg); +case SIOCDELRT : { +struct in6_rtmsg rtmsg; +if (copy_from_user (&rtmsg, argp,sizeof (rtmsg))) +return -EFAULT ; +return ipv6_route_ioctl (net, cmd, &rtmsg); + }case SIOCSIFADDR : -return addrconf_add_ifaddr (net, (void __user *) arg); +return addrconf_add_ifaddr (net, argp);case SIOCDIFADDR : -return addrconf_del_ifaddr (net, (void __user *) arg); +return addrconf_del_ifaddr (net, argp);case SIOCSIFDSTADDR : -return addrconf_set_dstaddr (net, (void __user *) arg); +return addrconf_set_dstaddr (net, argp);default :if (!sk->sk_prot->ioctl)return -ENOIOCTLCMD ;
net/ipv6/route.c +16 -28
57 lines not on this page · raw message
Signature · 1 line
2.26.2
David Miller
maintainerRe: [PATCH 1/4] ipv6: lift copy_from_user out of ipv6_route_ioctl
From: Christoph Hellwig <[email protected]>
Date: Thu, 14 May 2020 16:45:32 +0200
net/ipv6/af_inet6.c int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) · line 545
Quoted 7 lines
net/ipv6/af_inet6.c +1
-0@@ -542,19 +542,23 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) {struct sock *sk = sock->sk;struct net *net =sock_net (sk); +void __user *argp = (void __user *)arg;
Please retain the reverse christmas tree ordering here.
PATCH 2/4 ipv6: move SIOCADDRT and SIOCDELRT handling into ->compat_ioctl
In reply to Christoph HellwigTo prepare removing the global routing_ioctl hack start lifting the code into a newly added ipv6 ->compat_ioctl handler.
--- include/net/ipv6.h | 2 ++ net/dccp/ipv6.c | 1 + net/ipv6/af_inet6.c | 53 +++++++++++++++++++++++++++++++++++++ net/ipv6/raw.c | 1 + net/l2tp/l2tp_ip6.c | 1 + net/mptcp/protocol.c | 1 + net/sctp/ipv6.c | 1 + net/socket.c | 63 ++++++++++++-------------------------------- 8 files changed, 77 insertions(+), 46 deletions(-)
include/net/ipv6.h +2 -0
@@ -1115,6 +1115,8 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len);int inet6_getname (struct socket *sock,struct sockaddr *uaddr,int peer);int inet6_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg); +int inet6_compat_ioctl (struct socket *sock,unsigned int cmd, +unsigned long arg);int inet6_hash_connect (struct inet_timewait_death_row *death_row,struct sock *sk);
net/dccp/ipv6.c +1 -0
@@ -1082,6 +1082,7 @@ static const struct proto_ops inet6_dccp_ops = { .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, #ifdef CONFIG_COMPAT + .compat_ioctl = inet6_compat_ioctl, .compat_setsockopt = compat_sock_common_setsockopt, .compat_getsockopt = compat_sock_common_getsockopt, #endif
net/ipv6/af_inet6.c +53 -0
77 lines not on this page · raw message
net/ipv6/raw.c +1 -0
@@ -1377,6 +1377,7 @@ const struct proto_ops inet6_sockraw_ops = { .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, #ifdef CONFIG_COMPAT + .compat_ioctl = inet6_compat_ioctl, .compat_setsockopt = compat_sock_common_setsockopt, .compat_getsockopt = compat_sock_common_getsockopt, #endif
net/l2tp/l2tp_ip6.c +1 -0
@@ -758,6 +758,7 @@ static const struct proto_ops l2tp_ip6_ops = { .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, #ifdef CONFIG_COMPAT + .compat_ioctl = inet6_compat_ioctl, .compat_setsockopt = compat_sock_common_setsockopt, .compat_getsockopt = compat_sock_common_getsockopt, #endif
net/mptcp/protocol.c +1 -0
@@ -2006,6 +2006,7 @@ static const struct proto_ops mptcp_v6_stream_ops = { .mmap = sock_no_mmap, .sendpage = inet_sendpage, #ifdef CONFIG_COMPAT + .compat_ioctl = inet6_compat_ioctl, .compat_setsockopt = compat_sock_common_setsockopt, .compat_getsockopt = compat_sock_common_getsockopt, #endif
net/sctp/ipv6.c +1 -0
@@ -1032,6 +1032,7 @@ static const struct proto_ops inet6_seqpacket_ops = { .recvmsg = inet_recvmsg, .mmap = sock_no_mmap, #ifdef CONFIG_COMPAT + .compat_ioctl = inet6_compat_ioctl, .compat_setsockopt = compat_sock_common_setsockopt, .compat_getsockopt = compat_sock_common_getsockopt, #endif
net/socket.c +17 -46
79 lines not on this page · raw message
Signature · 1 line
2.26.2
David Miller
maintainerRe: [PATCH 2/4] ipv6: move SIOCADDRT and SIOCDELRT handling into ->compat_ioctl
From: Christoph Hellwig <[email protected]>
Date: Thu, 14 May 2020 16:45:33 +0200
net/ipv6/af_inet6.c int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) · line 610
Quoted 4 lines
net/ipv6/af_inet6.c +4
-0+int inet6_compat_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg) +{ +struct sock *sk = sock->sk; +void __user *argp =compat_ptr (arg);
Reverse chrstimas tree please.
PATCH 3/4 appletalk: factor out a atrtr_ioctl_addrt helper
In reply to Christoph HellwigAdd a helper than can be shared with the upcoming compat ioctl handler.
--- net/appletalk/ddp.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
net/appletalk/ddp.c +20 -13
@@ -867,6 +867,24 @@ static int atif_ioctl(int cmd, void __user *arg)return copy_to_user (arg, &atreq,sizeof (atreq)) ? -EFAULT :0 ; } +static int atrtr_ioctl_addrt (struct rtentry *rt) +{ +struct net_device *dev =NULL ; + +if (rt->rt_dev) { +char name[IFNAMSIZ ]; + +if (copy_from_user (name, rt->rt_dev,IFNAMSIZ -1 )) +return -EFAULT ; + name[IFNAMSIZ -1 ] ='\0' ; + + dev =__dev_get_by_name (&init_net, name); +if (!dev) +return -ENODEV ; + } +return atrtr_create (rt, dev); +} +/* Routing ioctl() calls */ static int atrtr_ioctl (unsigned int cmd,void __user *arg) {
@@ -882,19 +900,8 @@ static int atrtr_ioctl(unsigned int cmd, void __user *arg)return atrtr_delete (&((struct sockaddr_at *) &rt.rt_dst)->sat_addr); -case SIOCADDRT : { -struct net_device *dev =NULL ; -if (rt.rt_dev) { -char name[IFNAMSIZ ]; -if (copy_from_user (name, rt.rt_dev,IFNAMSIZ -1 )) -return -EFAULT ; - name[IFNAMSIZ -1 ] ='\0' ; - dev =__dev_get_by_name (&init_net, name); -if (!dev) -return -ENODEV ; - } -return atrtr_create (&rt, dev); - } +case SIOCADDRT : +return atrtr_ioctl_addrt (&rt); }return -EINVAL ; }
Signature · 1 line
2.26.2
PATCH 4/4 ipv4,appletalk: move SIOCADDRT and SIOCDELRT handling into ->compat_ioctl
In reply to Christoph HellwigTo prepare removing the global routing_ioctl hack start lifting the code into the ipv4 and appletalk ->compat_ioctl handlers. Unlike the existing handler we don't bother copying in the name - there are no compat issues for char arrays.
--- include/net/compat.h | 18 +++++++++++++ net/appletalk/ddp.c | 49 ++++++++++++++++++++++++++++++---- net/ipv4/af_inet.c | 38 ++++++++++++++++++++++----- net/socket.c | 62 -------------------------------------------- 4 files changed, 94 insertions(+), 73 deletions(-)
include/net/compat.h +18 -0
@@ -30,6 +30,24 @@ struct compat_cmsghdr { compat_int_t cmsg_type; }; +struct compat_rtentry { +u32 rt_pad1; +struct sockaddr rt_dst;/* target address */ +struct sockaddr rt_gateway;/* gateway addr (RTF_GATEWAY) */ +struct sockaddr rt_genmask;/* target network mask (IP) */ +unsigned short rt_flags; +short rt_pad2; +u32 rt_pad3; +unsigned char rt_tos; +unsigned char rt_class; +short rt_pad4; +short rt_metric;/* +1 for binary compatibility! */ +compat_uptr_t rt_dev;/* forcing the device at add */ +u32 rt_mtu;/* per route MTU/Window */ +u32 rt_window;/* Window clamping */ +unsigned short rt_irtt;/* Initial RTT */ +}; +#else /* defined(CONFIG_COMPAT) */ /* * To avoid compiler warnings:
net/appletalk/ddp.c +44 -5
70 lines not on this page · raw message
net/ipv4/af_inet.c +32 -6
@@ -116,6 +116,7 @@#include <linux/mroute.h> #endif #include <net/l3mdev.h> +#include <net/compat.h> #include <trace/events/sock.h>
@@ -968,17 +969,42 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)EXPORT_SYMBOL (inet_ioctl);#ifdef CONFIG_COMPAT +static int inet_compat_routing_ioctl (struct sock *sk,unsigned int cmd, +struct compat_rtentry __user *ur) +{ +struct rtentry rt; +compat_uptr_t rtdev; + +if (copy_from_user (&rt.rt_dst, &ur->rt_dst, +3 *sizeof (struct sockaddr )) || +get_user (rt.rt_flags, &ur->rt_flags) || +get_user (rt.rt_metric, &ur->rt_metric) || +get_user (rt.rt_mtu, &ur->rt_mtu) || +get_user (rt.rt_window, &ur->rt_window) || +get_user (rt.rt_irtt, &ur->rt_irtt) || +get_user (rtdev, &ur->rt_dev)) +return -EFAULT ; + + rt.rt_dev =compat_ptr (rtdev); +return ip_rt_ioctl (sock_net (sk), cmd, &rt); +} +static int inet_compat_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg) {struct sock *sk = sock->sk; -int err = -ENOIOCTLCMD ; - -if (sk->sk_prot->compat_ioctl) - err = sk->sk_prot->compat_ioctl (sk, cmd, arg); +void __user *argp =compat_ptr (arg); -return err; +switch (cmd) { +case SIOCADDRT : +case SIOCDELRT : +return inet_compat_routing_ioctl (sk, cmd, argp); +default : +if (!sk->sk_prot->compat_ioctl) +return -ENOIOCTLCMD ; +return sk->sk_prot->compat_ioctl (sk, cmd, arg); + } } -#endif +#endif /* CONFIG_COMPAT */ const struct proto_ops inet_stream_ops = { .family =PF_INET ,
net/socket.c +0 -62
74 lines not on this page · raw message
Signature · 1 line
2.26.2
David Miller
maintainerRe: [PATCH 4/4] ipv4,appletalk: move SIOCADDRT and SIOCDELRT handling into ->compat_ioctl
From: Christoph Hellwig <[email protected]>
Date: Thu, 14 May 2020 16:45:35 +0200
net/appletalk/ddp.c static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) · line 1848
Quoted 7 lines
#ifdef
CONFIG_COMPATnet/appletalk/ddp.c +6
-0+static int atalk_compat_routing_ioctl (struct sock *sk,unsigned int cmd, +struct compat_rtentry __user *ur) +{ +struct rtentry rt; +compat_uptr_t rtdev; +
Reverse christmas tree please.
net/appletalk/ddp.c static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) · line 1876
Quoted 4 lines
static int
atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg){net/appletalk/ddp.c +2
-0+struct sock *sk = sock->sk; +void __user *argp =compat_ptr (arg);
Likewise.
net/ipv4/af_inet.c int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) · line 976
Quoted 13 lines
net/ipv4/af_inet.c +5
-0@@ -968,17 +969,42 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)EXPORT_SYMBOL (inet_ioctl);#ifdef CONFIG_COMPAT +static int inet_compat_routing_ioctl (struct sock *sk,unsigned int cmd, +struct compat_rtentry __user *ur) +{ +struct rtentry rt; +compat_uptr_t rtdev;
Likewise.