Lines Matching +full:kernel +full:- +full:family

1 // SPDX-License-Identifier: GPL-2.0-or-later
25 * Jeff Uphoff : Made max number of sockets command-line
34 * for NetROM and future kernel nfsd type
47 * protocol-independent
55 #include <linux/bpf-cgroup.h>
139 struct socket *sock = f->private_data; in sock_show_fdinfo()
140 const struct proto_ops *ops = READ_ONCE(sock->ops); in sock_show_fdinfo()
142 if (ops->show_fdinfo) in sock_show_fdinfo()
143 ops->show_fdinfo(m, sock); in sock_show_fdinfo()
231 * Move socket addresses back and forth across the kernel/user
236 * move_addr_to_kernel - copy a socket address into kernel space
238 * @kaddr: Address in kernel space
241 * The address is copied into kernel space. If the provided address is
242 * too long an error code of -EINVAL is returned. If the copy gives
243 * invalid addresses -EFAULT is returned. On a success 0 is returned.
249 return -EINVAL; in move_addr_to_kernel()
253 return -EFAULT; in move_addr_to_kernel()
258 * move_addr_to_user - copy an address to user space
259 * @kaddr: kernel space address
260 * @klen: length of address in kernel
265 * This is overwritten with the buffer space used. -EINVAL is returned
266 * if an overlong buffer is specified or a negative buffer size. -EFAULT
287 return -EINVAL; in move_addr_to_user()
290 return -ENOMEM; in move_addr_to_user()
292 return -EFAULT; in move_addr_to_user()
310 init_waitqueue_head(&ei->socket.wq.wait); in sock_alloc_inode()
311 ei->socket.wq.fasync_list = NULL; in sock_alloc_inode()
312 ei->socket.wq.flags = 0; in sock_alloc_inode()
314 ei->socket.state = SS_UNCONNECTED; in sock_alloc_inode()
315 ei->socket.flags = 0; in sock_alloc_inode()
316 ei->socket.ops = NULL; in sock_alloc_inode()
317 ei->socket.sk = NULL; in sock_alloc_inode()
318 ei->socket.file = NULL; in sock_alloc_inode()
320 return &ei->vfs_inode; in sock_alloc_inode()
335 inode_init_once(&ei->vfs_inode); in init_once()
362 d_inode(dentry)->i_ino); in sockfs_dname()
374 if (dentry->d_name.len + 1 > size) in sockfs_xattr_get()
375 return -ERANGE; in sockfs_xattr_get()
376 memcpy(value, dentry->d_name.name, dentry->d_name.len + 1); in sockfs_xattr_get()
378 return dentry->d_name.len + 1; in sockfs_xattr_get()
383 #define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
397 return -EAGAIN; in sockfs_security_xattr_set()
415 return -ENOMEM; in sockfs_init_fs_context()
416 ctx->ops = &sockfs_ops; in sockfs_init_fs_context()
417 ctx->dops = &sockfs_dentry_operations; in sockfs_init_fs_context()
418 ctx->xattr = sockfs_xattr_handlers; in sockfs_init_fs_context()
435 * and file struct implicitly stored in sock->file.
443 * with shared fd spaces, we cannot solve it inside kernel,
448 * sock_alloc_file - Bind a &socket to a &file
454 * in sock->file. If dname is %NULL, sets to "".
466 dname = sock->sk ? sock->sk->sk_prot_creator->name : ""; in sock_alloc_file()
476 file->f_mode |= FMODE_NOWAIT; in sock_alloc_file()
477 sock->file = file; in sock_alloc_file()
478 file->private_data = sock; in sock_alloc_file()
504 * sock_from_file - Return the &socket bounded to @file.
512 if (file->f_op == &socket_file_ops) in sock_from_file()
513 return file->private_data; /* set in sock_alloc_file */ in sock_from_file()
520 * sockfd_lookup - Go from a file number to its socket slot
539 *err = -EBADF; in sockfd_lookup()
545 *err = -ENOTSOCK; in sockfd_lookup()
557 *err = -EBADF; in sockfd_lookup_light()
564 *err = -ENOTSOCK; in sockfd_lookup_light()
582 return -ERANGE; in sockfs_listxattr()
590 return -ERANGE; in sockfs_listxattr()
603 if (!err && (iattr->ia_valid & ATTR_UID)) { in sockfs_setattr()
606 if (sock->sk) in sockfs_setattr()
607 sock->sk->sk_uid = iattr->ia_uid; in sockfs_setattr()
609 err = -ENOENT; in sockfs_setattr()
621 * sock_alloc - allocate a socket
633 inode = new_inode_pseudo(sock_mnt->mnt_sb); in sock_alloc()
639 inode->i_ino = get_next_ino(); in sock_alloc()
640 inode->i_mode = S_IFSOCK | S_IRWXUGO; in sock_alloc()
641 inode->i_uid = current_fsuid(); in sock_alloc()
642 inode->i_gid = current_fsgid(); in sock_alloc()
643 inode->i_op = &sockfs_inode_ops; in sock_alloc()
651 const struct proto_ops *ops = READ_ONCE(sock->ops); in __sock_release()
654 struct module *owner = ops->owner; in __sock_release()
658 ops->release(sock); in __sock_release()
659 sock->sk = NULL; in __sock_release()
662 sock->ops = NULL; in __sock_release()
666 if (sock->wq.fasync_list) in __sock_release()
669 if (!sock->file) { in __sock_release()
673 sock->file = NULL; in __sock_release()
677 * sock_release - close a socket
729 int ret = INDIRECT_CALL_INET(READ_ONCE(sock->ops)->sendmsg, inet6_sendmsg, in sock_sendmsg_nosec()
732 BUG_ON(ret == -EIOCBQUEUED); in sock_sendmsg_nosec()
735 call_trace_sock_send_length(sock->sk, ret, 0); in sock_sendmsg_nosec()
748 * sock_sendmsg - send a message through @sock
757 struct sockaddr_storage *save_addr = (struct sockaddr_storage *)msg->msg_name; in sock_sendmsg()
759 int save_len = msg->msg_namelen; in sock_sendmsg()
762 if (msg->msg_name) { in sock_sendmsg()
763 memcpy(&address, msg->msg_name, msg->msg_namelen); in sock_sendmsg()
764 msg->msg_name = &address; in sock_sendmsg()
768 msg->msg_name = save_addr; in sock_sendmsg()
769 msg->msg_namelen = save_len; in sock_sendmsg()
776 * kernel_sendmsg - send a message through @sock (kernel-space)
779 * @vec: kernel vec
790 iov_iter_kvec(&msg->msg_iter, ITER_SOURCE, vec, num, size); in kernel_sendmsg()
796 * kernel_sendmsg_locked - send a message through @sock (kernel-space)
811 struct socket *sock = sk->sk_socket; in kernel_sendmsg_locked()
812 const struct proto_ops *ops = READ_ONCE(sock->ops); in kernel_sendmsg_locked()
814 if (!ops->sendmsg_locked) in kernel_sendmsg_locked()
817 iov_iter_kvec(&msg->msg_iter, ITER_SOURCE, vec, num, size); in kernel_sendmsg_locked()
819 return ops->sendmsg_locked(sk, msg, msg_data_left(msg)); in kernel_sendmsg_locked()
830 return skb->pkt_type == PACKET_OUTGOING; in skb_is_err_queue()
843 return skb->tstamp && !false_tstamp && skb_is_err_queue(skb); in skb_is_swtx_tstamp()
848 bool cycles = READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_BIND_PHC; in get_timestamp()
856 *if_index = orig_dev->ifindex; in get_timestamp()
859 hwtstamp = shhwtstamps->hwtstamp; in get_timestamp()
881 if_index = orig_dev->ifindex; in put_ts_pktinfo()
886 ts_pktinfo.pkt_length = skb->len - skb_mac_offset(skb); in put_ts_pktinfo()
909 if (need_software_tstamp && skb->tstamp == 0) { in __sock_recv_timestamp()
947 tsflags = READ_ONCE(sk->sk_tsflags); in __sock_recv_timestamp()
952 ktime_to_timespec64_cond(skb->tstamp, tss.ts + 0)) in __sock_recv_timestamp()
961 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP_NETDEV) in __sock_recv_timestamp()
964 hwtstamp = shhwtstamps->hwtstamp; in __sock_recv_timestamp()
968 READ_ONCE(sk->sk_bind_phc)); in __sock_recv_timestamp()
984 if (skb_is_err_queue(skb) && skb->len && in __sock_recv_timestamp()
985 SKB_EXT_ERR(skb)->opt_stats) in __sock_recv_timestamp()
987 skb->len, skb->data); in __sock_recv_timestamp()
1000 if (!skb->wifi_acked_valid) in __sock_recv_wifi_status()
1003 ack = skb->wifi_acked; in __sock_recv_wifi_status()
1013 if (sock_flag(sk, SOCK_RXQ_OVFL) && skb && SOCK_SKB_CB(skb)->dropcount) in sock_recv_drops()
1015 sizeof(__u32), &SOCK_SKB_CB(skb)->dropcount); in sock_recv_drops()
1023 __u32 mark = skb->mark; in sock_recv_mark()
1051 int ret = INDIRECT_CALL_INET(READ_ONCE(sock->ops)->recvmsg, in sock_recvmsg_nosec()
1056 call_trace_sock_recv_length(sock->sk, ret, flags); in sock_recvmsg_nosec()
1061 * sock_recvmsg - receive a message from @sock
1078 * kernel_recvmsg - Receive a message from a socket (kernel space)
1096 msg->msg_control_is_user = false; in kernel_recvmsg()
1097 iov_iter_kvec(&msg->msg_iter, ITER_DEST, vec, num, size); in kernel_recvmsg()
1106 struct socket *sock = file->private_data; in sock_splice_read()
1109 ops = READ_ONCE(sock->ops); in sock_splice_read()
1110 if (unlikely(!ops->splice_read)) in sock_splice_read()
1113 return ops->splice_read(sock, ppos, pipe, len, flags); in sock_splice_read()
1118 struct socket *sock = file->private_data; in sock_splice_eof()
1121 ops = READ_ONCE(sock->ops); in sock_splice_eof()
1122 if (ops->splice_eof) in sock_splice_eof()
1123 ops->splice_eof(sock); in sock_splice_eof()
1128 struct file *file = iocb->ki_filp; in sock_read_iter()
1129 struct socket *sock = file->private_data; in sock_read_iter()
1134 if (file->f_flags & O_NONBLOCK || (iocb->ki_flags & IOCB_NOWAIT)) in sock_read_iter()
1137 if (iocb->ki_pos != 0) in sock_read_iter()
1138 return -ESPIPE; in sock_read_iter()
1150 struct file *file = iocb->ki_filp; in sock_write_iter()
1151 struct socket *sock = file->private_data; in sock_write_iter()
1156 if (iocb->ki_pos != 0) in sock_write_iter()
1157 return -ESPIPE; in sock_write_iter()
1159 if (file->f_flags & O_NONBLOCK || (iocb->ki_flags & IOCB_NOWAIT)) in sock_write_iter()
1162 if (sock->type == SOCK_SEQPACKET) in sock_write_iter()
1193 int err = -ENOPKG; in br_ioctl_call()
1220 const struct proto_ops *ops = READ_ONCE(sock->ops); in sock_do_ioctl()
1227 err = ops->ioctl(sock, cmd, arg); in sock_do_ioctl()
1233 if (err != -ENOIOCTLCMD) in sock_do_ioctl()
1237 return -ENOTTY; in sock_do_ioctl()
1240 return -EFAULT; in sock_do_ioctl()
1244 return -EFAULT; in sock_do_ioctl()
1251 * what to do with it - that's up to the protocol still.
1263 sock = file->private_data; in sock_ioctl()
1264 ops = READ_ONCE(sock->ops); in sock_ioctl()
1265 sk = sock->sk; in sock_ioctl()
1272 return -EFAULT; in sock_ioctl()
1276 return -EFAULT; in sock_ioctl()
1286 err = -EFAULT; in sock_ioctl()
1289 err = f_setown(sock->file, pid, 1); in sock_ioctl()
1293 err = put_user(f_getown(sock->file), in sock_ioctl()
1304 err = -ENOPKG; in sock_ioctl()
1314 err = -EPERM; in sock_ioctl()
1315 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in sock_ioctl()
1318 err = open_related_ns(&net->ns, get_net_ns); in sock_ioctl()
1322 if (!ops->gettstamp) { in sock_ioctl()
1323 err = -ENOIOCTLCMD; in sock_ioctl()
1326 err = ops->gettstamp(sock, argp, in sock_ioctl()
1332 if (!ops->gettstamp) { in sock_ioctl()
1333 err = -ENOIOCTLCMD; in sock_ioctl()
1336 err = ops->gettstamp(sock, argp, in sock_ioctl()
1353 * sock_create_lite - creates a socket
1354 * @family: protocol family (AF_INET, ...)
1365 int sock_create_lite(int family, int type, int protocol, struct socket **res) in sock_create_lite() argument
1370 err = security_socket_create(family, type, protocol, 1); in sock_create_lite()
1376 err = -ENOMEM; in sock_create_lite()
1380 sock->type = type; in sock_create_lite()
1381 err = security_socket_post_create(sock, family, type, protocol, 1); in sock_create_lite()
1395 /* No kernel lock held - perfect */
1398 struct socket *sock = file->private_data; in sock_poll()
1399 const struct proto_ops *ops = READ_ONCE(sock->ops); in sock_poll()
1402 if (!ops->poll) in sock_poll()
1405 if (sk_can_busy_loop(sock->sk)) { in sock_poll()
1408 sk_busy_loop(sock->sk, 1); in sock_poll()
1414 return ops->poll(file, sock, wait) | flag; in sock_poll()
1419 struct socket *sock = file->private_data; in sock_mmap()
1421 return READ_ONCE(sock->ops)->mmap(file, sock, vma); in sock_mmap()
1437 * 2. fasync_list is used under read_lock(&sk->sk_callback_lock)
1443 struct socket *sock = filp->private_data; in sock_fasync()
1444 struct sock *sk = sock->sk; in sock_fasync()
1445 struct socket_wq *wq = &sock->wq; in sock_fasync()
1448 return -EINVAL; in sock_fasync()
1451 fasync_helper(fd, filp, on, &wq->fasync_list); in sock_fasync()
1453 if (!wq->fasync_list) in sock_fasync()
1466 if (!wq || !wq->fasync_list) in sock_wake_async()
1467 return -1; in sock_wake_async()
1471 if (test_bit(SOCKWQ_ASYNC_WAITDATA, &wq->flags)) in sock_wake_async()
1475 if (!test_and_clear_bit(SOCKWQ_ASYNC_NOSPACE, &wq->flags)) in sock_wake_async()
1480 kill_fasync(&wq->fasync_list, SIGIO, band); in sock_wake_async()
1483 kill_fasync(&wq->fasync_list, SIGURG, band); in sock_wake_async()
1491 * __sock_create - creates a socket
1493 * @family: protocol family (AF_INET, ...)
1497 * @kern: boolean for kernel space sockets
1501 * be set to true if the socket resides in kernel space.
1505 int __sock_create(struct net *net, int family, int type, int protocol, in __sock_create() argument
1515 if (family < 0 || family >= NPROTO) in __sock_create()
1516 return -EAFNOSUPPORT; in __sock_create()
1518 return -EINVAL; in __sock_create()
1525 if (family == PF_INET && type == SOCK_PACKET) { in __sock_create()
1527 current->comm); in __sock_create()
1528 family = PF_PACKET; in __sock_create()
1531 err = security_socket_create(family, type, protocol, kern); in __sock_create()
1536 * Allocate the socket and allow the family to set things up. if in __sock_create()
1537 * the protocol is 0, the family is instructed to select an appropriate in __sock_create()
1543 return -ENFILE; /* Not exactly a match, but its the in __sock_create()
1547 sock->type = type; in __sock_create()
1553 * requested real, full-featured networking support upon configuration. in __sock_create()
1556 if (rcu_access_pointer(net_families[family]) == NULL) in __sock_create()
1557 request_module("net-pf-%d", family); in __sock_create()
1561 pf = rcu_dereference(net_families[family]); in __sock_create()
1562 err = -EAFNOSUPPORT; in __sock_create()
1567 * We will call the ->create function, that possibly is in a loadable in __sock_create()
1570 if (!try_module_get(pf->owner)) in __sock_create()
1576 err = pf->create(net, sock, protocol, kern); in __sock_create()
1578 /* ->create should release the allocated sock->sk object on error in __sock_create()
1581 sock->sk = NULL; in __sock_create()
1589 if (!try_module_get(sock->ops->owner)) in __sock_create()
1593 * Now that we're done with the ->create function, the [loadable] in __sock_create()
1596 module_put(pf->owner); in __sock_create()
1597 err = security_socket_post_create(sock, family, type, protocol, kern); in __sock_create()
1605 err = -EAFNOSUPPORT; in __sock_create()
1607 sock->ops = NULL; in __sock_create()
1608 module_put(pf->owner); in __sock_create()
1620 * sock_create - creates a socket
1621 * @family: protocol family (AF_INET, ...)
1630 int sock_create(int family, int type, int protocol, struct socket **res) in sock_create() argument
1632 return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0); in sock_create()
1637 * sock_create_kern - creates a socket (kernel space)
1639 * @family: protocol family (AF_INET, ...)
1648 int sock_create_kern(struct net *net, int family, int type, int protocol, struct socket **res) in sock_create_kern() argument
1650 return __sock_create(net, family, type, protocol, res, 1); in sock_create_kern()
1654 static struct socket *__sys_socket_create(int family, int type, int protocol) in __sys_socket_create() argument
1666 return ERR_PTR(-EINVAL); in __sys_socket_create()
1669 retval = sock_create(family, type, protocol, &sock); in __sys_socket_create()
1676 struct file *__sys_socket_file(int family, int type, int protocol) in __sys_socket_file() argument
1681 sock = __sys_socket_create(family, type, protocol); in __sys_socket_file()
1704 __weak noinline int update_socket_protocol(int family, int type, int protocol) in update_socket_protocol() argument
1711 int __sys_socket(int family, int type, int protocol) in __sys_socket() argument
1716 sock = __sys_socket_create(family, type, in __sys_socket()
1717 update_socket_protocol(family, type, protocol)); in __sys_socket()
1728 SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) in SYSCALL_DEFINE3() argument
1730 return __sys_socket(family, type, protocol); in SYSCALL_DEFINE3()
1737 int __sys_socketpair(int family, int type, int protocol, int __user *usockvec) in __sys_socketpair() argument
1746 return -EINVAL; in __sys_socketpair()
1779 err = sock_create(family, type, protocol, &sock1); in __sys_socketpair()
1783 err = sock_create(family, type, protocol, &sock2); in __sys_socketpair()
1796 err = READ_ONCE(sock1->ops)->socketpair(sock1, sock2); in __sys_socketpair()
1829 SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol, in SYSCALL_DEFINE4() argument
1832 return __sys_socketpair(family, type, protocol, usockvec); in SYSCALL_DEFINE4()
1843 err = READ_ONCE(sock->ops)->bind(sock, in __sys_bind_socket()
1853 * We move the socket address to kernel space before we call
1868 fput_light(sock->file, fput_needed); in __sys_bind()
1887 somaxconn = READ_ONCE(sock_net(sock->sk)->core.sysctl_somaxconn); in __sys_listen_socket()
1893 err = READ_ONCE(sock->ops)->listen(sock, backlog); in __sys_listen_socket()
1905 fput_light(sock->file, fput_needed); in __sys_listen()
1927 return ERR_PTR(-ENOTSOCK); in do_accept()
1931 return ERR_PTR(-ENFILE); in do_accept()
1932 ops = READ_ONCE(sock->ops); in do_accept()
1934 newsock->type = sock->type; in do_accept()
1935 newsock->ops = ops; in do_accept()
1939 * has the protocol module (sock->ops->owner) held. in do_accept()
1941 __module_get(ops->owner); in do_accept()
1943 newfile = sock_alloc_file(newsock, flags, sock->sk->sk_prot_creator->name); in do_accept()
1951 arg->flags |= sock->file->f_flags; in do_accept()
1952 err = ops->accept(sock, newsock, arg); in do_accept()
1957 len = ops->getname(newsock, (struct sockaddr *)&address, 2); in do_accept()
1959 err = -ECONNABORTED; in do_accept()
1983 return -EINVAL; in __sys_accept4_file()
2005 * connected fd. We collect the address of the connector in kernel
2017 int ret = -EBADF; in __sys_accept4()
2044 * is in user space so we verify it is OK and move it to kernel space.
2051 * include the -EINPROGRESS status for such sockets.
2062 err = -ENOTSOCK; in __sys_connect_file()
2071 err = READ_ONCE(sock->ops)->connect(sock, (struct sockaddr *)address, in __sys_connect_file()
2072 addrlen, sock->file->f_flags | file_flags); in __sys_connect_file()
2079 int ret = -EBADF; in __sys_connect()
2121 err = READ_ONCE(sock->ops)->getname(sock, (struct sockaddr *)&address, 0); in __sys_getsockname()
2128 fput_light(sock->file, fput_needed); in __sys_getsockname()
2153 const struct proto_ops *ops = READ_ONCE(sock->ops); in __sys_getpeername()
2157 fput_light(sock->file, fput_needed); in __sys_getpeername()
2161 err = ops->getname(sock, (struct sockaddr *)&address, 1); in __sys_getpeername()
2166 fput_light(sock->file, fput_needed); in __sys_getpeername()
2178 * Send a datagram to a given address. We move the address into kernel
2211 if (sock->file->f_flags & O_NONBLOCK) in __sys_sendto()
2217 fput_light(sock->file, fput_needed); in __sys_sendto()
2242 * sender address from kernel to user space.
2263 if (sock->file->f_flags & O_NONBLOCK) in __sys_recvfrom()
2274 fput_light(sock->file, fput_needed); in __sys_recvfrom()
2298 return test_bit(SOCK_CUSTOM_SOCKOPT, &sock->flags); in sock_use_custom_sol_socket()
2309 return -EINVAL; in do_sock_setsockopt()
2316 err = BPF_CGROUP_RUN_PROG_SETSOCKOPT(sock->sk, &level, &optname, in do_sock_setsockopt()
2328 ops = READ_ONCE(sock->ops); in do_sock_setsockopt()
2331 else if (unlikely(!ops->setsockopt)) in do_sock_setsockopt()
2332 err = -EOPNOTSUPP; in do_sock_setsockopt()
2334 err = ops->setsockopt(sock, level, optname, optval, in do_sock_setsockopt()
2359 fput_light(sock->file, fput_needed); in __sys_setsockopt()
2386 ops = READ_ONCE(sock->ops); in do_sock_getsockopt()
2388 err = sk_getsockopt(sock->sk, level, optname, optval, optlen); in do_sock_getsockopt()
2389 } else if (unlikely(!ops->getsockopt)) { in do_sock_getsockopt()
2390 err = -EOPNOTSUPP; in do_sock_getsockopt()
2394 return -EOPNOTSUPP; in do_sock_getsockopt()
2396 err = ops->getsockopt(sock, level, optname, optval.user, in do_sock_getsockopt()
2401 err = BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock->sk, level, optname, in do_sock_getsockopt()
2428 fput_light(sock->file, fput_needed); in __sys_getsockopt()
2448 err = READ_ONCE(sock->ops)->shutdown(sock, how); in __sys_shutdown_sock()
2461 fput_light(sock->file, fput_needed); in __sys_shutdown()
2474 #define COMPAT_MSG(msg, member) ((MSG_CMSG_COMPAT & flags) ? &msg##_compat->member : &msg->member)
2489 kmsg->msg_control_is_user = true; in __copy_msghdr()
2490 kmsg->msg_get_inq = 0; in __copy_msghdr()
2491 kmsg->msg_control_user = msg->msg_control; in __copy_msghdr()
2492 kmsg->msg_controllen = msg->msg_controllen; in __copy_msghdr()
2493 kmsg->msg_flags = msg->msg_flags; in __copy_msghdr()
2495 kmsg->msg_namelen = msg->msg_namelen; in __copy_msghdr()
2496 if (!msg->msg_name) in __copy_msghdr()
2497 kmsg->msg_namelen = 0; in __copy_msghdr()
2499 if (kmsg->msg_namelen < 0) in __copy_msghdr()
2500 return -EINVAL; in __copy_msghdr()
2502 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage)) in __copy_msghdr()
2503 kmsg->msg_namelen = sizeof(struct sockaddr_storage); in __copy_msghdr()
2506 *save_addr = msg->msg_name; in __copy_msghdr()
2508 if (msg->msg_name && kmsg->msg_namelen) { in __copy_msghdr()
2510 err = move_addr_to_kernel(msg->msg_name, in __copy_msghdr()
2511 kmsg->msg_namelen, in __copy_msghdr()
2512 kmsg->msg_name); in __copy_msghdr()
2517 kmsg->msg_name = NULL; in __copy_msghdr()
2518 kmsg->msg_namelen = 0; in __copy_msghdr()
2521 if (msg->msg_iovlen > UIO_MAXIOV) in __copy_msghdr()
2522 return -EMSGSIZE; in __copy_msghdr()
2524 kmsg->msg_iocb = NULL; in __copy_msghdr()
2525 kmsg->msg_ubuf = NULL; in __copy_msghdr()
2538 return -EFAULT; in copy_msghdr_from_user()
2546 UIO_FASTIOV, iov, &kmsg->msg_iter); in copy_msghdr_from_user()
2561 err = -ENOBUFS; in ____sys_sendmsg()
2563 if (msg_sys->msg_controllen > INT_MAX) in ____sys_sendmsg()
2565 flags |= (msg_sys->msg_flags & allowed_msghdr_flags); in ____sys_sendmsg()
2566 ctl_len = msg_sys->msg_controllen; in ____sys_sendmsg()
2569 cmsghdr_from_user_compat_to_kern(msg_sys, sock->sk, ctl, in ____sys_sendmsg()
2573 ctl_buf = msg_sys->msg_control; in ____sys_sendmsg()
2574 ctl_len = msg_sys->msg_controllen; in ____sys_sendmsg()
2579 ctl_buf = sock_kmalloc(sock->sk, ctl_len, GFP_KERNEL); in ____sys_sendmsg()
2583 err = -EFAULT; in ____sys_sendmsg()
2584 if (copy_from_user(ctl_buf, msg_sys->msg_control_user, ctl_len)) in ____sys_sendmsg()
2586 msg_sys->msg_control = ctl_buf; in ____sys_sendmsg()
2587 msg_sys->msg_control_is_user = false; in ____sys_sendmsg()
2590 msg_sys->msg_flags = flags; in ____sys_sendmsg()
2592 if (sock->file->f_flags & O_NONBLOCK) in ____sys_sendmsg()
2593 msg_sys->msg_flags |= MSG_DONTWAIT; in ____sys_sendmsg()
2597 * used_address->name_len is initialized to UINT_MAX so that the first in ____sys_sendmsg()
2600 if (used_address && msg_sys->msg_name && in ____sys_sendmsg()
2601 used_address->name_len == msg_sys->msg_namelen && in ____sys_sendmsg()
2602 !memcmp(&used_address->name, msg_sys->msg_name, in ____sys_sendmsg()
2603 used_address->name_len)) { in ____sys_sendmsg()
2613 used_address->name_len = msg_sys->msg_namelen; in ____sys_sendmsg()
2614 if (msg_sys->msg_name) in ____sys_sendmsg()
2615 memcpy(&used_address->name, msg_sys->msg_name, in ____sys_sendmsg()
2616 used_address->name_len); in ____sys_sendmsg()
2621 sock_kfree_s(sock->sk, ctl_buf, ctl_len); in ____sys_sendmsg()
2655 msg_sys->msg_name = &address; in ___sys_sendmsg()
2684 return -EINVAL; in __sys_sendmsg()
2692 fput_light(sock->file, fput_needed); in __sys_sendmsg()
2718 return -EINVAL; in __sys_sendmmsg()
2736 if (datagrams == vlen - 1) in __sys_sendmmsg()
2744 err = __put_user(err, &compat_entry->msg_len); in __sys_sendmmsg()
2752 err = put_user(err, &entry->msg_len); in __sys_sendmmsg()
2764 fput_light(sock->file, fput_needed); in __sys_sendmmsg()
2813 msg_sys->msg_name = &addr; in ____sys_recvmsg()
2814 cmsg_ptr = (unsigned long)msg_sys->msg_control; in ____sys_recvmsg()
2815 msg_sys->msg_flags = flags & (MSG_CMSG_CLOEXEC|MSG_CMSG_COMPAT); in ____sys_recvmsg()
2817 /* We assume all kernel code knows the size of sockaddr_storage */ in ____sys_recvmsg()
2818 msg_sys->msg_namelen = 0; in ____sys_recvmsg()
2820 if (sock->file->f_flags & O_NONBLOCK) in ____sys_recvmsg()
2834 msg_sys->msg_namelen, uaddr, in ____sys_recvmsg()
2839 err = __put_user((msg_sys->msg_flags & ~MSG_CMSG_COMPAT), in ____sys_recvmsg()
2844 err = __put_user((unsigned long)msg_sys->msg_control - cmsg_ptr, in ____sys_recvmsg()
2845 &msg_compat->msg_controllen); in ____sys_recvmsg()
2847 err = __put_user((unsigned long)msg_sys->msg_control - cmsg_ptr, in ____sys_recvmsg()
2848 &msg->msg_controllen); in ____sys_recvmsg()
2892 return -EINVAL; in __sys_recvmsg()
2900 fput_light(sock->file, fput_needed); in __sys_recvmsg()
2928 poll_select_set_timeout(&end_time, timeout->tv_sec, in do_recvmmsg()
2929 timeout->tv_nsec)) in do_recvmmsg()
2930 return -EINVAL; in do_recvmmsg()
2939 err = sock_error(sock->sk); in do_recvmmsg()
2959 err = __put_user(err, &compat_entry->msg_len); in do_recvmmsg()
2968 err = put_user(err, &entry->msg_len); in do_recvmmsg()
2983 if (timeout->tv_sec < 0) { in do_recvmmsg()
2984 timeout->tv_sec = timeout->tv_nsec = 0; in do_recvmmsg()
2989 if (timeout->tv_nsec == 0 && timeout->tv_sec == 0) in do_recvmmsg()
3011 if (err != -EAGAIN) { in do_recvmmsg()
3018 WRITE_ONCE(sock->sk->sk_err, -err); in do_recvmmsg()
3021 fput_light(sock->file, fput_needed); in do_recvmmsg()
3035 return -EFAULT; in __sys_recvmmsg()
3038 return -EFAULT; in __sys_recvmmsg()
3049 datagrams = -EFAULT; in __sys_recvmmsg()
3052 datagrams = -EFAULT; in __sys_recvmmsg()
3062 return -EINVAL; in SYSCALL_DEFINE5()
3073 return -EINVAL; in SYSCALL_DEFINE5()
3095 * This function doesn't need to set the kernel lock because
3107 return -EINVAL; in SYSCALL_DEFINE2()
3112 return -EINVAL; in SYSCALL_DEFINE2()
3116 return -EFAULT; in SYSCALL_DEFINE2()
3212 err = -EINVAL; in SYSCALL_DEFINE2()
3221 * sock_register - add a socket protocol handler
3225 * advertise its address family, and have it linked into the
3226 * socket interface. The value ops->family corresponds to the
3227 * socket system call protocol family.
3233 if (ops->family >= NPROTO) { in sock_register()
3234 pr_crit("protocol %d >= NPROTO(%d)\n", ops->family, NPROTO); in sock_register()
3235 return -ENOBUFS; in sock_register()
3239 if (rcu_dereference_protected(net_families[ops->family], in sock_register()
3241 err = -EEXIST; in sock_register()
3243 rcu_assign_pointer(net_families[ops->family], ops); in sock_register()
3248 pr_info("NET: Registered %s protocol family\n", pf_family_names[ops->family]); in sock_register()
3254 * sock_unregister - remove a protocol handler
3255 * @family: protocol family to remove
3258 * remove its address family, and have it unlinked from the
3264 * the ops->create routine.
3266 void sock_unregister(int family) in sock_unregister() argument
3268 BUG_ON(family < 0 || family >= NPROTO); in sock_unregister()
3271 RCU_INIT_POINTER(net_families[family], NULL); in sock_unregister()
3276 pr_info("NET: Unregistered %s protocol family\n", pf_family_names[family]); in sock_unregister()
3280 bool sock_is_registered(int family) in sock_is_registered() argument
3282 return family < NPROTO && rcu_access_pointer(net_families[family]); in sock_is_registered()
3340 sock_inuse_get(seq->private)); in socket_seq_show()
3347 * ifreq::ifru_ifmap (which is 16 bytes on 32 bit, 24 bytes on 64-bit,
3360 return -EFAULT; in get_user_ifreq()
3363 *ifrdata = compat_ptr(ifr32->ifr_data); in get_user_ifreq()
3369 return -EFAULT; in get_user_ifreq()
3372 *ifrdata = ifr->ifr_data; in get_user_ifreq()
3386 return -EFAULT; in put_user_ifreq()
3401 return -EFAULT; in compat_siocwandev()
3403 if (get_user(uptr32, &uifr32->ifr_settings.ifs_ifsu)) in compat_siocwandev()
3404 return -EFAULT; in compat_siocwandev()
3413 err = -EFAULT; in compat_siocwandev()
3426 return -ENOTTY; in compat_ifr_data_ioctl()
3428 return -EFAULT; in compat_ifr_data_ioctl()
3438 struct sock *sk = sock->sk; in compat_sock_ioctl_trans()
3450 ops = READ_ONCE(sock->ops); in compat_sock_ioctl_trans()
3451 if (!ops->gettstamp) in compat_sock_ioctl_trans()
3452 return -ENOIOCTLCMD; in compat_sock_ioctl_trans()
3453 return ops->gettstamp(sock, argp, cmd == SIOCGSTAMP_OLD, in compat_sock_ioctl_trans()
3528 return -ENOIOCTLCMD; in compat_sock_ioctl_trans()
3534 struct socket *sock = file->private_data; in compat_sock_ioctl()
3535 const struct proto_ops *ops = READ_ONCE(sock->ops); in compat_sock_ioctl()
3536 int ret = -ENOIOCTLCMD; in compat_sock_ioctl()
3540 sk = sock->sk; in compat_sock_ioctl()
3543 if (ops->compat_ioctl) in compat_sock_ioctl()
3544 ret = ops->compat_ioctl(sock, cmd, arg); in compat_sock_ioctl()
3546 if (ret == -ENOIOCTLCMD && in compat_sock_ioctl()
3550 if (ret == -ENOIOCTLCMD) in compat_sock_ioctl()
3558 * kernel_bind - bind an address to a socket (kernel space)
3572 return READ_ONCE(sock->ops)->bind(sock, (struct sockaddr *)&address, in kernel_bind()
3578 * kernel_listen - move socket to listening state (kernel space)
3587 return READ_ONCE(sock->ops)->listen(sock, backlog); in kernel_listen()
3592 * kernel_accept - accept a connection (kernel space)
3604 struct sock *sk = sock->sk; in kernel_accept()
3605 const struct proto_ops *ops = READ_ONCE(sock->ops); in kernel_accept()
3612 err = sock_create_lite(sk->sk_family, sk->sk_type, sk->sk_protocol, in kernel_accept()
3617 err = ops->accept(sock, *newsock, &arg); in kernel_accept()
3624 (*newsock)->ops = ops; in kernel_accept()
3625 __module_get(ops->owner); in kernel_accept()
3633 * kernel_connect - connect a socket (kernel space)
3652 return READ_ONCE(sock->ops)->connect(sock, (struct sockaddr *)&address, in kernel_connect()
3658 * kernel_getsockname - get the address which the socket is bound (kernel space)
3668 return READ_ONCE(sock->ops)->getname(sock, addr, 0); in kernel_getsockname()
3673 * kernel_getpeername - get the address which the socket is connected (kernel space)
3683 return READ_ONCE(sock->ops)->getname(sock, addr, 1); in kernel_getpeername()
3688 * kernel_sock_shutdown - shut down part of a full-duplex connection (kernel space)
3697 return READ_ONCE(sock->ops)->shutdown(sock, how); in kernel_sock_shutdown()
3702 * kernel_sock_ip_overhead - returns the IP overhead imposed by a socket
3724 switch (sk->sk_family) { in kernel_sock_ip_overhead()
3728 opt = rcu_dereference_protected(inet->inet_opt, in kernel_sock_ip_overhead()
3731 overhead += opt->opt.optlen; in kernel_sock_ip_overhead()
3738 optv6 = rcu_dereference_protected(np->opt, in kernel_sock_ip_overhead()
3741 overhead += (optv6->opt_flen + optv6->opt_nflen); in kernel_sock_ip_overhead()