62 #include <linux/socket.h>
64 #include <linux/net.h>
68 #include <linux/netdevice.h>
72 #include <linux/wanrouter.h>
73 #include <linux/if_bridge.h>
74 #include <linux/if_frad.h>
75 #include <linux/if_vlan.h>
77 #include <linux/poll.h>
79 #include <linux/module.h>
86 #include <linux/audit.h>
87 #include <linux/wireless.h>
89 #include <linux/magic.h>
90 #include <linux/slab.h>
91 #include <linux/xattr.h>
93 #include <asm/uaccess.h>
94 #include <asm/unistd.h>
101 #include <linux/netfilter.h>
103 #include <linux/if_tun.h>
104 #include <linux/ipv6_route.h>
107 #include <linux/atalk.h>
109 static int sock_no_open(
struct inode *irrelevant,
struct file *dontcare);
111 unsigned long nr_segs, loff_t
pos);
113 unsigned long nr_segs, loff_t
pos);
117 static unsigned int sock_poll(
struct file *
file,
119 static long sock_ioctl(
struct file *
file,
unsigned int cmd,
unsigned long arg);
121 static long compat_sock_ioctl(
struct file *
file,
122 unsigned int cmd,
unsigned long arg);
124 static int sock_fasync(
int fd,
struct file *filp,
int on);
126 int offset,
size_t size, loff_t *ppos,
int more);
139 .aio_read = sock_aio_read,
140 .aio_write = sock_aio_write,
142 .unlocked_ioctl = sock_ioctl,
144 .compat_ioctl = compat_sock_ioctl,
147 .open = sock_no_open,
148 .release = sock_close,
149 .fasync = sock_fasync,
150 .sendpage = sock_sendpage,
152 .splice_read = sock_splice_read,
193 return audit_sockaddr(ulen, kaddr);
227 if (audit_sockaddr(klen, kaddr))
267 static void sock_destroy_inode(
struct inode *
inode)
278 static void init_once(
void *
foo)
285 static int init_inodecache(
void)
294 if (sock_inode_cachep ==
NULL)
300 .alloc_inode = sock_alloc_inode,
301 .destroy_inode = sock_destroy_inode,
315 .d_dname = sockfs_dname,
319 int flags,
const char *dev_name,
void *
data)
329 .mount = sockfs_mount,
359 }
else if (sock->
sk) {
360 name.
name = sock->
sk->sk_prot_creator->name;
369 SOCK_INODE(sock)->i_fop = &socket_file_ops;
390 struct file *newfile;
396 if (
likely(!IS_ERR(newfile))) {
402 return PTR_ERR(newfile);
407 if (file->
f_op == &socket_file_ops)
446 static struct socket *sockfd_lookup_light(
int fd,
int *err,
int *fput_needed)
457 fput_light(file, *fput_needed);
462 #define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname"
463 #define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)
464 #define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
468 const char *proto_name;
474 proto_name = dentry->
d_name.name;
475 proto_size =
strlen(proto_name);
479 if (proto_size + 1 > size)
482 strncpy(value, proto_name, proto_size + 1);
484 error = proto_size + 1;
520 .getxattr = sockfs_getxattr,
521 .listxattr = sockfs_listxattr,
532 static struct socket *sock_alloc(
void)
541 sock = SOCKET_I(inode);
548 inode->
i_op = &sockfs_inode_ops;
560 static int sock_no_open(
struct inode *irrelevant,
struct file *dontcare)
567 .open = sock_no_open,
585 sock->
ops->release(sock);
598 iput(SOCK_INODE(sock));
618 static inline int __sock_sendmsg_nosec(
struct kiocb *
iocb,
struct socket *sock,
621 struct sock_iocb *si = kiocb_to_siocb(iocb);
623 sock_update_classid(sock->
sk);
630 return sock->
ops->sendmsg(iocb, sock, msg, size);
633 static inline int __sock_sendmsg(
struct kiocb *iocb,
struct socket *sock,
634 struct msghdr *msg,
size_t size)
636 int err = security_socket_sendmsg(sock, msg, size);
638 return err ?: __sock_sendmsg_nosec(iocb, sock, msg, size);
647 init_sync_kiocb(&iocb,
NULL);
649 ret = __sock_sendmsg(&iocb, sock, msg, size);
656 static int sock_sendmsg_nosec(
struct socket *sock,
struct msghdr *msg,
size_t size)
662 init_sync_kiocb(&iocb,
NULL);
664 ret = __sock_sendmsg_nosec(&iocb, sock, msg, size);
671 struct kvec *vec,
size_t num,
size_t size)
692 *ts = ktime_to_timespec(kt);
713 if (need_software_tstamp && skb->
tstamp.
tv64 == 0)
714 __net_timestamp(skb);
716 if (need_software_tstamp) {
719 skb_get_timestamp(skb, &tv);
723 skb_get_timestampns(skb, &ts[0]);
725 sizeof(ts[0]), &ts[0]);
730 memset(ts, 0,
sizeof(ts));
733 skb_get_timestampns(skb, ts + 0);
738 ktime2ts(shhwtstamps->
syststamp, ts + 1))
741 ktime2ts(shhwtstamps->
hwtstamp, ts + 2))
766 static inline void sock_recv_drops(
struct msghdr *msg,
struct sock *
sk,
777 sock_recv_timestamp(msg, sk, skb);
778 sock_recv_drops(msg, sk, skb);
782 static inline int __sock_recvmsg_nosec(
struct kiocb *iocb,
struct socket *sock,
783 struct msghdr *msg,
size_t size,
int flags)
785 struct sock_iocb *si = kiocb_to_siocb(iocb);
787 sock_update_classid(sock->
sk);
795 return sock->
ops->recvmsg(iocb, sock, msg, size, flags);
798 static inline int __sock_recvmsg(
struct kiocb *iocb,
struct socket *sock,
799 struct msghdr *msg,
size_t size,
int flags)
801 int err = security_socket_recvmsg(sock, msg, size, flags);
803 return err ?: __sock_recvmsg_nosec(iocb, sock, msg, size, flags);
807 size_t size,
int flags)
813 init_sync_kiocb(&iocb,
NULL);
815 ret = __sock_recvmsg(&iocb, sock, msg, size, flags);
822 static int sock_recvmsg_nosec(
struct socket *sock,
struct msghdr *msg,
823 size_t size,
int flags)
829 init_sync_kiocb(&iocb,
NULL);
831 ret = __sock_recvmsg_nosec(&iocb, sock, msg, size, flags);
853 struct kvec *vec,
size_t num,
size_t size,
int flags)
870 static void sock_aio_dtor(
struct kiocb *iocb)
876 int offset,
size_t size, loff_t *ppos,
int more)
890 static ssize_t sock_splice_read(
struct file *file, loff_t *ppos,
899 sock_update_classid(sock->
sk);
901 return sock->
ops->splice_read(sock, ppos, pipe, len, flags);
907 if (!is_sync_kiocb(iocb)) {
920 struct file *file,
const struct iovec *iov,
921 unsigned long nr_segs)
927 for (i = 0; i < nr_segs; i++)
928 size += iov[i].iov_len;
938 return __sock_recvmsg(iocb, sock, msg, size, msg->
msg_flags);
942 unsigned long nr_segs, loff_t
pos)
953 x = alloc_sock_iocb(iocb, &siocb);
960 struct file *file,
const struct iovec *iov,
961 unsigned long nr_segs)
967 for (i = 0; i < nr_segs; i++)
968 size += iov[i].iov_len;
980 return __sock_sendmsg(iocb, sock, msg, size);
984 unsigned long nr_segs, loff_t pos)
991 x = alloc_sock_iocb(iocb, &siocb);
1009 br_ioctl_hook =
hook;
1020 vlan_ioctl_hook =
hook;
1026 static int (*dlci_ioctl_hook) (
unsigned int,
void __user *);
1031 dlci_ioctl_hook =
hook;
1036 static long sock_do_ioctl(
struct net *
net,
struct socket *sock,
1037 unsigned int cmd,
unsigned long arg)
1042 err = sock->
ops->ioctl(sock, cmd, arg);
1059 static long sock_ioctl(
struct file *file,
unsigned cmd,
unsigned long arg)
1073 #ifdef CONFIG_WEXT_CORE
1082 if (
get_user(pid, (
int __user *)argp))
1089 (
int __user *)argp);
1097 request_module(
"bridge");
1101 err = br_ioctl_hook(net, cmd, argp);
1107 if (!vlan_ioctl_hook)
1108 request_module(
"8021q");
1111 if (vlan_ioctl_hook)
1112 err = vlan_ioctl_hook(net, argp);
1118 if (!dlci_ioctl_hook)
1119 request_module(
"dlci");
1122 if (dlci_ioctl_hook)
1123 err = dlci_ioctl_hook(cmd, argp);
1127 err = sock_do_ioctl(net, sock, cmd, arg);
1138 err = security_socket_create(family, type, protocol, 1);
1142 sock = sock_alloc();
1149 err = security_socket_post_create(sock, family, type, protocol, 1);
1164 static unsigned int sock_poll(
struct file *file,
poll_table *
wait)
1172 return sock->
ops->poll(file, sock, wait);
1175 static int sock_mmap(
struct file *file,
struct vm_area_struct *vma)
1179 return sock->
ops->mmap(file, sock, vma);
1182 static int sock_close(
struct inode *inode,
struct file *filp)
1208 static int sock_fasync(
int fd,
struct file *filp,
int on)
1211 struct sock *sk = sock->
sk;
1275 if (family < 0 || family >=
NPROTO)
1295 err = security_socket_create(family, type, protocol, kern);
1304 sock = sock_alloc();
1313 #ifdef CONFIG_MODULES
1321 request_module(
"net-pf-%d", family);
1334 if (!try_module_get(pf->
owner))
1340 err = pf->
create(net, sock, protocol, kern);
1342 goto out_module_put;
1348 if (!try_module_get(sock->
ops->owner))
1349 goto out_module_busy;
1355 module_put(pf->
owner);
1356 err = security_socket_post_create(sock, family, type, protocol, kern);
1358 goto out_sock_release;
1367 module_put(pf->
owner);
1374 goto out_sock_release;
1402 flags =
type & ~SOCK_TYPE_MASK;
1408 flags = (flags & ~SOCK_NONBLOCK) |
O_NONBLOCK;
1432 int __user *, usockvec)
1434 struct socket *sock1, *sock2;
1436 struct file *newfile1, *newfile2;
1445 flags = (flags & ~SOCK_NONBLOCK) |
O_NONBLOCK;
1460 err = sock1->
ops->socketpair(sock1, sock2);
1462 goto out_release_both;
1467 goto out_release_both;
1473 goto out_release_both;
1478 err = PTR_ERR(newfile1);
1481 goto out_release_both;
1485 if (IS_ERR(newfile2)) {
1486 err = PTR_ERR(newfile2);
1494 audit_fd_pair(fd1, fd2);
1531 int err, fput_needed;
1533 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1537 err = security_socket_bind(sock,
1541 err = sock->
ops->bind(sock,
1545 fput_light(sock->
file, fput_needed);
1559 int err, fput_needed;
1562 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1564 somaxconn = sock_net(sock->
sk)->core.sysctl_somaxconn;
1565 if ((
unsigned int)
backlog > somaxconn)
1568 err = security_socket_listen(sock,
backlog);
1572 fput_light(sock->
file, fput_needed);
1590 int __user *, upeer_addrlen,
int, flags)
1593 struct file *newfile;
1594 int err, len, newfd, fput_needed;
1601 flags = (flags & ~SOCK_NONBLOCK) |
O_NONBLOCK;
1603 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1608 newsock = sock_alloc();
1613 newsock->
ops = sock->
ops;
1619 __module_get(newsock->
ops->owner);
1629 err = PTR_ERR(newfile);
1635 err = security_socket_accept(sock, newsock);
1639 err = sock->
ops->accept(sock, newsock, sock->
file->f_flags);
1643 if (upeer_sockaddr) {
1644 if (newsock->
ops->getname(newsock, (
struct sockaddr *)&address,
1649 err = move_addr_to_user(&address,
1650 len, upeer_sockaddr, upeer_addrlen);
1661 fput_light(sock->
file, fput_needed);
1671 int __user *, upeer_addrlen)
1673 return sys_accept4(fd, upeer_sockaddr, upeer_addrlen, 0);
1693 int err, fput_needed;
1695 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1703 security_socket_connect(sock, (
struct sockaddr *)&address, addrlen);
1707 err = sock->
ops->connect(sock, (
struct sockaddr *)&address, addrlen,
1708 sock->
file->f_flags);
1710 fput_light(sock->
file, fput_needed);
1721 int __user *, usockaddr_len)
1725 int len,
err, fput_needed;
1727 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1731 err = security_socket_getsockname(sock);
1735 err = sock->
ops->getname(sock, (
struct sockaddr *)&address, &len, 0);
1738 err = move_addr_to_user(&address, len, usockaddr, usockaddr_len);
1741 fput_light(sock->
file, fput_needed);
1752 int __user *, usockaddr_len)
1756 int len,
err, fput_needed;
1758 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1760 err = security_socket_getpeername(sock);
1762 fput_light(sock->
file, fput_needed);
1767 sock->
ops->getname(sock, (
struct sockaddr *)&address, &len,
1770 err = move_addr_to_user(&address, len, usockaddr,
1772 fput_light(sock->
file, fput_needed);
1796 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1821 fput_light(sock->
file, fput_needed);
1831 unsigned int, flags)
1844 int __user *, addr_len)
1855 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1872 err2 = move_addr_to_user(&address,
1878 fput_light(sock->
file, fput_needed);
1899 char __user *, optval,
int, optlen)
1901 int err, fput_needed;
1907 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1909 err = security_socket_setsockopt(sock,
level, optname);
1919 sock->
ops->setsockopt(sock,
level, optname, optval,
1922 fput_light(sock->
file, fput_needed);
1933 char __user *, optval,
int __user *, optlen)
1935 int err, fput_needed;
1938 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1940 err = security_socket_getsockopt(sock,
level, optname);
1950 sock->
ops->getsockopt(sock,
level, optname, optval,
1953 fput_light(sock->
file, fput_needed);
1964 int err, fput_needed;
1967 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1969 err = security_socket_shutdown(sock, how);
1971 err = sock->
ops->shutdown(sock, how);
1972 fput_light(sock->
file, fput_needed);
1980 #define COMPAT_MSG(msg, member) ((MSG_CMSG_COMPAT & flags) ? &msg##_compat->member : &msg->member)
1981 #define COMPAT_NAMELEN(msg) COMPAT_MSG(msg, msg_namelen)
1982 #define COMPAT_FLAGS(msg) COMPAT_MSG(msg, msg_flags)
1989 static int __sys_sendmsg(
struct socket *sock,
struct msghdr __user *msg,
1990 struct msghdr *msg_sys,
unsigned int flags,
1996 struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
1997 unsigned char ctl[
sizeof(
struct cmsghdr) + 20]
1998 __attribute__ ((aligned(sizeof(__kernel_size_t))));
2000 unsigned char *ctl_buf =
ctl;
2043 }
else if (ctl_len) {
2044 if (ctl_len >
sizeof(
ctl)) {
2046 if (ctl_buf ==
NULL)
2071 if (used_address && msg_sys->
msg_name &&
2075 err = sock_sendmsg_nosec(sock, msg_sys, total_len);
2083 if (used_address && err >= 0) {
2094 if (iov != iovstack)
2106 int fput_needed,
err;
2108 struct socket *sock = sockfd_lookup_light(fd, &err, &fput_needed);
2113 err = __sys_sendmsg(sock, msg, &msg_sys, flags,
NULL);
2115 fput_light(sock->
file, fput_needed);
2127 int fput_needed,
err, datagrams;
2132 struct used_address used_address;
2139 sock = sockfd_lookup_light(fd, &err, &fput_needed);
2148 while (datagrams < vlen) {
2150 err = __sys_sendmsg(sock, (
struct msghdr __user *)compat_entry,
2151 &msg_sys, flags, &used_address);
2154 err =
__put_user(err, &compat_entry->msg_len);
2157 err = __sys_sendmsg(sock, (
struct msghdr __user *)entry,
2158 &msg_sys, flags, &used_address);
2170 fput_light(sock->
file, fput_needed);
2180 unsigned int, vlen,
unsigned int, flags)
2185 static int __sys_recvmsg(
struct socket *sock,
struct msghdr __user *msg,
2186 struct msghdr *msg_sys,
unsigned int flags,
int nosec)
2190 struct iovec iovstack[UIO_FASTIOV];
2191 struct iovec *iov = iovstack;
2192 unsigned long cmsg_ptr;
2200 int __user *uaddr_len;
2239 err = (nosec ? sock_recvmsg_nosec :
sock_recvmsg)(sock, msg_sys,
2245 if (uaddr !=
NULL) {
2246 err = move_addr_to_user(&
addr,
2258 &msg_compat->msg_controllen);
2261 &msg->msg_controllen);
2267 if (iov != iovstack)
2278 unsigned int, flags)
2280 int fput_needed,
err;
2282 struct socket *sock = sockfd_lookup_light(fd, &err, &fput_needed);
2287 err = __sys_recvmsg(sock, msg, &msg_sys, flags, 0);
2289 fput_light(sock->
file, fput_needed);
2299 unsigned int flags,
struct timespec *timeout)
2301 int fput_needed,
err, datagrams;
2315 sock = sockfd_lookup_light(fd, &err, &fput_needed);
2319 err = sock_error(sock->
sk);
2326 while (datagrams < vlen) {
2331 err = __sys_recvmsg(sock, (
struct msghdr __user *)compat_entry,
2336 err =
__put_user(err, &compat_entry->msg_len);
2339 err = __sys_recvmsg(sock, (
struct msghdr __user *)entry,
2358 *timeout = timespec_sub(end_time, *timeout);
2359 if (timeout->
tv_sec < 0) {
2375 fput_light(sock->
file, fput_needed);
2380 if (datagrams != 0) {
2392 sock->
sk->sk_err = -
err;
2402 unsigned int, vlen,
unsigned int, flags,
2416 if (datagrams > 0 &&
2423 #ifdef __ARCH_WANT_SYS_SOCKETCALL
2425 #define AL(x) ((x) * sizeof(unsigned long))
2426 static const unsigned char nargs[21] = {
2446 unsigned long a0,
a1;
2454 if (len >
sizeof(a))
2461 audit_socketcall(nargs[call] /
sizeof(
unsigned long), a);
2481 (
int __user *)a[2], 0);
2486 (
int __user *)a[2]);
2491 (
int __user *)a[2]);
2497 err =
sys_send(a0, (
void __user *)a1, a[2], a[3]);
2500 err =
sys_sendto(a0, (
void __user *)a1, a[2], a[3],
2501 (
struct sockaddr __user *)a[4], a[5]);
2504 err =
sys_recv(a0, (
void __user *)a1, a[2], a[3]);
2509 (
int __user *)a[5]);
2520 (
int __user *)a[4]);
2537 (
int __user *)a[2], a[3]);
2567 spin_lock(&net_family_lock);
2569 lockdep_is_held(&net_family_lock)))
2575 spin_unlock(&net_family_lock);
2599 spin_lock(&net_family_lock);
2601 spin_unlock(&net_family_lock);
2609 static int __init sock_init(
void)
2634 if (IS_ERR(sock_mnt)) {
2635 err = PTR_ERR(sock_mnt);
2642 #ifdef CONFIG_NETFILTER
2646 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
2661 #ifdef CONFIG_PROC_FS
2662 void socket_seq_show(
struct seq_file *seq)
2668 counter +=
per_cpu(sockets_in_use, cpu);
2678 #ifdef CONFIG_COMPAT
2679 static int do_siocgstamp(
struct net *net,
struct socket *sock,
2680 unsigned int cmd,
void __user *
up)
2687 err = sock_do_ioctl(net, sock, cmd, (
unsigned long)&ktv);
2695 static int do_siocgstampns(
struct net *net,
struct socket *sock,
2696 unsigned int cmd,
void __user *up)
2703 err = sock_do_ioctl(net, sock, cmd, (
unsigned long)&kts);
2711 static int dev_ifname32(
struct net *net,
struct compat_ifreq __user *uifr32)
2713 struct ifreq __user *uifr;
2717 if (
copy_in_user(uifr, uifr32,
sizeof(
struct compat_ifreq)))
2724 if (
copy_in_user(uifr32, uifr,
sizeof(
struct compat_ifreq)))
2730 static int dev_ifconf(
struct net *net,
struct compat_ifconf __user *uifc32)
2732 struct compat_ifconf ifc32;
2734 struct ifconf __user *uifc;
2735 struct compat_ifreq __user *ifr32;
2736 struct ifreq __user *ifr;
2740 if (
copy_from_user(&ifc32, uifc32,
sizeof(
struct compat_ifconf)))
2743 memset(&ifc, 0,
sizeof(ifc));
2744 if (ifc32.ifcbuf == 0) {
2750 size_t len = ((ifc32.ifc_len /
sizeof(
struct compat_ifreq)) + 1) *
2751 sizeof(
struct ifreq);
2754 ifr = ifc.ifc_req = (
void __user *)(uifc + 1);
2755 ifr32 = compat_ptr(ifc32.ifcbuf);
2756 for (i = 0; i < ifc32.ifc_len; i +=
sizeof(
struct compat_ifreq)) {
2757 if (
copy_in_user(ifr, ifr32,
sizeof(
struct compat_ifreq)))
2774 ifr32 = compat_ptr(ifc32.ifcbuf);
2776 i +
sizeof(
struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len;
2777 i +=
sizeof(
struct compat_ifreq), j +=
sizeof(
struct ifreq)) {
2778 if (
copy_in_user(ifr32, ifr,
sizeof(
struct compat_ifreq)))
2784 if (ifc32.ifcbuf == 0) {
2789 i = ((i /
sizeof(
struct ifreq)) *
sizeof(
struct compat_ifreq));
2794 if (
copy_to_user(uifc32, &ifc32,
sizeof(
struct compat_ifconf)))
2800 static int ethtool_ioctl(
struct net *net,
struct compat_ifreq __user *ifr32)
2802 struct compat_ethtool_rxnfc __user *compat_rxnfc;
2803 bool convert_in =
false, convert_out =
false;
2806 struct ifreq __user *ifr;
2807 u32 rule_cnt = 0, actual_rule_cnt;
2812 if (
get_user(data, &ifr32->ifr_ifru.ifru_data))
2815 compat_rxnfc = compat_ptr(data);
2817 if (
get_user(ethcmd, &compat_rxnfc->cmd))
2828 if (
get_user(rule_cnt, &compat_rxnfc->rule_cnt))
2832 buf_size += rule_cnt *
sizeof(
u32);
2847 rxnfc = (
void *)ifr +
ALIGN(
sizeof(
struct ifreq), 8);
2852 if (
put_user(convert_in ? rxnfc : compat_ptr(data),
2861 sizeof(compat_rxnfc->fs.m_ext) !=
2863 sizeof(rxnfc->
fs.m_ext));
2865 offsetof(
struct compat_ethtool_rxnfc,
fs.location) -
2866 offsetof(
struct compat_ethtool_rxnfc,
fs.ring_cookie) !=
2871 (
void *)(&rxnfc->
fs.m_ext + 1) -
2874 &compat_rxnfc->fs.ring_cookie,
2875 (
void *)(&rxnfc->
fs.location + 1) -
2876 (
void *)&rxnfc->
fs.ring_cookie) ||
2888 (
const void *)(&rxnfc->
fs.m_ext + 1) -
2889 (
const void *)rxnfc) ||
2891 &rxnfc->
fs.ring_cookie,
2892 (
const void *)(&rxnfc->
fs.location + 1) -
2893 (
const void *)&rxnfc->
fs.ring_cookie) ||
2909 if (actual_rule_cnt < rule_cnt)
2910 rule_cnt = actual_rule_cnt;
2913 rule_cnt *
sizeof(
u32)))
2921 static int compat_siocwandev(
struct net *net,
struct compat_ifreq __user *uifr32)
2925 struct ifreq __user *uifr;
2928 if (
copy_in_user(uifr, uifr32,
sizeof(
struct compat_ifreq)))
2931 if (
get_user(uptr32, &uifr32->ifr_settings.ifs_ifsu))
2934 uptr = compat_ptr(uptr32);
2936 if (
put_user(uptr, &uifr->ifr_settings.ifs_ifsu.raw_hdlc))
2942 static int bond_ioctl(
struct net *net,
unsigned int cmd,
2943 struct compat_ifreq __user *ifr32)
2946 struct ifreq __user *uifr;
2973 if (
get_user(data, &ifr32->ifr_ifru.ifru_data))
2976 datap = compat_ptr(data);
2986 static int siocdevprivate_ioctl(
struct net *net,
unsigned int cmd,
2987 struct compat_ifreq __user *u_ifreq32)
2989 struct ifreq __user *u_ifreq64;
2991 void __user *data64;
2994 if (
copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
2997 if (
__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
2999 data64 = compat_ptr(data32);
3015 static int dev_ifsioc(
struct net *net,
struct socket *sock,
3016 unsigned int cmd,
struct compat_ifreq __user *uifr32)
3018 struct ifreq __user *uifr;
3025 err = sock_do_ioctl(net, sock, cmd, (
unsigned long)uifr);
3051 static int compat_sioc_ifmap(
struct net *net,
unsigned int cmd,
3052 struct compat_ifreq __user *uifr32)
3055 struct compat_ifmap __user *uifmap32;
3059 uifmap32 = &uifr32->ifr_ifru.ifru_map;
3061 err |=
__get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
3062 err |=
__get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
3063 err |=
__get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
3064 err |=
__get_user(ifr.ifr_map.irq, &uifmap32->irq);
3065 err |=
__get_user(ifr.ifr_map.dma, &uifmap32->dma);
3066 err |=
__get_user(ifr.ifr_map.port, &uifmap32->port);
3076 err =
copy_to_user(uifr32, &ifr,
sizeof(ifr.ifr_name));
3077 err |=
__put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
3078 err |=
__put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
3079 err |=
__put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
3080 err |=
__put_user(ifr.ifr_map.irq, &uifmap32->irq);
3081 err |=
__put_user(ifr.ifr_map.dma, &uifmap32->dma);
3082 err |=
__put_user(ifr.ifr_map.port, &uifmap32->port);
3089 static int compat_siocshwtstamp(
struct net *net,
struct compat_ifreq __user *uifr32)
3093 struct ifreq __user *uifr;
3096 if (
copy_in_user(uifr, uifr32,
sizeof(
struct compat_ifreq)))
3099 if (
get_user(uptr32, &uifr32->ifr_data))
3102 uptr = compat_ptr(uptr32);
3104 if (
put_user(uptr, &uifr->ifr_data))
3115 unsigned short rt_flags;
3118 unsigned char rt_tos;
3119 unsigned char rt_class;
3125 unsigned short rt_irtt;
3128 struct in6_rtmsg32 {
3141 static int routing_ioctl(
struct net *net,
struct socket *sock,
3142 unsigned int cmd,
void __user *argp)
3152 if (sock && sock->
sk && sock->
sk->sk_family ==
AF_INET6) {
3153 struct in6_rtmsg32 __user *ur6 = argp;
3157 ret |=
__get_user(
r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
3158 ret |=
__get_user(
r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
3159 ret |=
__get_user(
r6.rtmsg_metric, &(ur6->rtmsg_metric));
3161 ret |=
__get_user(
r6.rtmsg_flags, &(ur6->rtmsg_flags));
3162 ret |=
__get_user(
r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
3166 struct rtentry32 __user *ur4 = argp;
3177 r4.rt_dev = (
char __user
__force *)devname;
3191 ret = sock_do_ioctl(net, sock, cmd, (
unsigned long) r);
3213 static int compat_sock_ioctl_trans(
struct file *file,
struct socket *sock,
3214 unsigned int cmd,
unsigned long arg)
3216 void __user *argp = compat_ptr(arg);
3217 struct sock *sk = sock->
sk;
3218 struct net *net = sock_net(sk);
3221 return siocdevprivate_ioctl(net, cmd, argp);
3226 return old_bridge_ioctl(argp);
3228 return dev_ifname32(net, argp);
3230 return dev_ifconf(net, argp);
3234 return compat_siocwandev(net, argp);
3237 return compat_sioc_ifmap(net, cmd, argp);
3244 return bond_ioctl(net, cmd, argp);
3247 return routing_ioctl(net, sock, cmd, argp);
3249 return do_siocgstamp(net, sock, cmd, argp);
3251 return do_siocgstampns(net, sock, cmd, argp);
3253 return compat_siocshwtstamp(net, argp);
3265 return sock_ioctl(file, cmd, arg);
3300 return dev_ifsioc(net, sock, cmd, argp);
3306 return sock_do_ioctl(net, sock, cmd, arg);
3312 static long compat_sock_ioctl(
struct file *file,
unsigned int cmd,
3323 if (sock->
ops->compat_ioctl)
3324 ret = sock->
ops->compat_ioctl(sock, cmd, arg);
3328 ret = compat_wext_handle_ioctl(net, cmd, arg);
3331 ret = compat_sock_ioctl_trans(file, sock, cmd, arg);
3339 return sock->
ops->bind(sock, addr, addrlen);
3345 return sock->
ops->listen(sock, backlog);
3351 struct sock *sk = sock->
sk;
3359 err = sock->
ops->accept(sock, *newsock, flags);
3366 (*newsock)->ops = sock->
ops;
3367 __module_get((*newsock)->ops->owner);
3377 return sock->
ops->connect(sock, addr, addrlen, flags);
3384 return sock->
ops->getname(sock, addr, addrlen, 0);
3391 return sock->
ops->getname(sock, addr, addrlen, 1);
3396 char *optval,
int *optlen)
3399 char __user *uoptval;
3400 int __user *uoptlen;
3403 uoptval = (
char __user
__force *) optval;
3404 uoptlen = (
int __user
__force *) optlen;
3410 err = sock->
ops->getsockopt(sock, level, optname, uoptval,
3418 char *optval,
unsigned int optlen)
3421 char __user *uoptval;
3424 uoptval = (
char __user
__force *) optval;
3430 err = sock->
ops->setsockopt(sock, level, optname, uoptval,
3438 size_t size,
int flags)
3440 sock_update_classid(sock->
sk);
3442 if (sock->
ops->sendpage)
3443 return sock->
ops->sendpage(sock, page, offset, size, flags);
3455 err = sock->
ops->ioctl(sock, cmd, arg);
3464 return sock->
ops->shutdown(sock, how);