aboutsummaryrefslogtreecommitdiffstats
path: root/net/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/socket.c')
-rw-r--r--net/socket.c55
1 files changed, 11 insertions, 44 deletions
diff --git a/net/socket.c b/net/socket.c
index 8a109012608a..8c24d5dc4bc8 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -89,6 +89,7 @@
89#include <linux/magic.h> 89#include <linux/magic.h>
90#include <linux/slab.h> 90#include <linux/slab.h>
91#include <linux/xattr.h> 91#include <linux/xattr.h>
92#include <linux/nospec.h>
92 93
93#include <linux/uaccess.h> 94#include <linux/uaccess.h>
94#include <asm/unistd.h> 95#include <asm/unistd.h>
@@ -117,10 +118,8 @@ static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from);
117static int sock_mmap(struct file *file, struct vm_area_struct *vma); 118static int sock_mmap(struct file *file, struct vm_area_struct *vma);
118 119
119static int sock_close(struct inode *inode, struct file *file); 120static int sock_close(struct inode *inode, struct file *file);
120static struct wait_queue_head *sock_get_poll_head(struct file *file, 121static __poll_t sock_poll(struct file *file,
121 __poll_t events); 122 struct poll_table_struct *wait);
122static __poll_t sock_poll_mask(struct file *file, __poll_t);
123static __poll_t sock_poll(struct file *file, struct poll_table_struct *wait);
124static long sock_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 123static long sock_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
125#ifdef CONFIG_COMPAT 124#ifdef CONFIG_COMPAT
126static long compat_sock_ioctl(struct file *file, 125static long compat_sock_ioctl(struct file *file,
@@ -143,8 +142,6 @@ static const struct file_operations socket_file_ops = {
143 .llseek = no_llseek, 142 .llseek = no_llseek,
144 .read_iter = sock_read_iter, 143 .read_iter = sock_read_iter,
145 .write_iter = sock_write_iter, 144 .write_iter = sock_write_iter,
146 .get_poll_head = sock_get_poll_head,
147 .poll_mask = sock_poll_mask,
148 .poll = sock_poll, 145 .poll = sock_poll,
149 .unlocked_ioctl = sock_ioctl, 146 .unlocked_ioctl = sock_ioctl,
150#ifdef CONFIG_COMPAT 147#ifdef CONFIG_COMPAT
@@ -1130,48 +1127,16 @@ out_release:
1130} 1127}
1131EXPORT_SYMBOL(sock_create_lite); 1128EXPORT_SYMBOL(sock_create_lite);
1132 1129
1133static struct wait_queue_head *sock_get_poll_head(struct file *file,
1134 __poll_t events)
1135{
1136 struct socket *sock = file->private_data;
1137
1138 if (!sock->ops->poll_mask)
1139 return NULL;
1140 sock_poll_busy_loop(sock, events);
1141 return sk_sleep(sock->sk);
1142}
1143
1144static __poll_t sock_poll_mask(struct file *file, __poll_t events)
1145{
1146 struct socket *sock = file->private_data;
1147
1148 /*
1149 * We need to be sure we are in sync with the socket flags modification.
1150 *
1151 * This memory barrier is paired in the wq_has_sleeper.
1152 */
1153 smp_mb();
1154
1155 /* this socket can poll_ll so tell the system call */
1156 return sock->ops->poll_mask(sock, events) |
1157 (sk_can_busy_loop(sock->sk) ? POLL_BUSY_LOOP : 0);
1158}
1159
1160/* No kernel lock held - perfect */ 1130/* No kernel lock held - perfect */
1161static __poll_t sock_poll(struct file *file, poll_table *wait) 1131static __poll_t sock_poll(struct file *file, poll_table *wait)
1162{ 1132{
1163 struct socket *sock = file->private_data; 1133 struct socket *sock = file->private_data;
1164 __poll_t events = poll_requested_events(wait), mask = 0; 1134 __poll_t events = poll_requested_events(wait);
1165
1166 if (sock->ops->poll) {
1167 sock_poll_busy_loop(sock, events);
1168 mask = sock->ops->poll(file, sock, wait);
1169 } else if (sock->ops->poll_mask) {
1170 sock_poll_wait(file, sock_get_poll_head(file, events), wait);
1171 mask = sock->ops->poll_mask(sock, events);
1172 }
1173 1135
1174 return mask | sock_poll_busy_flag(sock); 1136 sock_poll_busy_loop(sock, events);
1137 if (!sock->ops->poll)
1138 return 0;
1139 return sock->ops->poll(file, sock, wait) | sock_poll_busy_flag(sock);
1175} 1140}
1176 1141
1177static int sock_mmap(struct file *file, struct vm_area_struct *vma) 1142static int sock_mmap(struct file *file, struct vm_area_struct *vma)
@@ -2558,6 +2523,7 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
2558 2523
2559 if (call < 1 || call > SYS_SENDMMSG) 2524 if (call < 1 || call > SYS_SENDMMSG)
2560 return -EINVAL; 2525 return -EINVAL;
2526 call = array_index_nospec(call, SYS_SENDMMSG + 1);
2561 2527
2562 len = nargs[call]; 2528 len = nargs[call];
2563 if (len > sizeof(a)) 2529 if (len > sizeof(a))
@@ -2724,7 +2690,8 @@ EXPORT_SYMBOL(sock_unregister);
2724 2690
2725bool sock_is_registered(int family) 2691bool sock_is_registered(int family)
2726{ 2692{
2727 return family < NPROTO && rcu_access_pointer(net_families[family]); 2693 return family < NPROTO &&
2694 rcu_access_pointer(net_families[array_index_nospec(family, NPROTO)]);
2728} 2695}
2729 2696
2730static int __init sock_init(void) 2697static int __init sock_init(void)