blob: 3236b4167a32109b91b1eb28ae8bdf522c8db3f5 [file] [log] [blame]
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +09001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 32bit Socket syscall emulation. Based on arch/sparc64/kernel/sys_sparc32.c.
3 *
4 * Copyright (C) 2000 VA Linux Co
5 * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
6 * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
7 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
9 * Copyright (C) 2000 Hewlett-Packard Co.
10 * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +090011 * Copyright (C) 2000,2001 Andi Kleen, SuSE Labs
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
14#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/types.h>
18#include <linux/file.h>
19#include <linux/icmpv6.h>
20#include <linux/socket.h>
21#include <linux/syscalls.h>
22#include <linux/filter.h>
23#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/security.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040025#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <net/scm.h>
28#include <net/sock.h>
David L Stevensdae50292008-04-27 01:06:07 -070029#include <net/ip.h>
30#include <net/ipv6.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/uaccess.h>
32#include <net/compat.h>
33
Al Viro08adb7d2014-11-10 20:23:13 -050034ssize_t get_compat_msghdr(struct msghdr *kmsg,
35 struct compat_msghdr __user *umsg,
36 struct sockaddr __user **save_addr,
37 struct iovec **iov)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
Al Viro08adb7d2014-11-10 20:23:13 -050039 compat_uptr_t uaddr, uiov, tmp3;
Al Viroc0371da2014-11-24 10:42:55 -050040 compat_size_t nr_segs;
Al Viro08adb7d2014-11-10 20:23:13 -050041 ssize_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 if (!access_ok(VERIFY_READ, umsg, sizeof(*umsg)) ||
Al Viro08adb7d2014-11-10 20:23:13 -050044 __get_user(uaddr, &umsg->msg_name) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 __get_user(kmsg->msg_namelen, &umsg->msg_namelen) ||
Al Viro08adb7d2014-11-10 20:23:13 -050046 __get_user(uiov, &umsg->msg_iov) ||
Al Viroc0371da2014-11-24 10:42:55 -050047 __get_user(nr_segs, &umsg->msg_iovlen) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 __get_user(tmp3, &umsg->msg_control) ||
49 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
50 __get_user(kmsg->msg_flags, &umsg->msg_flags))
51 return -EFAULT;
Dan Carpenter1661bf32013-10-03 00:27:20 +030052 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
Dan Carpenterdb31c552013-11-27 15:40:21 +030053 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 kmsg->msg_control = compat_ptr(tmp3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Al Viro08adb7d2014-11-10 20:23:13 -050056 if (save_addr)
57 *save_addr = compat_ptr(uaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Al Viro08adb7d2014-11-10 20:23:13 -050059 if (uaddr && kmsg->msg_namelen) {
60 if (!save_addr) {
61 err = move_addr_to_kernel(compat_ptr(uaddr),
62 kmsg->msg_namelen,
63 kmsg->msg_name);
Stephen Hemmingere71a4782007-04-10 20:10:33 -070064 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 return err;
66 }
Andrey Ryabinin40eea802014-07-26 21:26:58 +040067 } else {
Al Viro08adb7d2014-11-10 20:23:13 -050068 kmsg->msg_name = NULL;
69 kmsg->msg_namelen = 0;
Andrey Ryabinin40eea802014-07-26 21:26:58 +040070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Al Viroc0371da2014-11-24 10:42:55 -050072 if (nr_segs > UIO_MAXIOV)
Al Viro08449322014-11-09 22:33:45 -050073 return -EMSGSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Al Viro08adb7d2014-11-10 20:23:13 -050075 err = compat_rw_copy_check_uvector(save_addr ? READ : WRITE,
Al Viroc0371da2014-11-24 10:42:55 -050076 compat_ptr(uiov), nr_segs,
Al Viro08adb7d2014-11-10 20:23:13 -050077 UIO_FASTIOV, *iov, iov);
Al Viro08449322014-11-09 22:33:45 -050078 if (err >= 0)
Al Viroc0371da2014-11-24 10:42:55 -050079 iov_iter_init(&kmsg->msg_iter, save_addr ? READ : WRITE,
80 *iov, nr_segs, err);
Al Viro08449322014-11-09 22:33:45 -050081 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
84/* Bleech... */
85#define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32))
86
87#define CMSG_COMPAT_DATA(cmsg) \
88 ((void __user *)((char __user *)(cmsg) + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))))
89#define CMSG_COMPAT_SPACE(len) \
90 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + CMSG_COMPAT_ALIGN(len))
91#define CMSG_COMPAT_LEN(len) \
92 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + (len))
93
94#define CMSG_COMPAT_FIRSTHDR(msg) \
95 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96 (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97 (struct compat_cmsghdr __user *)NULL)
98
99#define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
100 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101 (ucmlen) <= (unsigned long) \
102 ((mhdr)->msg_controllen - \
103 ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
104
105static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
106 struct compat_cmsghdr __user *cmsg, int cmsg_len)
107{
108 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
109 if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
110 msg->msg_controllen)
111 return NULL;
112 return (struct compat_cmsghdr __user *)ptr;
113}
114
115/* There is a lot of hair here because the alignment rules (and
116 * thus placement) of cmsg headers and length are different for
117 * 32-bit apps. -DaveM
118 */
Al Viro8920e8f2005-09-07 18:28:51 -0700119int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 unsigned char *stackbuf, int stackbuf_size)
121{
122 struct compat_cmsghdr __user *ucmsg;
123 struct cmsghdr *kcmsg, *kcmsg_base;
124 compat_size_t ucmlen;
125 __kernel_size_t kcmlen, tmp;
Al Viro8920e8f2005-09-07 18:28:51 -0700126 int err = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 kcmlen = 0;
129 kcmsg_base = kcmsg = (struct cmsghdr *)stackbuf;
130 ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700131 while (ucmsg != NULL) {
132 if (get_user(ucmlen, &ucmsg->cmsg_len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return -EFAULT;
134
135 /* Catch bogons. */
136 if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg))
137 return -EINVAL;
138
139 tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) +
140 CMSG_ALIGN(sizeof(struct cmsghdr)));
Al Viro8920e8f2005-09-07 18:28:51 -0700141 tmp = CMSG_ALIGN(tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 kcmlen += tmp;
143 ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen);
144 }
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700145 if (kcmlen == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return -EINVAL;
147
148 /* The kcmlen holds the 64-bit version of the control length.
149 * It may not be modified as we do not stick it into the kmsg
150 * until we have successfully copied over all of the data
151 * from the user.
152 */
Al Viro8920e8f2005-09-07 18:28:51 -0700153 if (kcmlen > stackbuf_size)
154 kcmsg_base = kcmsg = sock_kmalloc(sk, kcmlen, GFP_KERNEL);
155 if (kcmsg == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return -ENOBUFS;
157
158 /* Now copy them over neatly. */
159 memset(kcmsg, 0, kcmlen);
160 ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700161 while (ucmsg != NULL) {
Al Viro8920e8f2005-09-07 18:28:51 -0700162 if (__get_user(ucmlen, &ucmsg->cmsg_len))
163 goto Efault;
164 if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg))
165 goto Einval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) +
167 CMSG_ALIGN(sizeof(struct cmsghdr)));
Al Viro8920e8f2005-09-07 18:28:51 -0700168 if ((char *)kcmsg_base + kcmlen - (char *)kcmsg < CMSG_ALIGN(tmp))
169 goto Einval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 kcmsg->cmsg_len = tmp;
Al Viro8920e8f2005-09-07 18:28:51 -0700171 tmp = CMSG_ALIGN(tmp);
172 if (__get_user(kcmsg->cmsg_level, &ucmsg->cmsg_level) ||
173 __get_user(kcmsg->cmsg_type, &ucmsg->cmsg_type) ||
174 copy_from_user(CMSG_DATA(kcmsg),
175 CMSG_COMPAT_DATA(ucmsg),
176 (ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg)))))
177 goto Efault;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 /* Advance. */
Al Viro8920e8f2005-09-07 18:28:51 -0700180 kcmsg = (struct cmsghdr *)((char *)kcmsg + tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen);
182 }
183
184 /* Ok, looks like we made it. Hook it up and return success. */
185 kmsg->msg_control = kcmsg_base;
186 kmsg->msg_controllen = kcmlen;
187 return 0;
188
Al Viro8920e8f2005-09-07 18:28:51 -0700189Einval:
190 err = -EINVAL;
191Efault:
192 if (kcmsg_base != (struct cmsghdr *)stackbuf)
193 sock_kfree_s(sk, kcmsg_base, kcmlen);
194 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
197int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
198{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
200 struct compat_cmsghdr cmhdr;
Jesper Juhl81881042012-07-22 11:37:20 +0000201 struct compat_timeval ctv;
202 struct compat_timespec cts[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 int cmlen;
204
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700205 if (cm == NULL || kmsg->msg_controllen < sizeof(*cm)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 kmsg->msg_flags |= MSG_CTRUNC;
207 return 0; /* XXX: return error? check spec. */
208 }
209
H. J. Luee4fa232012-02-19 17:50:46 -0800210 if (!COMPAT_USE_64BIT_TIME) {
H. J. Luee4fa232012-02-19 17:50:46 -0800211 if (level == SOL_SOCKET && type == SCM_TIMESTAMP) {
212 struct timeval *tv = (struct timeval *)data;
213 ctv.tv_sec = tv->tv_sec;
214 ctv.tv_usec = tv->tv_usec;
215 data = &ctv;
216 len = sizeof(ctv);
Patrick Ohly20d49472009-02-12 05:03:38 +0000217 }
H. J. Luee4fa232012-02-19 17:50:46 -0800218 if (level == SOL_SOCKET &&
219 (type == SCM_TIMESTAMPNS || type == SCM_TIMESTAMPING)) {
220 int count = type == SCM_TIMESTAMPNS ? 1 : 3;
221 int i;
222 struct timespec *ts = (struct timespec *)data;
223 for (i = 0; i < count; i++) {
224 cts[i].tv_sec = ts[i].tv_sec;
225 cts[i].tv_nsec = ts[i].tv_nsec;
226 }
227 data = &cts;
228 len = sizeof(cts[0]) * count;
229 }
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +0900230 }
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 cmlen = CMSG_COMPAT_LEN(len);
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700233 if (kmsg->msg_controllen < cmlen) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 kmsg->msg_flags |= MSG_CTRUNC;
235 cmlen = kmsg->msg_controllen;
236 }
237 cmhdr.cmsg_level = level;
238 cmhdr.cmsg_type = type;
239 cmhdr.cmsg_len = cmlen;
240
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700241 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 return -EFAULT;
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700243 if (copy_to_user(CMSG_COMPAT_DATA(cm), data, cmlen - sizeof(struct compat_cmsghdr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return -EFAULT;
245 cmlen = CMSG_COMPAT_SPACE(len);
Wei Yongjun1ac70e72007-12-20 14:36:44 -0800246 if (kmsg->msg_controllen < cmlen)
247 cmlen = kmsg->msg_controllen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 kmsg->msg_control += cmlen;
249 kmsg->msg_controllen -= cmlen;
250 return 0;
251}
252
253void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
254{
255 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
256 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
257 int fdnum = scm->fp->count;
258 struct file **fp = scm->fp->fp;
259 int __user *cmfptr;
260 int err = 0, i;
261
262 if (fdnum < fdmax)
263 fdmax = fdnum;
264
265 for (i = 0, cmfptr = (int __user *) CMSG_COMPAT_DATA(cm); i < fdmax; i++, cmfptr++) {
266 int new_fd;
267 err = security_file_receive(fp[i]);
268 if (err)
269 break;
Ulrich Drepper4a195422007-07-15 23:40:34 -0700270 err = get_unused_fd_flags(MSG_CMSG_CLOEXEC & kmsg->msg_flags
271 ? O_CLOEXEC : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (err < 0)
273 break;
274 new_fd = err;
275 err = put_user(new_fd, cmfptr);
276 if (err) {
277 put_unused_fd(new_fd);
278 break;
279 }
280 /* Bump the usage count and install the file. */
Al Virocb0942b2012-08-27 14:48:26 -0400281 fd_install(new_fd, get_file(fp[i]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 }
283
284 if (i > 0) {
285 int cmlen = CMSG_COMPAT_LEN(i * sizeof(int));
Miklos Szeredieffee6a2006-10-09 21:42:14 -0700286 err = put_user(SOL_SOCKET, &cm->cmsg_level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 if (!err)
288 err = put_user(SCM_RIGHTS, &cm->cmsg_type);
289 if (!err)
290 err = put_user(cmlen, &cm->cmsg_len);
291 if (!err) {
292 cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
293 kmsg->msg_control += cmlen;
294 kmsg->msg_controllen -= cmlen;
295 }
296 }
297 if (i < fdnum)
298 kmsg->msg_flags |= MSG_CTRUNC;
299
300 /*
301 * All of the files that fit in the message have had their
302 * usage counts incremented, so we just free the list.
303 */
304 __scm_destroy(scm);
305}
306
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800307static int do_set_attach_filter(struct socket *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700308 char __user *optval, unsigned int optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 struct compat_sock_fprog __user *fprog32 = (struct compat_sock_fprog __user *)optval;
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +0900311 struct sock_fprog __user *kfprog = compat_alloc_user_space(sizeof(struct sock_fprog));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 compat_uptr_t ptr;
313 u16 len;
314
315 if (!access_ok(VERIFY_READ, fprog32, sizeof(*fprog32)) ||
316 !access_ok(VERIFY_WRITE, kfprog, sizeof(struct sock_fprog)) ||
317 __get_user(len, &fprog32->len) ||
318 __get_user(ptr, &fprog32->filter) ||
319 __put_user(len, &kfprog->len) ||
320 __put_user(compat_ptr(ptr), &kfprog->filter))
321 return -EFAULT;
322
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800323 return sock_setsockopt(sock, level, optname, (char __user *)kfprog,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 sizeof(struct sock_fprog));
325}
326
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800327static int do_set_sock_timeout(struct socket *sock, int level,
David S. Millerb7058842009-09-30 16:12:20 -0700328 int optname, char __user *optval, unsigned int optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700330 struct compat_timeval __user *up = (struct compat_timeval __user *)optval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 struct timeval ktime;
332 mm_segment_t old_fs;
333 int err;
334
335 if (optlen < sizeof(*up))
336 return -EINVAL;
337 if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
338 __get_user(ktime.tv_sec, &up->tv_sec) ||
339 __get_user(ktime.tv_usec, &up->tv_usec))
340 return -EFAULT;
341 old_fs = get_fs();
342 set_fs(KERNEL_DS);
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700343 err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 set_fs(old_fs);
345
346 return err;
347}
348
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800349static int compat_sock_setsockopt(struct socket *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700350 char __user *optval, unsigned int optlen)
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800351{
352 if (optname == SO_ATTACH_FILTER)
353 return do_set_attach_filter(sock, level, optname,
354 optval, optlen);
355 if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
356 return do_set_sock_timeout(sock, level, optname, optval, optlen);
357
358 return sock_setsockopt(sock, level, optname, optval, optlen);
359}
360
Heiko Carstens361d93c2014-03-03 16:21:27 +0100361COMPAT_SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname,
362 char __user *, optval, unsigned int, optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800364 int err;
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700365 struct socket *sock = sockfd_lookup(fd, &err);
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800366
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700367 if (sock) {
368 err = security_socket_setsockopt(sock, level, optname);
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800369 if (err) {
370 sockfd_put(sock);
371 return err;
372 }
373
374 if (level == SOL_SOCKET)
375 err = compat_sock_setsockopt(sock, level,
376 optname, optval, optlen);
377 else if (sock->ops->compat_setsockopt)
378 err = sock->ops->compat_setsockopt(sock, level,
379 optname, optval, optlen);
380 else
381 err = sock->ops->setsockopt(sock, level,
382 optname, optval, optlen);
383 sockfd_put(sock);
384 }
385 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
387
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800388static int do_get_sock_timeout(struct socket *sock, int level, int optname,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 char __user *optval, int __user *optlen)
390{
391 struct compat_timeval __user *up;
392 struct timeval ktime;
393 mm_segment_t old_fs;
394 int len, err;
395
396 up = (struct compat_timeval __user *) optval;
397 if (get_user(len, optlen))
398 return -EFAULT;
399 if (len < sizeof(*up))
400 return -EINVAL;
401 len = sizeof(ktime);
402 old_fs = get_fs();
403 set_fs(KERNEL_DS);
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800404 err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 set_fs(old_fs);
406
407 if (!err) {
408 if (put_user(sizeof(*up), optlen) ||
409 !access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
410 __put_user(ktime.tv_sec, &up->tv_sec) ||
411 __put_user(ktime.tv_usec, &up->tv_usec))
412 err = -EFAULT;
413 }
414 return err;
415}
416
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800417static int compat_sock_getsockopt(struct socket *sock, int level, int optname,
418 char __user *optval, int __user *optlen)
419{
420 if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
421 return do_get_sock_timeout(sock, level, optname, optval, optlen);
422 return sock_getsockopt(sock, level, optname, optval, optlen);
423}
424
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800425int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
426{
H. J. Luee4fa232012-02-19 17:50:46 -0800427 struct compat_timeval __user *ctv;
428 int err;
Eric Dumazetb7aa0bf2007-04-19 16:16:32 -0700429 struct timeval tv;
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800430
H. J. Luee4fa232012-02-19 17:50:46 -0800431 if (COMPAT_USE_64BIT_TIME)
432 return sock_get_timestamp(sk, userstamp);
433
434 ctv = (struct compat_timeval __user *) userstamp;
435 err = -ENOENT;
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800436 if (!sock_flag(sk, SOCK_TIMESTAMP))
Patrick Ohly20d49472009-02-12 05:03:38 +0000437 sock_enable_timestamp(sk, SOCK_TIMESTAMP);
Eric Dumazetb7aa0bf2007-04-19 16:16:32 -0700438 tv = ktime_to_timeval(sk->sk_stamp);
439 if (tv.tv_sec == -1)
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800440 return err;
Eric Dumazetb7aa0bf2007-04-19 16:16:32 -0700441 if (tv.tv_sec == 0) {
442 sk->sk_stamp = ktime_get_real();
443 tv = ktime_to_timeval(sk->sk_stamp);
444 }
445 err = 0;
446 if (put_user(tv.tv_sec, &ctv->tv_sec) ||
447 put_user(tv.tv_usec, &ctv->tv_usec))
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800448 err = -EFAULT;
449 return err;
450}
451EXPORT_SYMBOL(compat_sock_get_timestamp);
452
Eric Dumazetae40eb12007-03-18 17:33:16 -0700453int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
454{
H. J. Luee4fa232012-02-19 17:50:46 -0800455 struct compat_timespec __user *ctv;
456 int err;
Eric Dumazetae40eb12007-03-18 17:33:16 -0700457 struct timespec ts;
458
H. J. Luee4fa232012-02-19 17:50:46 -0800459 if (COMPAT_USE_64BIT_TIME)
460 return sock_get_timestampns (sk, userstamp);
461
462 ctv = (struct compat_timespec __user *) userstamp;
463 err = -ENOENT;
Eric Dumazetae40eb12007-03-18 17:33:16 -0700464 if (!sock_flag(sk, SOCK_TIMESTAMP))
Patrick Ohly20d49472009-02-12 05:03:38 +0000465 sock_enable_timestamp(sk, SOCK_TIMESTAMP);
Eric Dumazetae40eb12007-03-18 17:33:16 -0700466 ts = ktime_to_timespec(sk->sk_stamp);
467 if (ts.tv_sec == -1)
468 return err;
469 if (ts.tv_sec == 0) {
470 sk->sk_stamp = ktime_get_real();
471 ts = ktime_to_timespec(sk->sk_stamp);
472 }
473 err = 0;
474 if (put_user(ts.tv_sec, &ctv->tv_sec) ||
475 put_user(ts.tv_nsec, &ctv->tv_nsec))
476 err = -EFAULT;
477 return err;
478}
479EXPORT_SYMBOL(compat_sock_get_timestampns);
480
Heiko Carstens361d93c2014-03-03 16:21:27 +0100481COMPAT_SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname,
482 char __user *, optval, int __user *, optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800484 int err;
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700485 struct socket *sock = sockfd_lookup(fd, &err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700487 if (sock) {
488 err = security_socket_getsockopt(sock, level, optname);
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800489 if (err) {
490 sockfd_put(sock);
491 return err;
492 }
493
494 if (level == SOL_SOCKET)
495 err = compat_sock_getsockopt(sock, level,
496 optname, optval, optlen);
497 else if (sock->ops->compat_getsockopt)
498 err = sock->ops->compat_getsockopt(sock, level,
499 optname, optval, optlen);
500 else
501 err = sock->ops->getsockopt(sock, level,
502 optname, optval, optlen);
503 sockfd_put(sock);
504 }
505 return err;
506}
David L Stevensdae50292008-04-27 01:06:07 -0700507
508struct compat_group_req {
509 __u32 gr_interface;
510 struct __kernel_sockaddr_storage gr_group
511 __attribute__ ((aligned(4)));
Eric Dumazetbc105022010-06-03 03:21:52 -0700512} __packed;
David L Stevensdae50292008-04-27 01:06:07 -0700513
514struct compat_group_source_req {
515 __u32 gsr_interface;
516 struct __kernel_sockaddr_storage gsr_group
517 __attribute__ ((aligned(4)));
518 struct __kernel_sockaddr_storage gsr_source
519 __attribute__ ((aligned(4)));
Eric Dumazetbc105022010-06-03 03:21:52 -0700520} __packed;
David L Stevensdae50292008-04-27 01:06:07 -0700521
522struct compat_group_filter {
523 __u32 gf_interface;
524 struct __kernel_sockaddr_storage gf_group
525 __attribute__ ((aligned(4)));
526 __u32 gf_fmode;
527 __u32 gf_numsrc;
528 struct __kernel_sockaddr_storage gf_slist[1]
529 __attribute__ ((aligned(4)));
Eric Dumazetbc105022010-06-03 03:21:52 -0700530} __packed;
David L Stevensdae50292008-04-27 01:06:07 -0700531
David L Stevensbe666e02008-04-29 03:23:00 -0700532#define __COMPAT_GF0_SIZE (sizeof(struct compat_group_filter) - \
533 sizeof(struct __kernel_sockaddr_storage))
534
David L Stevensdae50292008-04-27 01:06:07 -0700535
536int compat_mc_setsockopt(struct sock *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700537 char __user *optval, unsigned int optlen,
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700538 int (*setsockopt)(struct sock *, int, int, char __user *, unsigned int))
David L Stevensdae50292008-04-27 01:06:07 -0700539{
540 char __user *koptval = optval;
541 int koptlen = optlen;
542
543 switch (optname) {
544 case MCAST_JOIN_GROUP:
545 case MCAST_LEAVE_GROUP:
546 {
547 struct compat_group_req __user *gr32 = (void *)optval;
548 struct group_req __user *kgr =
549 compat_alloc_user_space(sizeof(struct group_req));
550 u32 interface;
551
552 if (!access_ok(VERIFY_READ, gr32, sizeof(*gr32)) ||
553 !access_ok(VERIFY_WRITE, kgr, sizeof(struct group_req)) ||
554 __get_user(interface, &gr32->gr_interface) ||
555 __put_user(interface, &kgr->gr_interface) ||
556 copy_in_user(&kgr->gr_group, &gr32->gr_group,
557 sizeof(kgr->gr_group)))
558 return -EFAULT;
559 koptval = (char __user *)kgr;
560 koptlen = sizeof(struct group_req);
561 break;
562 }
563 case MCAST_JOIN_SOURCE_GROUP:
564 case MCAST_LEAVE_SOURCE_GROUP:
565 case MCAST_BLOCK_SOURCE:
566 case MCAST_UNBLOCK_SOURCE:
567 {
568 struct compat_group_source_req __user *gsr32 = (void *)optval;
David L Stevensbe666e02008-04-29 03:23:00 -0700569 struct group_source_req __user *kgsr = compat_alloc_user_space(
David L Stevensdae50292008-04-27 01:06:07 -0700570 sizeof(struct group_source_req));
571 u32 interface;
572
573 if (!access_ok(VERIFY_READ, gsr32, sizeof(*gsr32)) ||
574 !access_ok(VERIFY_WRITE, kgsr,
575 sizeof(struct group_source_req)) ||
576 __get_user(interface, &gsr32->gsr_interface) ||
577 __put_user(interface, &kgsr->gsr_interface) ||
578 copy_in_user(&kgsr->gsr_group, &gsr32->gsr_group,
579 sizeof(kgsr->gsr_group)) ||
580 copy_in_user(&kgsr->gsr_source, &gsr32->gsr_source,
581 sizeof(kgsr->gsr_source)))
582 return -EFAULT;
583 koptval = (char __user *)kgsr;
584 koptlen = sizeof(struct group_source_req);
585 break;
586 }
587 case MCAST_MSFILTER:
588 {
589 struct compat_group_filter __user *gf32 = (void *)optval;
David L Stevensbe666e02008-04-29 03:23:00 -0700590 struct group_filter __user *kgf;
David L Stevensdae50292008-04-27 01:06:07 -0700591 u32 interface, fmode, numsrc;
592
David L Stevensbe666e02008-04-29 03:23:00 -0700593 if (!access_ok(VERIFY_READ, gf32, __COMPAT_GF0_SIZE) ||
David L Stevensdae50292008-04-27 01:06:07 -0700594 __get_user(interface, &gf32->gf_interface) ||
595 __get_user(fmode, &gf32->gf_fmode) ||
596 __get_user(numsrc, &gf32->gf_numsrc))
597 return -EFAULT;
598 koptlen = optlen + sizeof(struct group_filter) -
599 sizeof(struct compat_group_filter);
600 if (koptlen < GROUP_FILTER_SIZE(numsrc))
601 return -EINVAL;
602 kgf = compat_alloc_user_space(koptlen);
603 if (!access_ok(VERIFY_WRITE, kgf, koptlen) ||
604 __put_user(interface, &kgf->gf_interface) ||
605 __put_user(fmode, &kgf->gf_fmode) ||
606 __put_user(numsrc, &kgf->gf_numsrc) ||
607 copy_in_user(&kgf->gf_group, &gf32->gf_group,
608 sizeof(kgf->gf_group)) ||
David L Stevensbe666e02008-04-29 03:23:00 -0700609 (numsrc && copy_in_user(kgf->gf_slist, gf32->gf_slist,
David L Stevensdae50292008-04-27 01:06:07 -0700610 numsrc * sizeof(kgf->gf_slist[0]))))
611 return -EFAULT;
612 koptval = (char __user *)kgf;
613 break;
614 }
615
616 default:
617 break;
618 }
619 return setsockopt(sock, level, optname, koptval, koptlen);
620}
David L Stevensdae50292008-04-27 01:06:07 -0700621EXPORT_SYMBOL(compat_mc_setsockopt);
622
David L Stevens42908c62008-04-29 03:23:22 -0700623int compat_mc_getsockopt(struct sock *sock, int level, int optname,
624 char __user *optval, int __user *optlen,
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700625 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
David L Stevens42908c62008-04-29 03:23:22 -0700626{
627 struct compat_group_filter __user *gf32 = (void *)optval;
628 struct group_filter __user *kgf;
629 int __user *koptlen;
630 u32 interface, fmode, numsrc;
631 int klen, ulen, err;
632
633 if (optname != MCAST_MSFILTER)
634 return getsockopt(sock, level, optname, optval, optlen);
635
636 koptlen = compat_alloc_user_space(sizeof(*koptlen));
637 if (!access_ok(VERIFY_READ, optlen, sizeof(*optlen)) ||
638 __get_user(ulen, optlen))
639 return -EFAULT;
640
641 /* adjust len for pad */
642 klen = ulen + sizeof(*kgf) - sizeof(*gf32);
643
644 if (klen < GROUP_FILTER_SIZE(0))
645 return -EINVAL;
646
647 if (!access_ok(VERIFY_WRITE, koptlen, sizeof(*koptlen)) ||
648 __put_user(klen, koptlen))
649 return -EFAULT;
650
651 /* have to allow space for previous compat_alloc_user_space, too */
652 kgf = compat_alloc_user_space(klen+sizeof(*optlen));
653
654 if (!access_ok(VERIFY_READ, gf32, __COMPAT_GF0_SIZE) ||
655 __get_user(interface, &gf32->gf_interface) ||
656 __get_user(fmode, &gf32->gf_fmode) ||
657 __get_user(numsrc, &gf32->gf_numsrc) ||
658 __put_user(interface, &kgf->gf_interface) ||
659 __put_user(fmode, &kgf->gf_fmode) ||
660 __put_user(numsrc, &kgf->gf_numsrc) ||
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700661 copy_in_user(&kgf->gf_group, &gf32->gf_group, sizeof(kgf->gf_group)))
David L Stevens42908c62008-04-29 03:23:22 -0700662 return -EFAULT;
663
664 err = getsockopt(sock, level, optname, (char __user *)kgf, koptlen);
665 if (err)
666 return err;
667
668 if (!access_ok(VERIFY_READ, koptlen, sizeof(*koptlen)) ||
669 __get_user(klen, koptlen))
670 return -EFAULT;
671
672 ulen = klen - (sizeof(*kgf)-sizeof(*gf32));
673
674 if (!access_ok(VERIFY_WRITE, optlen, sizeof(*optlen)) ||
675 __put_user(ulen, optlen))
676 return -EFAULT;
677
678 if (!access_ok(VERIFY_READ, kgf, klen) ||
679 !access_ok(VERIFY_WRITE, gf32, ulen) ||
680 __get_user(interface, &kgf->gf_interface) ||
681 __get_user(fmode, &kgf->gf_fmode) ||
682 __get_user(numsrc, &kgf->gf_numsrc) ||
683 __put_user(interface, &gf32->gf_interface) ||
684 __put_user(fmode, &gf32->gf_fmode) ||
685 __put_user(numsrc, &gf32->gf_numsrc))
686 return -EFAULT;
687 if (numsrc) {
688 int copylen;
689
690 klen -= GROUP_FILTER_SIZE(0);
691 copylen = numsrc * sizeof(gf32->gf_slist[0]);
692 if (copylen > klen)
693 copylen = klen;
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700694 if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen))
David L Stevens42908c62008-04-29 03:23:22 -0700695 return -EFAULT;
696 }
697 return err;
698}
David L Stevens42908c62008-04-29 03:23:22 -0700699EXPORT_SYMBOL(compat_mc_getsockopt);
700
David L Stevensdae50292008-04-27 01:06:07 -0700701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702/* Argument list sizes for compat_sys_socketcall */
703#define AL(x) ((x) * sizeof(u32))
Anton Blanchard228e5482011-05-02 20:21:35 +0000704static unsigned char nas[21] = {
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700705 AL(0), AL(3), AL(3), AL(3), AL(2), AL(3),
706 AL(3), AL(3), AL(4), AL(4), AL(4), AL(6),
707 AL(6), AL(2), AL(5), AL(5), AL(3), AL(3),
Anton Blanchard228e5482011-05-02 20:21:35 +0000708 AL(4), AL(5), AL(4)
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700709};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710#undef AL
711
Heiko Carstens361d93c2014-03-03 16:21:27 +0100712COMPAT_SYSCALL_DEFINE3(sendmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713{
Andy Lutomirskia7526eb2013-06-05 19:38:26 +0000714 if (flags & MSG_CMSG_COMPAT)
715 return -EINVAL;
Al Viro666547f2014-04-06 14:03:05 -0400716 return __sys_sendmsg(fd, (struct user_msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717}
718
Heiko Carstens361d93c2014-03-03 16:21:27 +0100719COMPAT_SYSCALL_DEFINE4(sendmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
720 unsigned int, vlen, unsigned int, flags)
Anton Blanchard228e5482011-05-02 20:21:35 +0000721{
Andy Lutomirskia7526eb2013-06-05 19:38:26 +0000722 if (flags & MSG_CMSG_COMPAT)
723 return -EINVAL;
Anton Blanchard228e5482011-05-02 20:21:35 +0000724 return __sys_sendmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
725 flags | MSG_CMSG_COMPAT);
726}
727
Heiko Carstens361d93c2014-03-03 16:21:27 +0100728COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
Andy Lutomirskia7526eb2013-06-05 19:38:26 +0000730 if (flags & MSG_CMSG_COMPAT)
731 return -EINVAL;
Al Viro666547f2014-04-06 14:03:05 -0400732 return __sys_recvmsg(fd, (struct user_msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733}
734
Heiko Carstens3a49a0f2014-03-04 17:09:57 +0100735COMPAT_SYSCALL_DEFINE4(recv, int, fd, void __user *, buf, compat_size_t, len, unsigned int, flags)
Johannes Berg1dacc762009-07-01 11:26:02 +0000736{
737 return sys_recv(fd, buf, len, flags | MSG_CMSG_COMPAT);
738}
739
Heiko Carstens3a49a0f2014-03-04 17:09:57 +0100740COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, len,
741 unsigned int, flags, struct sockaddr __user *, addr,
742 int __user *, addrlen)
Johannes Berg1dacc762009-07-01 11:26:02 +0000743{
744 return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen);
745}
746
Heiko Carstens361d93c2014-03-03 16:21:27 +0100747COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
748 unsigned int, vlen, unsigned int, flags,
749 struct compat_timespec __user *, timeout)
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700750{
751 int datagrams;
752 struct timespec ktspec;
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700753
Andy Lutomirskia7526eb2013-06-05 19:38:26 +0000754 if (flags & MSG_CMSG_COMPAT)
755 return -EINVAL;
756
Jean-Mickael Guerin5b231362009-12-01 07:52:16 +0000757 if (timeout == NULL)
758 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
759 flags | MSG_CMSG_COMPAT, NULL);
760
PaX Team2def2ef2014-01-30 16:59:25 -0800761 if (compat_get_timespec(&ktspec, timeout))
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700762 return -EFAULT;
763
764 datagrams = __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
765 flags | MSG_CMSG_COMPAT, &ktspec);
PaX Team2def2ef2014-01-30 16:59:25 -0800766 if (datagrams > 0 && compat_put_timespec(&ktspec, timeout))
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700767 datagrams = -EFAULT;
768
769 return datagrams;
770}
771
Heiko Carstens361d93c2014-03-03 16:21:27 +0100772COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
774 int ret;
775 u32 a[6];
776 u32 a0, a1;
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +0900777
Anton Blanchard228e5482011-05-02 20:21:35 +0000778 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 return -EINVAL;
780 if (copy_from_user(a, args, nas[call]))
781 return -EFAULT;
782 a0 = a[0];
783 a1 = a[1];
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +0900784
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700785 switch (call) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 case SYS_SOCKET:
787 ret = sys_socket(a0, a1, a[2]);
788 break;
789 case SYS_BIND:
790 ret = sys_bind(a0, compat_ptr(a1), a[2]);
791 break;
792 case SYS_CONNECT:
793 ret = sys_connect(a0, compat_ptr(a1), a[2]);
794 break;
795 case SYS_LISTEN:
796 ret = sys_listen(a0, a1);
797 break;
798 case SYS_ACCEPT:
Ulrich Drepperde11def2008-11-19 15:36:14 -0800799 ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 break;
801 case SYS_GETSOCKNAME:
802 ret = sys_getsockname(a0, compat_ptr(a1), compat_ptr(a[2]));
803 break;
804 case SYS_GETPEERNAME:
805 ret = sys_getpeername(a0, compat_ptr(a1), compat_ptr(a[2]));
806 break;
807 case SYS_SOCKETPAIR:
808 ret = sys_socketpair(a0, a1, a[2], compat_ptr(a[3]));
809 break;
810 case SYS_SEND:
811 ret = sys_send(a0, compat_ptr(a1), a[2], a[3]);
812 break;
813 case SYS_SENDTO:
814 ret = sys_sendto(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), a[5]);
815 break;
816 case SYS_RECV:
Johannes Berg1dacc762009-07-01 11:26:02 +0000817 ret = compat_sys_recv(a0, compat_ptr(a1), a[2], a[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 break;
819 case SYS_RECVFROM:
Johannes Berg1dacc762009-07-01 11:26:02 +0000820 ret = compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3],
821 compat_ptr(a[4]), compat_ptr(a[5]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 break;
823 case SYS_SHUTDOWN:
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700824 ret = sys_shutdown(a0, a1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 break;
826 case SYS_SETSOCKOPT:
827 ret = compat_sys_setsockopt(a0, a1, a[2],
828 compat_ptr(a[3]), a[4]);
829 break;
830 case SYS_GETSOCKOPT:
831 ret = compat_sys_getsockopt(a0, a1, a[2],
832 compat_ptr(a[3]), compat_ptr(a[4]));
833 break;
834 case SYS_SENDMSG:
835 ret = compat_sys_sendmsg(a0, compat_ptr(a1), a[2]);
836 break;
Anton Blanchard228e5482011-05-02 20:21:35 +0000837 case SYS_SENDMMSG:
838 ret = compat_sys_sendmmsg(a0, compat_ptr(a1), a[2], a[3]);
839 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 case SYS_RECVMSG:
841 ret = compat_sys_recvmsg(a0, compat_ptr(a1), a[2]);
842 break;
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700843 case SYS_RECVMMSG:
844 ret = compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3],
845 compat_ptr(a[4]));
846 break;
Ulrich Drepperde11def2008-11-19 15:36:14 -0800847 case SYS_ACCEPT4:
848 ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]);
Ulrich Drepperaaca0bd2008-07-23 21:29:20 -0700849 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 default:
851 ret = -EINVAL;
852 break;
853 }
854 return ret;
855}