mirror of
https://github.com/torvalds/linux.git
synced 2024-11-01 17:51:43 +00:00
c6d409cfd0
From: Eric Dumazet <eric.dumazet@gmail.com> Date: Thu, 3 Jun 2010 04:29:41 +0000 Subject: [PATCH 2/3] net: net/socket.c and net/compat.c cleanups cleanup patch, to match modern coding style. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> --- net/compat.c | 47 ++++++++--------- net/socket.c | 165 ++++++++++++++++++++++++++++------------------------------ 2 files changed, 102 insertions(+), 110 deletions(-) diff --git a/net/compat.c b/net/compat.c index 1cf7590..63d260e 100644 --- a/net/compat.c +++ b/net/compat.c @@ -81,7 +81,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov, int tot_len; if (kern_msg->msg_namelen) { - if (mode==VERIFY_READ) { + if (mode == VERIFY_READ) { int err = move_addr_to_kernel(kern_msg->msg_name, kern_msg->msg_namelen, kern_address); @@ -354,7 +354,7 @@ static int do_set_attach_filter(struct socket *sock, int level, int optname, static int do_set_sock_timeout(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen) { - struct compat_timeval __user *up = (struct compat_timeval __user *) optval; + struct compat_timeval __user *up = (struct compat_timeval __user *)optval; struct timeval ktime; mm_segment_t old_fs; int err; @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level, return -EFAULT; old_fs = get_fs(); set_fs(KERNEL_DS); - err = sock_setsockopt(sock, level, optname, (char *) &ktime, sizeof(ktime)); + err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime)); set_fs(old_fs); return err; @@ -389,11 +389,10 @@ asmlinkage long compat_sys_setsockopt(int fd, int level, int optname, char __user *optval, unsigned int optlen) { int err; - struct socket *sock; + struct socket *sock = sockfd_lookup(fd, &err); - if ((sock = sockfd_lookup(fd, &err))!=NULL) - { - err = security_socket_setsockopt(sock,level,optname); + if (sock) { + err = security_socket_setsockopt(sock, level, optname); if (err) { sockfd_put(sock); return err; @@ -453,7 +452,7 @@ static int compat_sock_getsockopt(struct socket *sock, int level, int optname, int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp) { struct compat_timeval __user *ctv = - (struct compat_timeval __user*) userstamp; + (struct compat_timeval __user *) userstamp; int err = -ENOENT; struct timeval tv; @@ -477,7 +476,7 @@ EXPORT_SYMBOL(compat_sock_get_timestamp); int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp) { struct compat_timespec __user *ctv = - (struct compat_timespec __user*) userstamp; + (struct compat_timespec __user *) userstamp; int err = -ENOENT; struct timespec ts; @@ -502,12 +501,10 @@ asmlinkage long compat_sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen) { int err; - struct socket *sock; + struct socket *sock = sockfd_lookup(fd, &err); - if ((sock = sockfd_lookup(fd, &err))!=NULL) - { - err = security_socket_getsockopt(sock, level, - optname); + if (sock) { + err = security_socket_getsockopt(sock, level, optname); if (err) { sockfd_put(sock); return err; @@ -557,7 +554,7 @@ struct compat_group_filter { int compat_mc_setsockopt(struct sock *sock, int level, int optname, char __user *optval, unsigned int optlen, - int (*setsockopt)(struct sock *,int,int,char __user *,unsigned int)) + int (*setsockopt)(struct sock *, int, int, char __user *, unsigned int)) { char __user *koptval = optval; int koptlen = optlen; @@ -640,12 +637,11 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname, } return setsockopt(sock, level, optname, koptval, koptlen); } - EXPORT_SYMBOL(compat_mc_setsockopt); int compat_mc_getsockopt(struct sock *sock, int level, int optname, char __user *optval, int __user *optlen, - int (*getsockopt)(struct sock *,int,int,char __user *,int __user *)) + int (*getsockopt)(struct sock *, int, int, char __user *, int __user *)) { struct compat_group_filter __user *gf32 = (void *)optval; struct group_filter __user *kgf; @@ -681,7 +677,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname, __put_user(interface, &kgf->gf_interface) || __put_user(fmode, &kgf->gf_fmode) || __put_user(numsrc, &kgf->gf_numsrc) || - copy_in_user(&kgf->gf_group,&gf32->gf_group,sizeof(kgf->gf_group))) + copy_in_user(&kgf->gf_group, &gf32->gf_group, sizeof(kgf->gf_group))) return -EFAULT; err = getsockopt(sock, level, optname, (char __user *)kgf, koptlen); @@ -714,21 +710,22 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname, copylen = numsrc * sizeof(gf32->gf_slist[0]); if (copylen > klen) copylen = klen; - if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen)) + if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen)) return -EFAULT; } return err; } - EXPORT_SYMBOL(compat_mc_getsockopt); /* Argument list sizes for compat_sys_socketcall */ #define AL(x) ((x) * sizeof(u32)) -static unsigned char nas[20]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), - AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), - AL(6),AL(2),AL(5),AL(5),AL(3),AL(3), - AL(4),AL(5)}; +static unsigned char nas[20] = { + AL(0), AL(3), AL(3), AL(3), AL(2), AL(3), + AL(3), AL(3), AL(4), AL(4), AL(4), AL(6), + AL(6), AL(2), AL(5), AL(5), AL(3), AL(3), + AL(4), AL(5) +}; #undef AL asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags) @@ -827,7 +824,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args) compat_ptr(a[4]), compat_ptr(a[5])); break; case SYS_SHUTDOWN: - ret = sys_shutdown(a0,a1); + ret = sys_shutdown(a0, a1); break; case SYS_SETSOCKOPT: ret = compat_sys_setsockopt(a0, a1, a[2], diff --git a/net/socket.c b/net/socket.c index 367d547..b63c051 100644 --- a/net/socket.c +++ b/net/socket.c @@ -124,7 +124,7 @@ static int sock_fasync(int fd, struct file *filp, int on); static ssize_t sock_sendpage(struct file *file, struct page *page, int offset, size_t size, loff_t *ppos, int more); static ssize_t sock_splice_read(struct file *file, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, + struct pipe_inode_info *pipe, size_t len, unsigned int flags); /* @@ -162,7 +162,7 @@ static const struct net_proto_family *net_families[NPROTO] __read_mostly; * Statistics counters of the socket lists */ -static DEFINE_PER_CPU(int, sockets_in_use) = 0; +static DEFINE_PER_CPU(int, sockets_in_use); /* * Support routines. @@ -309,9 +309,9 @@ static int init_inodecache(void) } static const struct super_operations sockfs_ops = { - .alloc_inode = sock_alloc_inode, - .destroy_inode =sock_destroy_inode, - .statfs = simple_statfs, + .alloc_inode = sock_alloc_inode, + .destroy_inode = sock_destroy_inode, + .statfs = simple_statfs, }; static int sockfs_get_sb(struct file_system_type *fs_type, @@ -411,6 +411,7 @@ int sock_map_fd(struct socket *sock, int flags) return fd; } +EXPORT_SYMBOL(sock_map_fd); static struct socket *sock_from_file(struct file *file, int *err) { @@ -422,7 +423,7 @@ static struct socket *sock_from_file(struct file *file, int *err) } /** - * sockfd_lookup - Go from a file number to its socket slot + * sockfd_lookup - Go from a file number to its socket slot * @fd: file handle * @err: pointer to an error code return * @@ -450,6 +451,7 @@ struct socket *sockfd_lookup(int fd, int *err) fput(file); return sock; } +EXPORT_SYMBOL(sockfd_lookup); static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) { @@ -540,6 +542,7 @@ void sock_release(struct socket *sock) } sock->file = NULL; } +EXPORT_SYMBOL(sock_release); int sock_tx_timestamp(struct msghdr *msg, struct sock *sk, union skb_shared_tx *shtx) @@ -586,6 +589,7 @@ int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) ret = wait_on_sync_kiocb(&iocb); return ret; } +EXPORT_SYMBOL(sock_sendmsg); int kernel_sendmsg(struct socket *sock, struct msghdr *msg, struct kvec *vec, size_t num, size_t size) @@ -604,6 +608,7 @@ int kernel_sendmsg(struct socket *sock, struct msghdr *msg, set_fs(oldfs); return result; } +EXPORT_SYMBOL(kernel_sendmsg); static int ktime2ts(ktime_t kt, struct timespec *ts) { @@ -664,7 +669,6 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPING, sizeof(ts), &ts); } - EXPORT_SYMBOL_GPL(__sock_recv_timestamp); inline void sock_recv_drops(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) @@ -720,6 +724,7 @@ int sock_recvmsg(struct socket *sock, struct msghdr *msg, ret = wait_on_sync_kiocb(&iocb); return ret; } +EXPORT_SYMBOL(sock_recvmsg); static int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg, size_t size, int flags) @@ -752,6 +757,7 @@ int kernel_recvmsg(struct socket *sock, struct msghdr *msg, set_fs(oldfs); return result; } +EXPORT_SYMBOL(kernel_recvmsg); static void sock_aio_dtor(struct kiocb *iocb) { @@ -774,7 +780,7 @@ static ssize_t sock_sendpage(struct file *file, struct page *page, } static ssize_t sock_splice_read(struct file *file, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, + struct pipe_inode_info *pipe, size_t len, unsigned int flags) { struct socket *sock = file->private_data; @@ -887,7 +893,7 @@ static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov, */ static DEFINE_MUTEX(br_ioctl_mutex); -static int (*br_ioctl_hook) (struct net *, unsigned int cmd, void __user *arg) = NULL; +static int (*br_ioctl_hook) (struct net *, unsigned int cmd, void __user *arg); void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *)) { @@ -895,7 +901,6 @@ void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *)) br_ioctl_hook = hook; mutex_unlock(&br_ioctl_mutex); } - EXPORT_SYMBOL(brioctl_set); static DEFINE_MUTEX(vlan_ioctl_mutex); @@ -907,7 +912,6 @@ void vlan_ioctl_set(int (*hook) (struct net *, void __user *)) vlan_ioctl_hook = hook; mutex_unlock(&vlan_ioctl_mutex); } - EXPORT_SYMBOL(vlan_ioctl_set); static DEFINE_MUTEX(dlci_ioctl_mutex); @@ -919,7 +923,6 @@ void dlci_ioctl_set(int (*hook) (unsigned int, void __user *)) dlci_ioctl_hook = hook; mutex_unlock(&dlci_ioctl_mutex); } - EXPORT_SYMBOL(dlci_ioctl_set); static long sock_do_ioctl(struct net *net, struct socket *sock, @@ -1047,6 +1050,7 @@ out_release: sock = NULL; goto out; } +EXPORT_SYMBOL(sock_create_lite); /* No kernel lock held - perfect */ static unsigned int sock_poll(struct file *file, poll_table *wait) @@ -1147,6 +1151,7 @@ call_kill: rcu_read_unlock(); return 0; } +EXPORT_SYMBOL(sock_wake_async); static int __sock_create(struct net *net, int family, int type, int protocol, struct socket **res, int kern) @@ -1265,11 +1270,13 @@ int sock_create(int family, int type, int protocol, struct socket **res) { return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0); } +EXPORT_SYMBOL(sock_create); int sock_create_kern(int family, int type, int protocol, struct socket **res) { return __sock_create(&init_net, family, type, protocol, res, 1); } +EXPORT_SYMBOL(sock_create_kern); SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) { @@ -1474,7 +1481,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr, goto out; err = -ENFILE; - if (!(newsock = sock_alloc())) + newsock = sock_alloc(); + if (!newsock) goto out_put; newsock->type = sock->type; @@ -1861,8 +1869,7 @@ SYSCALL_DEFINE3(sendmsg, int, fd, struct msghdr __user *, msg, unsigned, flags) if (MSG_CMSG_COMPAT & flags) { if (get_compat_msghdr(&msg_sys, msg_compat)) return -EFAULT; - } - else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr))) + } else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr))) return -EFAULT; sock = sockfd_lookup_light(fd, &err, &fput_needed); @@ -1964,8 +1971,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg, if (MSG_CMSG_COMPAT & flags) { if (get_compat_msghdr(msg_sys, msg_compat)) return -EFAULT; - } - else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr))) + } else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr))) return -EFAULT; err = -EMSGSIZE; @@ -2191,10 +2197,10 @@ SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg, /* Argument list sizes for sys_socketcall */ #define AL(x) ((x) * sizeof(unsigned long)) static const unsigned char nargs[20] = { - AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), - AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), - AL(6),AL(2),AL(5),AL(5),AL(3),AL(3), - AL(4),AL(5) + AL(0), AL(3), AL(3), AL(3), AL(2), AL(3), + AL(3), AL(3), AL(4), AL(4), AL(4), AL(6), + AL(6), AL(2), AL(5), AL(5), AL(3), AL(3), + AL(4), AL(5) }; #undef AL @@ -2340,6 +2346,7 @@ int sock_register(const struct net_proto_family *ops) printk(KERN_INFO "NET: Registered protocol family %d\n", ops->family); return err; } +EXPORT_SYMBOL(sock_register); /** * sock_unregister - remove a protocol handler @@ -2366,6 +2373,7 @@ void sock_unregister(int family) printk(KERN_INFO "NET: Unregistered protocol family %d\n", family); } +EXPORT_SYMBOL(sock_unregister); static int __init sock_init(void) { @@ -2490,13 +2498,13 @@ static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32) ifc.ifc_req = NULL; uifc = compat_alloc_user_space(sizeof(struct ifconf)); } else { - size_t len =((ifc32.ifc_len / sizeof (struct compat_ifreq)) + 1) * - sizeof (struct ifreq); + size_t len = ((ifc32.ifc_len / sizeof(struct compat_ifreq)) + 1) * + sizeof(struct ifreq); uifc = compat_alloc_user_space(sizeof(struct ifconf) + len); ifc.ifc_len = len; ifr = ifc.ifc_req = (void __user *)(uifc + 1); ifr32 = compat_ptr(ifc32.ifcbuf); - for (i = 0; i < ifc32.ifc_len; i += sizeof (struct compat_ifreq)) { + for (i = 0; i < ifc32.ifc_len; i += sizeof(struct compat_ifreq)) { if (copy_in_user(ifr, ifr32, sizeof(struct compat_ifreq))) return -EFAULT; ifr++; @@ -2516,9 +2524,9 @@ static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32) ifr = ifc.ifc_req; ifr32 = compat_ptr(ifc32.ifcbuf); for (i = 0, j = 0; - i + sizeof (struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len; - i += sizeof (struct compat_ifreq), j += sizeof (struct ifreq)) { - if (copy_in_user(ifr32, ifr, sizeof (struct compat_ifreq))) + i + sizeof(struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len; + i += sizeof(struct compat_ifreq), j += sizeof(struct ifreq)) { + if (copy_in_user(ifr32, ifr, sizeof(struct compat_ifreq))) return -EFAULT; ifr32++; ifr++; @@ -2567,7 +2575,7 @@ static int compat_siocwandev(struct net *net, struct compat_ifreq __user *uifr32 compat_uptr_t uptr32; struct ifreq __user *uifr; - uifr = compat_alloc_user_space(sizeof (*uifr)); + uifr = compat_alloc_user_space(sizeof(*uifr)); if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq))) return -EFAULT; @@ -2601,9 +2609,9 @@ static int bond_ioctl(struct net *net, unsigned int cmd, return -EFAULT; old_fs = get_fs(); - set_fs (KERNEL_DS); + set_fs(KERNEL_DS); err = dev_ioctl(net, cmd, &kifr); - set_fs (old_fs); + set_fs(old_fs); return err; case SIOCBONDSLAVEINFOQUERY: @@ -2710,9 +2718,9 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd, return -EFAULT; old_fs = get_fs(); - set_fs (KERNEL_DS); + set_fs(KERNEL_DS); err = dev_ioctl(net, cmd, (void __user *)&ifr); - set_fs (old_fs); + set_fs(old_fs); if (cmd == SIOCGIFMAP && !err) { err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name)); @@ -2734,7 +2742,7 @@ static int compat_siocshwtstamp(struct net *net, struct compat_ifreq __user *uif compat_uptr_t uptr32; struct ifreq __user *uifr; - uifr = compat_alloc_user_space(sizeof (*uifr)); + uifr = compat_alloc_user_space(sizeof(*uifr)); if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq))) return -EFAULT; @@ -2750,20 +2758,20 @@ static int compat_siocshwtstamp(struct net *net, struct compat_ifreq __user *uif } struct rtentry32 { - u32 rt_pad1; + 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! */ + 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! */ /* char * */ u32 rt_dev; /* forcing the device at add */ - u32 rt_mtu; /* per route MTU/Window */ - u32 rt_window; /* Window clamping */ + u32 rt_mtu; /* per route MTU/Window */ + u32 rt_window; /* Window clamping */ unsigned short rt_irtt; /* Initial RTT */ }; @@ -2793,29 +2801,29 @@ static int routing_ioctl(struct net *net, struct socket *sock, if (sock && sock->sk && sock->sk->sk_family == AF_INET6) { /* ipv6 */ struct in6_rtmsg32 __user *ur6 = argp; - ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst), + ret = copy_from_user(&r6.rtmsg_dst, &(ur6->rtmsg_dst), 3 * sizeof(struct in6_addr)); - ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type)); - ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len)); - ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len)); - ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric)); - ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info)); - ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags)); - ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex)); + ret |= __get_user(r6.rtmsg_type, &(ur6->rtmsg_type)); + ret |= __get_user(r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len)); + ret |= __get_user(r6.rtmsg_src_len, &(ur6->rtmsg_src_len)); + ret |= __get_user(r6.rtmsg_metric, &(ur6->rtmsg_metric)); + ret |= __get_user(r6.rtmsg_info, &(ur6->rtmsg_info)); + ret |= __get_user(r6.rtmsg_flags, &(ur6->rtmsg_flags)); + ret |= __get_user(r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex)); r = (void *) &r6; } else { /* ipv4 */ struct rtentry32 __user *ur4 = argp; - ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst), + ret = copy_from_user(&r4.rt_dst, &(ur4->rt_dst), 3 * sizeof(struct sockaddr)); - ret |= __get_user (r4.rt_flags, &(ur4->rt_flags)); - ret |= __get_user (r4.rt_metric, &(ur4->rt_metric)); - ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu)); - ret |= __get_user (r4.rt_window, &(ur4->rt_window)); - ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt)); - ret |= __get_user (rtdev, &(ur4->rt_dev)); + ret |= __get_user(r4.rt_flags, &(ur4->rt_flags)); + ret |= __get_user(r4.rt_metric, &(ur4->rt_metric)); + ret |= __get_user(r4.rt_mtu, &(ur4->rt_mtu)); + ret |= __get_user(r4.rt_window, &(ur4->rt_window)); + ret |= __get_user(r4.rt_irtt, &(ur4->rt_irtt)); + ret |= __get_user(rtdev, &(ur4->rt_dev)); if (rtdev) { - ret |= copy_from_user (devname, compat_ptr(rtdev), 15); + ret |= copy_from_user(devname, compat_ptr(rtdev), 15); r4.rt_dev = devname; devname[15] = 0; } else r4.rt_dev = NULL; @@ -2828,9 +2836,9 @@ static int routing_ioctl(struct net *net, struct socket *sock, goto out; } - set_fs (KERNEL_DS); + set_fs(KERNEL_DS); ret = sock_do_ioctl(net, sock, cmd, (unsigned long) r); - set_fs (old_fs); + set_fs(old_fs); out: return ret; @@ -2993,11 +3001,13 @@ int kernel_bind(struct socket *sock, struct sockaddr *addr, int addrlen) { return sock->ops->bind(sock, addr, addrlen); } +EXPORT_SYMBOL(kernel_bind); int kernel_listen(struct socket *sock, int backlog) { return sock->ops->listen(sock, backlog); } +EXPORT_SYMBOL(kernel_listen); int kernel_accept(struct socket *sock, struct socket **newsock, int flags) { @@ -3022,24 +3032,28 @@ int kernel_accept(struct socket *sock, struct socket **newsock, int flags) done: return err; } +EXPORT_SYMBOL(kernel_accept); int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen, int flags) { return sock->ops->connect(sock, addr, addrlen, flags); } +EXPORT_SYMBOL(kernel_connect); int kernel_getsockname(struct socket *sock, struct sockaddr *addr, int *addrlen) { return sock->ops->getname(sock, addr, addrlen, 0); } +EXPORT_SYMBOL(kernel_getsockname); int kernel_getpeername(struct socket *sock, struct sockaddr *addr, int *addrlen) { return sock->ops->getname(sock, addr, addrlen, 1); } +EXPORT_SYMBOL(kernel_getpeername); int kernel_getsockopt(struct socket *sock, int level, int optname, char *optval, int *optlen) @@ -3056,6 +3070,7 @@ int kernel_getsockopt(struct socket *sock, int level, int optname, set_fs(oldfs); return err; } +EXPORT_SYMBOL(kernel_getsockopt); int kernel_setsockopt(struct socket *sock, int level, int optname, char *optval, unsigned int optlen) @@ -3072,6 +3087,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname, set_fs(oldfs); return err; } +EXPORT_SYMBOL(kernel_setsockopt); int kernel_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags) @@ -3083,6 +3099,7 @@ int kernel_sendpage(struct socket *sock, struct page *page, int offset, return sock_no_sendpage(sock, page, offset, size, flags); } +EXPORT_SYMBOL(kernel_sendpage); int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg) { @@ -3095,33 +3112,11 @@ int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg) return err; } +EXPORT_SYMBOL(kernel_sock_ioctl); int kernel_sock_shutdown(struct socket *sock, enum sock_shutdown_cmd how) { return sock->ops->shutdown(sock, how); } - -EXPORT_SYMBOL(sock_create); -EXPORT_SYMBOL(sock_create_kern); -EXPORT_SYMBOL(sock_create_lite); -EXPORT_SYMBOL(sock_map_fd); -EXPORT_SYMBOL(sock_recvmsg); -EXPORT_SYMBOL(sock_register); -EXPORT_SYMBOL(sock_release); -EXPORT_SYMBOL(sock_sendmsg); -EXPORT_SYMBOL(sock_unregister); -EXPORT_SYMBOL(sock_wake_async); -EXPORT_SYMBOL(sockfd_lookup); -EXPORT_SYMBOL(kernel_sendmsg); -EXPORT_SYMBOL(kernel_recvmsg); -EXPORT_SYMBOL(kernel_bind); -EXPORT_SYMBOL(kernel_listen); -EXPORT_SYMBOL(kernel_accept); -EXPORT_SYMBOL(kernel_connect); -EXPORT_SYMBOL(kernel_getsockname); -EXPORT_SYMBOL(kernel_getpeername); -EXPORT_SYMBOL(kernel_getsockopt); -EXPORT_SYMBOL(kernel_setsockopt); -EXPORT_SYMBOL(kernel_sendpage); -EXPORT_SYMBOL(kernel_sock_ioctl); EXPORT_SYMBOL(kernel_sock_shutdown); + -- 1.7.0.4
856 lines
24 KiB
C
856 lines
24 KiB
C
/*
|
|
* 32bit Socket syscall emulation. Based on arch/sparc64/kernel/sys_sparc32.c.
|
|
*
|
|
* Copyright (C) 2000 VA Linux Co
|
|
* Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
|
|
* Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
|
|
* Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
|
|
* Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
|
|
* Copyright (C) 2000 Hewlett-Packard Co.
|
|
* Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
|
|
* Copyright (C) 2000,2001 Andi Kleen, SuSE Labs
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/types.h>
|
|
#include <linux/file.h>
|
|
#include <linux/icmpv6.h>
|
|
#include <linux/socket.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/filter.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/security.h>
|
|
|
|
#include <net/scm.h>
|
|
#include <net/sock.h>
|
|
#include <net/ip.h>
|
|
#include <net/ipv6.h>
|
|
#include <asm/uaccess.h>
|
|
#include <net/compat.h>
|
|
|
|
static inline int iov_from_user_compat_to_kern(struct iovec *kiov,
|
|
struct compat_iovec __user *uiov32,
|
|
int niov)
|
|
{
|
|
int tot_len = 0;
|
|
|
|
while (niov > 0) {
|
|
compat_uptr_t buf;
|
|
compat_size_t len;
|
|
|
|
if (get_user(len, &uiov32->iov_len) ||
|
|
get_user(buf, &uiov32->iov_base)) {
|
|
tot_len = -EFAULT;
|
|
break;
|
|
}
|
|
tot_len += len;
|
|
kiov->iov_base = compat_ptr(buf);
|
|
kiov->iov_len = (__kernel_size_t) len;
|
|
uiov32++;
|
|
kiov++;
|
|
niov--;
|
|
}
|
|
return tot_len;
|
|
}
|
|
|
|
int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
|
|
{
|
|
compat_uptr_t tmp1, tmp2, tmp3;
|
|
|
|
if (!access_ok(VERIFY_READ, umsg, sizeof(*umsg)) ||
|
|
__get_user(tmp1, &umsg->msg_name) ||
|
|
__get_user(kmsg->msg_namelen, &umsg->msg_namelen) ||
|
|
__get_user(tmp2, &umsg->msg_iov) ||
|
|
__get_user(kmsg->msg_iovlen, &umsg->msg_iovlen) ||
|
|
__get_user(tmp3, &umsg->msg_control) ||
|
|
__get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
|
|
__get_user(kmsg->msg_flags, &umsg->msg_flags))
|
|
return -EFAULT;
|
|
kmsg->msg_name = compat_ptr(tmp1);
|
|
kmsg->msg_iov = compat_ptr(tmp2);
|
|
kmsg->msg_control = compat_ptr(tmp3);
|
|
return 0;
|
|
}
|
|
|
|
/* I've named the args so it is easy to tell whose space the pointers are in. */
|
|
int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
|
|
struct sockaddr *kern_address, int mode)
|
|
{
|
|
int tot_len;
|
|
|
|
if (kern_msg->msg_namelen) {
|
|
if (mode == VERIFY_READ) {
|
|
int err = move_addr_to_kernel(kern_msg->msg_name,
|
|
kern_msg->msg_namelen,
|
|
kern_address);
|
|
if (err < 0)
|
|
return err;
|
|
}
|
|
kern_msg->msg_name = kern_address;
|
|
} else
|
|
kern_msg->msg_name = NULL;
|
|
|
|
tot_len = iov_from_user_compat_to_kern(kern_iov,
|
|
(struct compat_iovec __user *)kern_msg->msg_iov,
|
|
kern_msg->msg_iovlen);
|
|
if (tot_len >= 0)
|
|
kern_msg->msg_iov = kern_iov;
|
|
|
|
return tot_len;
|
|
}
|
|
|
|
/* Bleech... */
|
|
#define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32))
|
|
|
|
#define CMSG_COMPAT_DATA(cmsg) \
|
|
((void __user *)((char __user *)(cmsg) + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))))
|
|
#define CMSG_COMPAT_SPACE(len) \
|
|
(CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + CMSG_COMPAT_ALIGN(len))
|
|
#define CMSG_COMPAT_LEN(len) \
|
|
(CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + (len))
|
|
|
|
#define CMSG_COMPAT_FIRSTHDR(msg) \
|
|
(((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
|
|
(struct compat_cmsghdr __user *)((msg)->msg_control) : \
|
|
(struct compat_cmsghdr __user *)NULL)
|
|
|
|
#define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
|
|
((ucmlen) >= sizeof(struct compat_cmsghdr) && \
|
|
(ucmlen) <= (unsigned long) \
|
|
((mhdr)->msg_controllen - \
|
|
((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
|
|
|
|
static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
|
|
struct compat_cmsghdr __user *cmsg, int cmsg_len)
|
|
{
|
|
char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
|
|
if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
|
|
msg->msg_controllen)
|
|
return NULL;
|
|
return (struct compat_cmsghdr __user *)ptr;
|
|
}
|
|
|
|
/* There is a lot of hair here because the alignment rules (and
|
|
* thus placement) of cmsg headers and length are different for
|
|
* 32-bit apps. -DaveM
|
|
*/
|
|
int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk,
|
|
unsigned char *stackbuf, int stackbuf_size)
|
|
{
|
|
struct compat_cmsghdr __user *ucmsg;
|
|
struct cmsghdr *kcmsg, *kcmsg_base;
|
|
compat_size_t ucmlen;
|
|
__kernel_size_t kcmlen, tmp;
|
|
int err = -EFAULT;
|
|
|
|
kcmlen = 0;
|
|
kcmsg_base = kcmsg = (struct cmsghdr *)stackbuf;
|
|
ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
|
|
while (ucmsg != NULL) {
|
|
if (get_user(ucmlen, &ucmsg->cmsg_len))
|
|
return -EFAULT;
|
|
|
|
/* Catch bogons. */
|
|
if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg))
|
|
return -EINVAL;
|
|
|
|
tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) +
|
|
CMSG_ALIGN(sizeof(struct cmsghdr)));
|
|
tmp = CMSG_ALIGN(tmp);
|
|
kcmlen += tmp;
|
|
ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen);
|
|
}
|
|
if (kcmlen == 0)
|
|
return -EINVAL;
|
|
|
|
/* The kcmlen holds the 64-bit version of the control length.
|
|
* It may not be modified as we do not stick it into the kmsg
|
|
* until we have successfully copied over all of the data
|
|
* from the user.
|
|
*/
|
|
if (kcmlen > stackbuf_size)
|
|
kcmsg_base = kcmsg = sock_kmalloc(sk, kcmlen, GFP_KERNEL);
|
|
if (kcmsg == NULL)
|
|
return -ENOBUFS;
|
|
|
|
/* Now copy them over neatly. */
|
|
memset(kcmsg, 0, kcmlen);
|
|
ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
|
|
while (ucmsg != NULL) {
|
|
if (__get_user(ucmlen, &ucmsg->cmsg_len))
|
|
goto Efault;
|
|
if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg))
|
|
goto Einval;
|
|
tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) +
|
|
CMSG_ALIGN(sizeof(struct cmsghdr)));
|
|
if ((char *)kcmsg_base + kcmlen - (char *)kcmsg < CMSG_ALIGN(tmp))
|
|
goto Einval;
|
|
kcmsg->cmsg_len = tmp;
|
|
tmp = CMSG_ALIGN(tmp);
|
|
if (__get_user(kcmsg->cmsg_level, &ucmsg->cmsg_level) ||
|
|
__get_user(kcmsg->cmsg_type, &ucmsg->cmsg_type) ||
|
|
copy_from_user(CMSG_DATA(kcmsg),
|
|
CMSG_COMPAT_DATA(ucmsg),
|
|
(ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg)))))
|
|
goto Efault;
|
|
|
|
/* Advance. */
|
|
kcmsg = (struct cmsghdr *)((char *)kcmsg + tmp);
|
|
ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen);
|
|
}
|
|
|
|
/* Ok, looks like we made it. Hook it up and return success. */
|
|
kmsg->msg_control = kcmsg_base;
|
|
kmsg->msg_controllen = kcmlen;
|
|
return 0;
|
|
|
|
Einval:
|
|
err = -EINVAL;
|
|
Efault:
|
|
if (kcmsg_base != (struct cmsghdr *)stackbuf)
|
|
sock_kfree_s(sk, kcmsg_base, kcmlen);
|
|
return err;
|
|
}
|
|
|
|
int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
|
|
{
|
|
struct compat_timeval ctv;
|
|
struct compat_timespec cts[3];
|
|
struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
|
|
struct compat_cmsghdr cmhdr;
|
|
int cmlen;
|
|
|
|
if (cm == NULL || kmsg->msg_controllen < sizeof(*cm)) {
|
|
kmsg->msg_flags |= MSG_CTRUNC;
|
|
return 0; /* XXX: return error? check spec. */
|
|
}
|
|
|
|
if (level == SOL_SOCKET && type == SCM_TIMESTAMP) {
|
|
struct timeval *tv = (struct timeval *)data;
|
|
ctv.tv_sec = tv->tv_sec;
|
|
ctv.tv_usec = tv->tv_usec;
|
|
data = &ctv;
|
|
len = sizeof(ctv);
|
|
}
|
|
if (level == SOL_SOCKET &&
|
|
(type == SCM_TIMESTAMPNS || type == SCM_TIMESTAMPING)) {
|
|
int count = type == SCM_TIMESTAMPNS ? 1 : 3;
|
|
int i;
|
|
struct timespec *ts = (struct timespec *)data;
|
|
for (i = 0; i < count; i++) {
|
|
cts[i].tv_sec = ts[i].tv_sec;
|
|
cts[i].tv_nsec = ts[i].tv_nsec;
|
|
}
|
|
data = &cts;
|
|
len = sizeof(cts[0]) * count;
|
|
}
|
|
|
|
cmlen = CMSG_COMPAT_LEN(len);
|
|
if (kmsg->msg_controllen < cmlen) {
|
|
kmsg->msg_flags |= MSG_CTRUNC;
|
|
cmlen = kmsg->msg_controllen;
|
|
}
|
|
cmhdr.cmsg_level = level;
|
|
cmhdr.cmsg_type = type;
|
|
cmhdr.cmsg_len = cmlen;
|
|
|
|
if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
|
|
return -EFAULT;
|
|
if (copy_to_user(CMSG_COMPAT_DATA(cm), data, cmlen - sizeof(struct compat_cmsghdr)))
|
|
return -EFAULT;
|
|
cmlen = CMSG_COMPAT_SPACE(len);
|
|
if (kmsg->msg_controllen < cmlen)
|
|
cmlen = kmsg->msg_controllen;
|
|
kmsg->msg_control += cmlen;
|
|
kmsg->msg_controllen -= cmlen;
|
|
return 0;
|
|
}
|
|
|
|
void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
|
|
{
|
|
struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
|
|
int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
|
|
int fdnum = scm->fp->count;
|
|
struct file **fp = scm->fp->fp;
|
|
int __user *cmfptr;
|
|
int err = 0, i;
|
|
|
|
if (fdnum < fdmax)
|
|
fdmax = fdnum;
|
|
|
|
for (i = 0, cmfptr = (int __user *) CMSG_COMPAT_DATA(cm); i < fdmax; i++, cmfptr++) {
|
|
int new_fd;
|
|
err = security_file_receive(fp[i]);
|
|
if (err)
|
|
break;
|
|
err = get_unused_fd_flags(MSG_CMSG_CLOEXEC & kmsg->msg_flags
|
|
? O_CLOEXEC : 0);
|
|
if (err < 0)
|
|
break;
|
|
new_fd = err;
|
|
err = put_user(new_fd, cmfptr);
|
|
if (err) {
|
|
put_unused_fd(new_fd);
|
|
break;
|
|
}
|
|
/* Bump the usage count and install the file. */
|
|
get_file(fp[i]);
|
|
fd_install(new_fd, fp[i]);
|
|
}
|
|
|
|
if (i > 0) {
|
|
int cmlen = CMSG_COMPAT_LEN(i * sizeof(int));
|
|
err = put_user(SOL_SOCKET, &cm->cmsg_level);
|
|
if (!err)
|
|
err = put_user(SCM_RIGHTS, &cm->cmsg_type);
|
|
if (!err)
|
|
err = put_user(cmlen, &cm->cmsg_len);
|
|
if (!err) {
|
|
cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
|
|
kmsg->msg_control += cmlen;
|
|
kmsg->msg_controllen -= cmlen;
|
|
}
|
|
}
|
|
if (i < fdnum)
|
|
kmsg->msg_flags |= MSG_CTRUNC;
|
|
|
|
/*
|
|
* All of the files that fit in the message have had their
|
|
* usage counts incremented, so we just free the list.
|
|
*/
|
|
__scm_destroy(scm);
|
|
}
|
|
|
|
/*
|
|
* A struct sock_filter is architecture independent.
|
|
*/
|
|
struct compat_sock_fprog {
|
|
u16 len;
|
|
compat_uptr_t filter; /* struct sock_filter * */
|
|
};
|
|
|
|
static int do_set_attach_filter(struct socket *sock, int level, int optname,
|
|
char __user *optval, unsigned int optlen)
|
|
{
|
|
struct compat_sock_fprog __user *fprog32 = (struct compat_sock_fprog __user *)optval;
|
|
struct sock_fprog __user *kfprog = compat_alloc_user_space(sizeof(struct sock_fprog));
|
|
compat_uptr_t ptr;
|
|
u16 len;
|
|
|
|
if (!access_ok(VERIFY_READ, fprog32, sizeof(*fprog32)) ||
|
|
!access_ok(VERIFY_WRITE, kfprog, sizeof(struct sock_fprog)) ||
|
|
__get_user(len, &fprog32->len) ||
|
|
__get_user(ptr, &fprog32->filter) ||
|
|
__put_user(len, &kfprog->len) ||
|
|
__put_user(compat_ptr(ptr), &kfprog->filter))
|
|
return -EFAULT;
|
|
|
|
return sock_setsockopt(sock, level, optname, (char __user *)kfprog,
|
|
sizeof(struct sock_fprog));
|
|
}
|
|
|
|
static int do_set_sock_timeout(struct socket *sock, int level,
|
|
int optname, char __user *optval, unsigned int optlen)
|
|
{
|
|
struct compat_timeval __user *up = (struct compat_timeval __user *)optval;
|
|
struct timeval ktime;
|
|
mm_segment_t old_fs;
|
|
int err;
|
|
|
|
if (optlen < sizeof(*up))
|
|
return -EINVAL;
|
|
if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
|
|
__get_user(ktime.tv_sec, &up->tv_sec) ||
|
|
__get_user(ktime.tv_usec, &up->tv_usec))
|
|
return -EFAULT;
|
|
old_fs = get_fs();
|
|
set_fs(KERNEL_DS);
|
|
err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
|
|
set_fs(old_fs);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int compat_sock_setsockopt(struct socket *sock, int level, int optname,
|
|
char __user *optval, unsigned int optlen)
|
|
{
|
|
if (optname == SO_ATTACH_FILTER)
|
|
return do_set_attach_filter(sock, level, optname,
|
|
optval, optlen);
|
|
if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
|
|
return do_set_sock_timeout(sock, level, optname, optval, optlen);
|
|
|
|
return sock_setsockopt(sock, level, optname, optval, optlen);
|
|
}
|
|
|
|
asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
|
|
char __user *optval, unsigned int optlen)
|
|
{
|
|
int err;
|
|
struct socket *sock = sockfd_lookup(fd, &err);
|
|
|
|
if (sock) {
|
|
err = security_socket_setsockopt(sock, level, optname);
|
|
if (err) {
|
|
sockfd_put(sock);
|
|
return err;
|
|
}
|
|
|
|
if (level == SOL_SOCKET)
|
|
err = compat_sock_setsockopt(sock, level,
|
|
optname, optval, optlen);
|
|
else if (sock->ops->compat_setsockopt)
|
|
err = sock->ops->compat_setsockopt(sock, level,
|
|
optname, optval, optlen);
|
|
else
|
|
err = sock->ops->setsockopt(sock, level,
|
|
optname, optval, optlen);
|
|
sockfd_put(sock);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
static int do_get_sock_timeout(struct socket *sock, int level, int optname,
|
|
char __user *optval, int __user *optlen)
|
|
{
|
|
struct compat_timeval __user *up;
|
|
struct timeval ktime;
|
|
mm_segment_t old_fs;
|
|
int len, err;
|
|
|
|
up = (struct compat_timeval __user *) optval;
|
|
if (get_user(len, optlen))
|
|
return -EFAULT;
|
|
if (len < sizeof(*up))
|
|
return -EINVAL;
|
|
len = sizeof(ktime);
|
|
old_fs = get_fs();
|
|
set_fs(KERNEL_DS);
|
|
err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
|
|
set_fs(old_fs);
|
|
|
|
if (!err) {
|
|
if (put_user(sizeof(*up), optlen) ||
|
|
!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
|
|
__put_user(ktime.tv_sec, &up->tv_sec) ||
|
|
__put_user(ktime.tv_usec, &up->tv_usec))
|
|
err = -EFAULT;
|
|
}
|
|
return err;
|
|
}
|
|
|
|
static int compat_sock_getsockopt(struct socket *sock, int level, int optname,
|
|
char __user *optval, int __user *optlen)
|
|
{
|
|
if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
|
|
return do_get_sock_timeout(sock, level, optname, optval, optlen);
|
|
return sock_getsockopt(sock, level, optname, optval, optlen);
|
|
}
|
|
|
|
int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
|
|
{
|
|
struct compat_timeval __user *ctv =
|
|
(struct compat_timeval __user *) userstamp;
|
|
int err = -ENOENT;
|
|
struct timeval tv;
|
|
|
|
if (!sock_flag(sk, SOCK_TIMESTAMP))
|
|
sock_enable_timestamp(sk, SOCK_TIMESTAMP);
|
|
tv = ktime_to_timeval(sk->sk_stamp);
|
|
if (tv.tv_sec == -1)
|
|
return err;
|
|
if (tv.tv_sec == 0) {
|
|
sk->sk_stamp = ktime_get_real();
|
|
tv = ktime_to_timeval(sk->sk_stamp);
|
|
}
|
|
err = 0;
|
|
if (put_user(tv.tv_sec, &ctv->tv_sec) ||
|
|
put_user(tv.tv_usec, &ctv->tv_usec))
|
|
err = -EFAULT;
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(compat_sock_get_timestamp);
|
|
|
|
int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
|
|
{
|
|
struct compat_timespec __user *ctv =
|
|
(struct compat_timespec __user *) userstamp;
|
|
int err = -ENOENT;
|
|
struct timespec ts;
|
|
|
|
if (!sock_flag(sk, SOCK_TIMESTAMP))
|
|
sock_enable_timestamp(sk, SOCK_TIMESTAMP);
|
|
ts = ktime_to_timespec(sk->sk_stamp);
|
|
if (ts.tv_sec == -1)
|
|
return err;
|
|
if (ts.tv_sec == 0) {
|
|
sk->sk_stamp = ktime_get_real();
|
|
ts = ktime_to_timespec(sk->sk_stamp);
|
|
}
|
|
err = 0;
|
|
if (put_user(ts.tv_sec, &ctv->tv_sec) ||
|
|
put_user(ts.tv_nsec, &ctv->tv_nsec))
|
|
err = -EFAULT;
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(compat_sock_get_timestampns);
|
|
|
|
asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
|
|
char __user *optval, int __user *optlen)
|
|
{
|
|
int err;
|
|
struct socket *sock = sockfd_lookup(fd, &err);
|
|
|
|
if (sock) {
|
|
err = security_socket_getsockopt(sock, level, optname);
|
|
if (err) {
|
|
sockfd_put(sock);
|
|
return err;
|
|
}
|
|
|
|
if (level == SOL_SOCKET)
|
|
err = compat_sock_getsockopt(sock, level,
|
|
optname, optval, optlen);
|
|
else if (sock->ops->compat_getsockopt)
|
|
err = sock->ops->compat_getsockopt(sock, level,
|
|
optname, optval, optlen);
|
|
else
|
|
err = sock->ops->getsockopt(sock, level,
|
|
optname, optval, optlen);
|
|
sockfd_put(sock);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
struct compat_group_req {
|
|
__u32 gr_interface;
|
|
struct __kernel_sockaddr_storage gr_group
|
|
__attribute__ ((aligned(4)));
|
|
} __packed;
|
|
|
|
struct compat_group_source_req {
|
|
__u32 gsr_interface;
|
|
struct __kernel_sockaddr_storage gsr_group
|
|
__attribute__ ((aligned(4)));
|
|
struct __kernel_sockaddr_storage gsr_source
|
|
__attribute__ ((aligned(4)));
|
|
} __packed;
|
|
|
|
struct compat_group_filter {
|
|
__u32 gf_interface;
|
|
struct __kernel_sockaddr_storage gf_group
|
|
__attribute__ ((aligned(4)));
|
|
__u32 gf_fmode;
|
|
__u32 gf_numsrc;
|
|
struct __kernel_sockaddr_storage gf_slist[1]
|
|
__attribute__ ((aligned(4)));
|
|
} __packed;
|
|
|
|
#define __COMPAT_GF0_SIZE (sizeof(struct compat_group_filter) - \
|
|
sizeof(struct __kernel_sockaddr_storage))
|
|
|
|
|
|
int compat_mc_setsockopt(struct sock *sock, int level, int optname,
|
|
char __user *optval, unsigned int optlen,
|
|
int (*setsockopt)(struct sock *, int, int, char __user *, unsigned int))
|
|
{
|
|
char __user *koptval = optval;
|
|
int koptlen = optlen;
|
|
|
|
switch (optname) {
|
|
case MCAST_JOIN_GROUP:
|
|
case MCAST_LEAVE_GROUP:
|
|
{
|
|
struct compat_group_req __user *gr32 = (void *)optval;
|
|
struct group_req __user *kgr =
|
|
compat_alloc_user_space(sizeof(struct group_req));
|
|
u32 interface;
|
|
|
|
if (!access_ok(VERIFY_READ, gr32, sizeof(*gr32)) ||
|
|
!access_ok(VERIFY_WRITE, kgr, sizeof(struct group_req)) ||
|
|
__get_user(interface, &gr32->gr_interface) ||
|
|
__put_user(interface, &kgr->gr_interface) ||
|
|
copy_in_user(&kgr->gr_group, &gr32->gr_group,
|
|
sizeof(kgr->gr_group)))
|
|
return -EFAULT;
|
|
koptval = (char __user *)kgr;
|
|
koptlen = sizeof(struct group_req);
|
|
break;
|
|
}
|
|
case MCAST_JOIN_SOURCE_GROUP:
|
|
case MCAST_LEAVE_SOURCE_GROUP:
|
|
case MCAST_BLOCK_SOURCE:
|
|
case MCAST_UNBLOCK_SOURCE:
|
|
{
|
|
struct compat_group_source_req __user *gsr32 = (void *)optval;
|
|
struct group_source_req __user *kgsr = compat_alloc_user_space(
|
|
sizeof(struct group_source_req));
|
|
u32 interface;
|
|
|
|
if (!access_ok(VERIFY_READ, gsr32, sizeof(*gsr32)) ||
|
|
!access_ok(VERIFY_WRITE, kgsr,
|
|
sizeof(struct group_source_req)) ||
|
|
__get_user(interface, &gsr32->gsr_interface) ||
|
|
__put_user(interface, &kgsr->gsr_interface) ||
|
|
copy_in_user(&kgsr->gsr_group, &gsr32->gsr_group,
|
|
sizeof(kgsr->gsr_group)) ||
|
|
copy_in_user(&kgsr->gsr_source, &gsr32->gsr_source,
|
|
sizeof(kgsr->gsr_source)))
|
|
return -EFAULT;
|
|
koptval = (char __user *)kgsr;
|
|
koptlen = sizeof(struct group_source_req);
|
|
break;
|
|
}
|
|
case MCAST_MSFILTER:
|
|
{
|
|
struct compat_group_filter __user *gf32 = (void *)optval;
|
|
struct group_filter __user *kgf;
|
|
u32 interface, fmode, numsrc;
|
|
|
|
if (!access_ok(VERIFY_READ, gf32, __COMPAT_GF0_SIZE) ||
|
|
__get_user(interface, &gf32->gf_interface) ||
|
|
__get_user(fmode, &gf32->gf_fmode) ||
|
|
__get_user(numsrc, &gf32->gf_numsrc))
|
|
return -EFAULT;
|
|
koptlen = optlen + sizeof(struct group_filter) -
|
|
sizeof(struct compat_group_filter);
|
|
if (koptlen < GROUP_FILTER_SIZE(numsrc))
|
|
return -EINVAL;
|
|
kgf = compat_alloc_user_space(koptlen);
|
|
if (!access_ok(VERIFY_WRITE, kgf, koptlen) ||
|
|
__put_user(interface, &kgf->gf_interface) ||
|
|
__put_user(fmode, &kgf->gf_fmode) ||
|
|
__put_user(numsrc, &kgf->gf_numsrc) ||
|
|
copy_in_user(&kgf->gf_group, &gf32->gf_group,
|
|
sizeof(kgf->gf_group)) ||
|
|
(numsrc && copy_in_user(kgf->gf_slist, gf32->gf_slist,
|
|
numsrc * sizeof(kgf->gf_slist[0]))))
|
|
return -EFAULT;
|
|
koptval = (char __user *)kgf;
|
|
break;
|
|
}
|
|
|
|
default:
|
|
break;
|
|
}
|
|
return setsockopt(sock, level, optname, koptval, koptlen);
|
|
}
|
|
EXPORT_SYMBOL(compat_mc_setsockopt);
|
|
|
|
int compat_mc_getsockopt(struct sock *sock, int level, int optname,
|
|
char __user *optval, int __user *optlen,
|
|
int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
|
|
{
|
|
struct compat_group_filter __user *gf32 = (void *)optval;
|
|
struct group_filter __user *kgf;
|
|
int __user *koptlen;
|
|
u32 interface, fmode, numsrc;
|
|
int klen, ulen, err;
|
|
|
|
if (optname != MCAST_MSFILTER)
|
|
return getsockopt(sock, level, optname, optval, optlen);
|
|
|
|
koptlen = compat_alloc_user_space(sizeof(*koptlen));
|
|
if (!access_ok(VERIFY_READ, optlen, sizeof(*optlen)) ||
|
|
__get_user(ulen, optlen))
|
|
return -EFAULT;
|
|
|
|
/* adjust len for pad */
|
|
klen = ulen + sizeof(*kgf) - sizeof(*gf32);
|
|
|
|
if (klen < GROUP_FILTER_SIZE(0))
|
|
return -EINVAL;
|
|
|
|
if (!access_ok(VERIFY_WRITE, koptlen, sizeof(*koptlen)) ||
|
|
__put_user(klen, koptlen))
|
|
return -EFAULT;
|
|
|
|
/* have to allow space for previous compat_alloc_user_space, too */
|
|
kgf = compat_alloc_user_space(klen+sizeof(*optlen));
|
|
|
|
if (!access_ok(VERIFY_READ, gf32, __COMPAT_GF0_SIZE) ||
|
|
__get_user(interface, &gf32->gf_interface) ||
|
|
__get_user(fmode, &gf32->gf_fmode) ||
|
|
__get_user(numsrc, &gf32->gf_numsrc) ||
|
|
__put_user(interface, &kgf->gf_interface) ||
|
|
__put_user(fmode, &kgf->gf_fmode) ||
|
|
__put_user(numsrc, &kgf->gf_numsrc) ||
|
|
copy_in_user(&kgf->gf_group, &gf32->gf_group, sizeof(kgf->gf_group)))
|
|
return -EFAULT;
|
|
|
|
err = getsockopt(sock, level, optname, (char __user *)kgf, koptlen);
|
|
if (err)
|
|
return err;
|
|
|
|
if (!access_ok(VERIFY_READ, koptlen, sizeof(*koptlen)) ||
|
|
__get_user(klen, koptlen))
|
|
return -EFAULT;
|
|
|
|
ulen = klen - (sizeof(*kgf)-sizeof(*gf32));
|
|
|
|
if (!access_ok(VERIFY_WRITE, optlen, sizeof(*optlen)) ||
|
|
__put_user(ulen, optlen))
|
|
return -EFAULT;
|
|
|
|
if (!access_ok(VERIFY_READ, kgf, klen) ||
|
|
!access_ok(VERIFY_WRITE, gf32, ulen) ||
|
|
__get_user(interface, &kgf->gf_interface) ||
|
|
__get_user(fmode, &kgf->gf_fmode) ||
|
|
__get_user(numsrc, &kgf->gf_numsrc) ||
|
|
__put_user(interface, &gf32->gf_interface) ||
|
|
__put_user(fmode, &gf32->gf_fmode) ||
|
|
__put_user(numsrc, &gf32->gf_numsrc))
|
|
return -EFAULT;
|
|
if (numsrc) {
|
|
int copylen;
|
|
|
|
klen -= GROUP_FILTER_SIZE(0);
|
|
copylen = numsrc * sizeof(gf32->gf_slist[0]);
|
|
if (copylen > klen)
|
|
copylen = klen;
|
|
if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen))
|
|
return -EFAULT;
|
|
}
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(compat_mc_getsockopt);
|
|
|
|
|
|
/* Argument list sizes for compat_sys_socketcall */
|
|
#define AL(x) ((x) * sizeof(u32))
|
|
static unsigned char nas[20] = {
|
|
AL(0), AL(3), AL(3), AL(3), AL(2), AL(3),
|
|
AL(3), AL(3), AL(4), AL(4), AL(4), AL(6),
|
|
AL(6), AL(2), AL(5), AL(5), AL(3), AL(3),
|
|
AL(4), AL(5)
|
|
};
|
|
#undef AL
|
|
|
|
asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags)
|
|
{
|
|
return sys_sendmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
|
|
}
|
|
|
|
asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg, unsigned int flags)
|
|
{
|
|
return sys_recvmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
|
|
}
|
|
|
|
asmlinkage long compat_sys_recv(int fd, void __user *buf, size_t len, unsigned flags)
|
|
{
|
|
return sys_recv(fd, buf, len, flags | MSG_CMSG_COMPAT);
|
|
}
|
|
|
|
asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, size_t len,
|
|
unsigned flags, struct sockaddr __user *addr,
|
|
int __user *addrlen)
|
|
{
|
|
return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen);
|
|
}
|
|
|
|
asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
|
|
unsigned vlen, unsigned int flags,
|
|
struct compat_timespec __user *timeout)
|
|
{
|
|
int datagrams;
|
|
struct timespec ktspec;
|
|
|
|
if (timeout == NULL)
|
|
return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
|
|
flags | MSG_CMSG_COMPAT, NULL);
|
|
|
|
if (get_compat_timespec(&ktspec, timeout))
|
|
return -EFAULT;
|
|
|
|
datagrams = __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
|
|
flags | MSG_CMSG_COMPAT, &ktspec);
|
|
if (datagrams > 0 && put_compat_timespec(&ktspec, timeout))
|
|
datagrams = -EFAULT;
|
|
|
|
return datagrams;
|
|
}
|
|
|
|
asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
|
|
{
|
|
int ret;
|
|
u32 a[6];
|
|
u32 a0, a1;
|
|
|
|
if (call < SYS_SOCKET || call > SYS_RECVMMSG)
|
|
return -EINVAL;
|
|
if (copy_from_user(a, args, nas[call]))
|
|
return -EFAULT;
|
|
a0 = a[0];
|
|
a1 = a[1];
|
|
|
|
switch (call) {
|
|
case SYS_SOCKET:
|
|
ret = sys_socket(a0, a1, a[2]);
|
|
break;
|
|
case SYS_BIND:
|
|
ret = sys_bind(a0, compat_ptr(a1), a[2]);
|
|
break;
|
|
case SYS_CONNECT:
|
|
ret = sys_connect(a0, compat_ptr(a1), a[2]);
|
|
break;
|
|
case SYS_LISTEN:
|
|
ret = sys_listen(a0, a1);
|
|
break;
|
|
case SYS_ACCEPT:
|
|
ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), 0);
|
|
break;
|
|
case SYS_GETSOCKNAME:
|
|
ret = sys_getsockname(a0, compat_ptr(a1), compat_ptr(a[2]));
|
|
break;
|
|
case SYS_GETPEERNAME:
|
|
ret = sys_getpeername(a0, compat_ptr(a1), compat_ptr(a[2]));
|
|
break;
|
|
case SYS_SOCKETPAIR:
|
|
ret = sys_socketpair(a0, a1, a[2], compat_ptr(a[3]));
|
|
break;
|
|
case SYS_SEND:
|
|
ret = sys_send(a0, compat_ptr(a1), a[2], a[3]);
|
|
break;
|
|
case SYS_SENDTO:
|
|
ret = sys_sendto(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), a[5]);
|
|
break;
|
|
case SYS_RECV:
|
|
ret = compat_sys_recv(a0, compat_ptr(a1), a[2], a[3]);
|
|
break;
|
|
case SYS_RECVFROM:
|
|
ret = compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3],
|
|
compat_ptr(a[4]), compat_ptr(a[5]));
|
|
break;
|
|
case SYS_SHUTDOWN:
|
|
ret = sys_shutdown(a0, a1);
|
|
break;
|
|
case SYS_SETSOCKOPT:
|
|
ret = compat_sys_setsockopt(a0, a1, a[2],
|
|
compat_ptr(a[3]), a[4]);
|
|
break;
|
|
case SYS_GETSOCKOPT:
|
|
ret = compat_sys_getsockopt(a0, a1, a[2],
|
|
compat_ptr(a[3]), compat_ptr(a[4]));
|
|
break;
|
|
case SYS_SENDMSG:
|
|
ret = compat_sys_sendmsg(a0, compat_ptr(a1), a[2]);
|
|
break;
|
|
case SYS_RECVMSG:
|
|
ret = compat_sys_recvmsg(a0, compat_ptr(a1), a[2]);
|
|
break;
|
|
case SYS_RECVMMSG:
|
|
ret = compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3],
|
|
compat_ptr(a[4]));
|
|
break;
|
|
case SYS_ACCEPT4:
|
|
ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]);
|
|
break;
|
|
default:
|
|
ret = -EINVAL;
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|