Commit 19acc9c5 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'move-the-SIOCDELRT-and-SIOCADDRT-compat_ioctl-handlers-v3'



Christoph Hellwig says:

====================
move the SIOCDELRT and SIOCADDRT compat_ioctl handlers v3

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.

Changes since v3:
 - moar variable reordering

Changes since v1:
 - reorder a bunch of variable declarations
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a307593a dc13c876
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,24 @@ struct compat_cmsghdr {
	compat_int_t	cmsg_type;
	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) */
#else /* defined(CONFIG_COMPAT) */
/*
/*
 * To avoid compiler warnings:
 * To avoid compiler warnings:
+2 −1
Original line number Original line Diff line number Diff line
@@ -118,7 +118,8 @@ void ip6_route_init_special_entries(void);
int ip6_route_init(void);
int ip6_route_init(void);
void ip6_route_cleanup(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,
int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,
		  struct netlink_ext_ack *extack);
		  struct netlink_ext_ack *extack);
+2 −0
Original line number Original line Diff line number Diff line
@@ -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 inet6_getname(struct socket *sock, struct sockaddr *uaddr,
		  int peer);
		  int peer);
int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
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,
int inet6_hash_connect(struct inet_timewait_death_row *death_row,
			      struct sock *sk);
			      struct sock *sk);
+64 −18
Original line number Original line Diff line number Diff line
@@ -57,6 +57,7 @@
#include <net/sock.h>
#include <net/sock.h>
#include <net/tcp_states.h>
#include <net/tcp_states.h>
#include <net/route.h>
#include <net/route.h>
#include <net/compat.h>
#include <linux/atalk.h>
#include <linux/atalk.h>
#include <linux/highmem.h>
#include <linux/highmem.h>


@@ -867,6 +868,24 @@ static int atif_ioctl(int cmd, void __user *arg)
	return copy_to_user(arg, &atreq, sizeof(atreq)) ? -EFAULT : 0;
	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 */
/* Routing ioctl() calls */
static int atrtr_ioctl(unsigned int cmd, void __user *arg)
static int atrtr_ioctl(unsigned int cmd, void __user *arg)
{
{
@@ -882,19 +901,8 @@ static int atrtr_ioctl(unsigned int cmd, void __user *arg)
		return atrtr_delete(&((struct sockaddr_at *)
		return atrtr_delete(&((struct sockaddr_at *)
				      &rt.rt_dst)->sat_addr);
				      &rt.rt_dst)->sat_addr);


	case SIOCADDRT: {
	case SIOCADDRT:
		struct net_device *dev = NULL;
		return atrtr_ioctl_addrt(&rt);
		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);
	}
	}
	}
	return -EINVAL;
	return -EINVAL;
}
}
@@ -1832,20 +1840,58 @@ static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)




#ifdef CONFIG_COMPAT
#ifdef CONFIG_COMPAT
static int atalk_compat_routing_ioctl(struct sock *sk, unsigned int cmd,
		struct compat_rtentry __user *ur)
{
	compat_uptr_t rtdev;
	struct rtentry rt;

	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;

	switch (cmd) {
	case SIOCDELRT:
		if (rt.rt_dst.sa_family != AF_APPLETALK)
			return -EINVAL;
		return atrtr_delete(&((struct sockaddr_at *)
				      &rt.rt_dst)->sat_addr);

	case SIOCADDRT:
		rt.rt_dev = compat_ptr(rtdev);
		return atrtr_ioctl_addrt(&rt);
	default:
		return -EINVAL;
	}
}
static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
{
{
	void __user *argp = compat_ptr(arg);
	struct sock *sk = sock->sk;

	switch (cmd) {
	case SIOCADDRT:
	case SIOCDELRT:
		return atalk_compat_routing_ioctl(sk, cmd, argp);
	/*
	/*
	 * SIOCATALKDIFADDR is a SIOCPROTOPRIVATE ioctl number, so we
	 * SIOCATALKDIFADDR is a SIOCPROTOPRIVATE ioctl number, so we
	 * cannot handle it in common code. The data we access if ifreq
	 * cannot handle it in common code. The data we access if ifreq
	 * here is compatible, so we can simply call the native
	 * here is compatible, so we can simply call the native
	 * handler.
	 * handler.
	 */
	 */
	if (cmd == SIOCATALKDIFADDR)
	case SIOCATALKDIFADDR:
		return atalk_ioctl(sock, cmd, (unsigned long)compat_ptr(arg));
		return atalk_ioctl(sock, cmd, (unsigned long)argp);

	default:
		return -ENOIOCTLCMD;
		return -ENOIOCTLCMD;
	}
	}
#endif
}
#endif /* CONFIG_COMPAT */




static const struct net_proto_family atalk_family_ops = {
static const struct net_proto_family atalk_family_ops = {
+1 −0
Original line number Original line Diff line number Diff line
@@ -1082,6 +1082,7 @@ static const struct proto_ops inet6_dccp_ops = {
	.mmap		   = sock_no_mmap,
	.mmap		   = sock_no_mmap,
	.sendpage	   = sock_no_sendpage,
	.sendpage	   = sock_no_sendpage,
#ifdef CONFIG_COMPAT
#ifdef CONFIG_COMPAT
	.compat_ioctl	   = inet6_compat_ioctl,
	.compat_setsockopt = compat_sock_common_setsockopt,
	.compat_setsockopt = compat_sock_common_setsockopt,
	.compat_getsockopt = compat_sock_common_getsockopt,
	.compat_getsockopt = compat_sock_common_getsockopt,
#endif
#endif
Loading