blob: 062f157d2a6b9726ae888cea7b0b1af6f69e4082 [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;
40 ssize_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 if (!access_ok(VERIFY_READ, umsg, sizeof(*umsg)) ||
Al Viro08adb7d2014-11-10 20:23:13 -050043 __get_user(uaddr, &umsg->msg_name) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 __get_user(kmsg->msg_namelen, &umsg->msg_namelen) ||
Al Viro08adb7d2014-11-10 20:23:13 -050045 __get_user(uiov, &umsg->msg_iov) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 __get_user(kmsg->msg_iovlen, &umsg->msg_iovlen) ||
47 __get_user(tmp3, &umsg->msg_control) ||
48 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
49 __get_user(kmsg->msg_flags, &umsg->msg_flags))
50 return -EFAULT;
Dan Carpenter1661bf32013-10-03 00:27:20 +030051 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
Dan Carpenterdb31c552013-11-27 15:40:21 +030052 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 kmsg->msg_control = compat_ptr(tmp3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Al Viro08adb7d2014-11-10 20:23:13 -050055 if (save_addr)
56 *save_addr = compat_ptr(uaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Al Viro08adb7d2014-11-10 20:23:13 -050058 if (uaddr && kmsg->msg_namelen) {
59 if (!save_addr) {
60 err = move_addr_to_kernel(compat_ptr(uaddr),
61 kmsg->msg_namelen,
62 kmsg->msg_name);
Stephen Hemmingere71a4782007-04-10 20:10:33 -070063 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 return err;
65 }
Andrey Ryabinin40eea802014-07-26 21:26:58 +040066 } else {
Al Viro08adb7d2014-11-10 20:23:13 -050067 kmsg->msg_name = NULL;
68 kmsg->msg_namelen = 0;
Andrey Ryabinin40eea802014-07-26 21:26:58 +040069 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Al Viro08adb7d2014-11-10 20:23:13 -050071 if (kmsg->msg_iovlen > UIO_MAXIOV)
Al Viro08449322014-11-09 22:33:45 -050072 return -EMSGSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Al Viro08adb7d2014-11-10 20:23:13 -050074 err = compat_rw_copy_check_uvector(save_addr ? READ : WRITE,
75 compat_ptr(uiov), kmsg->msg_iovlen,
76 UIO_FASTIOV, *iov, iov);
Al Viro08449322014-11-09 22:33:45 -050077 if (err >= 0)
Al Viro08adb7d2014-11-10 20:23:13 -050078 kmsg->msg_iov = *iov;
Al Viro08449322014-11-09 22:33:45 -050079 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82/* Bleech... */
83#define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32))
84
85#define CMSG_COMPAT_DATA(cmsg) \
86 ((void __user *)((char __user *)(cmsg) + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))))
87#define CMSG_COMPAT_SPACE(len) \
88 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + CMSG_COMPAT_ALIGN(len))
89#define CMSG_COMPAT_LEN(len) \
90 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + (len))
91
92#define CMSG_COMPAT_FIRSTHDR(msg) \
93 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
94 (struct compat_cmsghdr __user *)((msg)->msg_control) : \
95 (struct compat_cmsghdr __user *)NULL)
96
97#define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
98 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
99 (ucmlen) <= (unsigned long) \
100 ((mhdr)->msg_controllen - \
101 ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
102
103static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
104 struct compat_cmsghdr __user *cmsg, int cmsg_len)
105{
106 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
107 if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
108 msg->msg_controllen)
109 return NULL;
110 return (struct compat_cmsghdr __user *)ptr;
111}
112
113/* There is a lot of hair here because the alignment rules (and
114 * thus placement) of cmsg headers and length are different for
115 * 32-bit apps. -DaveM
116 */
Al Viro8920e8f2005-09-07 18:28:51 -0700117int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 unsigned char *stackbuf, int stackbuf_size)
119{
120 struct compat_cmsghdr __user *ucmsg;
121 struct cmsghdr *kcmsg, *kcmsg_base;
122 compat_size_t ucmlen;
123 __kernel_size_t kcmlen, tmp;
Al Viro8920e8f2005-09-07 18:28:51 -0700124 int err = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 kcmlen = 0;
127 kcmsg_base = kcmsg = (struct cmsghdr *)stackbuf;
128 ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700129 while (ucmsg != NULL) {
130 if (get_user(ucmlen, &ucmsg->cmsg_len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return -EFAULT;
132
133 /* Catch bogons. */
134 if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg))
135 return -EINVAL;
136
137 tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) +
138 CMSG_ALIGN(sizeof(struct cmsghdr)));
Al Viro8920e8f2005-09-07 18:28:51 -0700139 tmp = CMSG_ALIGN(tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 kcmlen += tmp;
141 ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen);
142 }
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700143 if (kcmlen == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return -EINVAL;
145
146 /* The kcmlen holds the 64-bit version of the control length.
147 * It may not be modified as we do not stick it into the kmsg
148 * until we have successfully copied over all of the data
149 * from the user.
150 */
Al Viro8920e8f2005-09-07 18:28:51 -0700151 if (kcmlen > stackbuf_size)
152 kcmsg_base = kcmsg = sock_kmalloc(sk, kcmlen, GFP_KERNEL);
153 if (kcmsg == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return -ENOBUFS;
155
156 /* Now copy them over neatly. */
157 memset(kcmsg, 0, kcmlen);
158 ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700159 while (ucmsg != NULL) {
Al Viro8920e8f2005-09-07 18:28:51 -0700160 if (__get_user(ucmlen, &ucmsg->cmsg_len))
161 goto Efault;
162 if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg))
163 goto Einval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) +
165 CMSG_ALIGN(sizeof(struct cmsghdr)));
Al Viro8920e8f2005-09-07 18:28:51 -0700166 if ((char *)kcmsg_base + kcmlen - (char *)kcmsg < CMSG_ALIGN(tmp))
167 goto Einval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 kcmsg->cmsg_len = tmp;
Al Viro8920e8f2005-09-07 18:28:51 -0700169 tmp = CMSG_ALIGN(tmp);
170 if (__get_user(kcmsg->cmsg_level, &ucmsg->cmsg_level) ||
171 __get_user(kcmsg->cmsg_type, &ucmsg->cmsg_type) ||
172 copy_from_user(CMSG_DATA(kcmsg),
173 CMSG_COMPAT_DATA(ucmsg),
174 (ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg)))))
175 goto Efault;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 /* Advance. */
Al Viro8920e8f2005-09-07 18:28:51 -0700178 kcmsg = (struct cmsghdr *)((char *)kcmsg + tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen);
180 }
181
182 /* Ok, looks like we made it. Hook it up and return success. */
183 kmsg->msg_control = kcmsg_base;
184 kmsg->msg_controllen = kcmlen;
185 return 0;
186
Al Viro8920e8f2005-09-07 18:28:51 -0700187Einval:
188 err = -EINVAL;
189Efault:
190 if (kcmsg_base != (struct cmsghdr *)stackbuf)
191 sock_kfree_s(sk, kcmsg_base, kcmlen);
192 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
196{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
198 struct compat_cmsghdr cmhdr;
Jesper Juhl81881042012-07-22 11:37:20 +0000199 struct compat_timeval ctv;
200 struct compat_timespec cts[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 int cmlen;
202
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700203 if (cm == NULL || kmsg->msg_controllen < sizeof(*cm)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 kmsg->msg_flags |= MSG_CTRUNC;
205 return 0; /* XXX: return error? check spec. */
206 }
207
H. J. Luee4fa232012-02-19 17:50:46 -0800208 if (!COMPAT_USE_64BIT_TIME) {
H. J. Luee4fa232012-02-19 17:50:46 -0800209 if (level == SOL_SOCKET && type == SCM_TIMESTAMP) {
210 struct timeval *tv = (struct timeval *)data;
211 ctv.tv_sec = tv->tv_sec;
212 ctv.tv_usec = tv->tv_usec;
213 data = &ctv;
214 len = sizeof(ctv);
Patrick Ohly20d49472009-02-12 05:03:38 +0000215 }
H. J. Luee4fa232012-02-19 17:50:46 -0800216 if (level == SOL_SOCKET &&
217 (type == SCM_TIMESTAMPNS || type == SCM_TIMESTAMPING)) {
218 int count = type == SCM_TIMESTAMPNS ? 1 : 3;
219 int i;
220 struct timespec *ts = (struct timespec *)data;
221 for (i = 0; i < count; i++) {
222 cts[i].tv_sec = ts[i].tv_sec;
223 cts[i].tv_nsec = ts[i].tv_nsec;
224 }
225 data = &cts;
226 len = sizeof(cts[0]) * count;
227 }
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +0900228 }
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 cmlen = CMSG_COMPAT_LEN(len);
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700231 if (kmsg->msg_controllen < cmlen) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 kmsg->msg_flags |= MSG_CTRUNC;
233 cmlen = kmsg->msg_controllen;
234 }
235 cmhdr.cmsg_level = level;
236 cmhdr.cmsg_type = type;
237 cmhdr.cmsg_len = cmlen;
238
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700239 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return -EFAULT;
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700241 if (copy_to_user(CMSG_COMPAT_DATA(cm), data, cmlen - sizeof(struct compat_cmsghdr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 return -EFAULT;
243 cmlen = CMSG_COMPAT_SPACE(len);
Wei Yongjun1ac70e72007-12-20 14:36:44 -0800244 if (kmsg->msg_controllen < cmlen)
245 cmlen = kmsg->msg_controllen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 kmsg->msg_control += cmlen;
247 kmsg->msg_controllen -= cmlen;
248 return 0;
249}
250
251void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
252{
253 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
254 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
255 int fdnum = scm->fp->count;
256 struct file **fp = scm->fp->fp;
257 int __user *cmfptr;
258 int err = 0, i;
259
260 if (fdnum < fdmax)
261 fdmax = fdnum;
262
263 for (i = 0, cmfptr = (int __user *) CMSG_COMPAT_DATA(cm); i < fdmax; i++, cmfptr++) {
264 int new_fd;
265 err = security_file_receive(fp[i]);
266 if (err)
267 break;
Ulrich Drepper4a195422007-07-15 23:40:34 -0700268 err = get_unused_fd_flags(MSG_CMSG_CLOEXEC & kmsg->msg_flags
269 ? O_CLOEXEC : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (err < 0)
271 break;
272 new_fd = err;
273 err = put_user(new_fd, cmfptr);
274 if (err) {
275 put_unused_fd(new_fd);
276 break;
277 }
278 /* Bump the usage count and install the file. */
Al Virocb0942b2012-08-27 14:48:26 -0400279 fd_install(new_fd, get_file(fp[i]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281
282 if (i > 0) {
283 int cmlen = CMSG_COMPAT_LEN(i * sizeof(int));
Miklos Szeredieffee6a2006-10-09 21:42:14 -0700284 err = put_user(SOL_SOCKET, &cm->cmsg_level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if (!err)
286 err = put_user(SCM_RIGHTS, &cm->cmsg_type);
287 if (!err)
288 err = put_user(cmlen, &cm->cmsg_len);
289 if (!err) {
290 cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
291 kmsg->msg_control += cmlen;
292 kmsg->msg_controllen -= cmlen;
293 }
294 }
295 if (i < fdnum)
296 kmsg->msg_flags |= MSG_CTRUNC;
297
298 /*
299 * All of the files that fit in the message have had their
300 * usage counts incremented, so we just free the list.
301 */
302 __scm_destroy(scm);
303}
304
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800305static int do_set_attach_filter(struct socket *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700306 char __user *optval, unsigned int optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
308 struct compat_sock_fprog __user *fprog32 = (struct compat_sock_fprog __user *)optval;
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +0900309 struct sock_fprog __user *kfprog = compat_alloc_user_space(sizeof(struct sock_fprog));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 compat_uptr_t ptr;
311 u16 len;
312
313 if (!access_ok(VERIFY_READ, fprog32, sizeof(*fprog32)) ||
314 !access_ok(VERIFY_WRITE, kfprog, sizeof(struct sock_fprog)) ||
315 __get_user(len, &fprog32->len) ||
316 __get_user(ptr, &fprog32->filter) ||
317 __put_user(len, &kfprog->len) ||
318 __put_user(compat_ptr(ptr), &kfprog->filter))
319 return -EFAULT;
320
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800321 return sock_setsockopt(sock, level, optname, (char __user *)kfprog,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 sizeof(struct sock_fprog));
323}
324
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800325static int do_set_sock_timeout(struct socket *sock, int level,
David S. Millerb7058842009-09-30 16:12:20 -0700326 int optname, char __user *optval, unsigned int optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700328 struct compat_timeval __user *up = (struct compat_timeval __user *)optval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 struct timeval ktime;
330 mm_segment_t old_fs;
331 int err;
332
333 if (optlen < sizeof(*up))
334 return -EINVAL;
335 if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
336 __get_user(ktime.tv_sec, &up->tv_sec) ||
337 __get_user(ktime.tv_usec, &up->tv_usec))
338 return -EFAULT;
339 old_fs = get_fs();
340 set_fs(KERNEL_DS);
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700341 err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 set_fs(old_fs);
343
344 return err;
345}
346
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800347static int compat_sock_setsockopt(struct socket *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700348 char __user *optval, unsigned int optlen)
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800349{
350 if (optname == SO_ATTACH_FILTER)
351 return do_set_attach_filter(sock, level, optname,
352 optval, optlen);
353 if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
354 return do_set_sock_timeout(sock, level, optname, optval, optlen);
355
356 return sock_setsockopt(sock, level, optname, optval, optlen);
357}
358
Heiko Carstens361d93c2014-03-03 16:21:27 +0100359COMPAT_SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname,
360 char __user *, optval, unsigned int, optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800362 int err;
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700363 struct socket *sock = sockfd_lookup(fd, &err);
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800364
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700365 if (sock) {
366 err = security_socket_setsockopt(sock, level, optname);
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800367 if (err) {
368 sockfd_put(sock);
369 return err;
370 }
371
372 if (level == SOL_SOCKET)
373 err = compat_sock_setsockopt(sock, level,
374 optname, optval, optlen);
375 else if (sock->ops->compat_setsockopt)
376 err = sock->ops->compat_setsockopt(sock, level,
377 optname, optval, optlen);
378 else
379 err = sock->ops->setsockopt(sock, level,
380 optname, optval, optlen);
381 sockfd_put(sock);
382 }
383 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800386static int do_get_sock_timeout(struct socket *sock, int level, int optname,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 char __user *optval, int __user *optlen)
388{
389 struct compat_timeval __user *up;
390 struct timeval ktime;
391 mm_segment_t old_fs;
392 int len, err;
393
394 up = (struct compat_timeval __user *) optval;
395 if (get_user(len, optlen))
396 return -EFAULT;
397 if (len < sizeof(*up))
398 return -EINVAL;
399 len = sizeof(ktime);
400 old_fs = get_fs();
401 set_fs(KERNEL_DS);
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800402 err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 set_fs(old_fs);
404
405 if (!err) {
406 if (put_user(sizeof(*up), optlen) ||
407 !access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
408 __put_user(ktime.tv_sec, &up->tv_sec) ||
409 __put_user(ktime.tv_usec, &up->tv_usec))
410 err = -EFAULT;
411 }
412 return err;
413}
414
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800415static int compat_sock_getsockopt(struct socket *sock, int level, int optname,
416 char __user *optval, int __user *optlen)
417{
418 if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
419 return do_get_sock_timeout(sock, level, optname, optval, optlen);
420 return sock_getsockopt(sock, level, optname, optval, optlen);
421}
422
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800423int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
424{
H. J. Luee4fa232012-02-19 17:50:46 -0800425 struct compat_timeval __user *ctv;
426 int err;
Eric Dumazetb7aa0bf2007-04-19 16:16:32 -0700427 struct timeval tv;
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800428
H. J. Luee4fa232012-02-19 17:50:46 -0800429 if (COMPAT_USE_64BIT_TIME)
430 return sock_get_timestamp(sk, userstamp);
431
432 ctv = (struct compat_timeval __user *) userstamp;
433 err = -ENOENT;
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800434 if (!sock_flag(sk, SOCK_TIMESTAMP))
Patrick Ohly20d49472009-02-12 05:03:38 +0000435 sock_enable_timestamp(sk, SOCK_TIMESTAMP);
Eric Dumazetb7aa0bf2007-04-19 16:16:32 -0700436 tv = ktime_to_timeval(sk->sk_stamp);
437 if (tv.tv_sec == -1)
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800438 return err;
Eric Dumazetb7aa0bf2007-04-19 16:16:32 -0700439 if (tv.tv_sec == 0) {
440 sk->sk_stamp = ktime_get_real();
441 tv = ktime_to_timeval(sk->sk_stamp);
442 }
443 err = 0;
444 if (put_user(tv.tv_sec, &ctv->tv_sec) ||
445 put_user(tv.tv_usec, &ctv->tv_usec))
Shaun Pereiraf0ac2612006-03-21 23:59:39 -0800446 err = -EFAULT;
447 return err;
448}
449EXPORT_SYMBOL(compat_sock_get_timestamp);
450
Eric Dumazetae40eb12007-03-18 17:33:16 -0700451int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
452{
H. J. Luee4fa232012-02-19 17:50:46 -0800453 struct compat_timespec __user *ctv;
454 int err;
Eric Dumazetae40eb12007-03-18 17:33:16 -0700455 struct timespec ts;
456
H. J. Luee4fa232012-02-19 17:50:46 -0800457 if (COMPAT_USE_64BIT_TIME)
458 return sock_get_timestampns (sk, userstamp);
459
460 ctv = (struct compat_timespec __user *) userstamp;
461 err = -ENOENT;
Eric Dumazetae40eb12007-03-18 17:33:16 -0700462 if (!sock_flag(sk, SOCK_TIMESTAMP))
Patrick Ohly20d49472009-02-12 05:03:38 +0000463 sock_enable_timestamp(sk, SOCK_TIMESTAMP);
Eric Dumazetae40eb12007-03-18 17:33:16 -0700464 ts = ktime_to_timespec(sk->sk_stamp);
465 if (ts.tv_sec == -1)
466 return err;
467 if (ts.tv_sec == 0) {
468 sk->sk_stamp = ktime_get_real();
469 ts = ktime_to_timespec(sk->sk_stamp);
470 }
471 err = 0;
472 if (put_user(ts.tv_sec, &ctv->tv_sec) ||
473 put_user(ts.tv_nsec, &ctv->tv_nsec))
474 err = -EFAULT;
475 return err;
476}
477EXPORT_SYMBOL(compat_sock_get_timestampns);
478
Heiko Carstens361d93c2014-03-03 16:21:27 +0100479COMPAT_SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname,
480 char __user *, optval, int __user *, optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800482 int err;
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700483 struct socket *sock = sockfd_lookup(fd, &err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700485 if (sock) {
486 err = security_socket_getsockopt(sock, level, optname);
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800487 if (err) {
488 sockfd_put(sock);
489 return err;
490 }
491
492 if (level == SOL_SOCKET)
493 err = compat_sock_getsockopt(sock, level,
494 optname, optval, optlen);
495 else if (sock->ops->compat_getsockopt)
496 err = sock->ops->compat_getsockopt(sock, level,
497 optname, optval, optlen);
498 else
499 err = sock->ops->getsockopt(sock, level,
500 optname, optval, optlen);
501 sockfd_put(sock);
502 }
503 return err;
504}
David L Stevensdae50292008-04-27 01:06:07 -0700505
506struct compat_group_req {
507 __u32 gr_interface;
508 struct __kernel_sockaddr_storage gr_group
509 __attribute__ ((aligned(4)));
Eric Dumazetbc105022010-06-03 03:21:52 -0700510} __packed;
David L Stevensdae50292008-04-27 01:06:07 -0700511
512struct compat_group_source_req {
513 __u32 gsr_interface;
514 struct __kernel_sockaddr_storage gsr_group
515 __attribute__ ((aligned(4)));
516 struct __kernel_sockaddr_storage gsr_source
517 __attribute__ ((aligned(4)));
Eric Dumazetbc105022010-06-03 03:21:52 -0700518} __packed;
David L Stevensdae50292008-04-27 01:06:07 -0700519
520struct compat_group_filter {
521 __u32 gf_interface;
522 struct __kernel_sockaddr_storage gf_group
523 __attribute__ ((aligned(4)));
524 __u32 gf_fmode;
525 __u32 gf_numsrc;
526 struct __kernel_sockaddr_storage gf_slist[1]
527 __attribute__ ((aligned(4)));
Eric Dumazetbc105022010-06-03 03:21:52 -0700528} __packed;
David L Stevensdae50292008-04-27 01:06:07 -0700529
David L Stevensbe666e02008-04-29 03:23:00 -0700530#define __COMPAT_GF0_SIZE (sizeof(struct compat_group_filter) - \
531 sizeof(struct __kernel_sockaddr_storage))
532
David L Stevensdae50292008-04-27 01:06:07 -0700533
534int compat_mc_setsockopt(struct sock *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700535 char __user *optval, unsigned int optlen,
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700536 int (*setsockopt)(struct sock *, int, int, char __user *, unsigned int))
David L Stevensdae50292008-04-27 01:06:07 -0700537{
538 char __user *koptval = optval;
539 int koptlen = optlen;
540
541 switch (optname) {
542 case MCAST_JOIN_GROUP:
543 case MCAST_LEAVE_GROUP:
544 {
545 struct compat_group_req __user *gr32 = (void *)optval;
546 struct group_req __user *kgr =
547 compat_alloc_user_space(sizeof(struct group_req));
548 u32 interface;
549
550 if (!access_ok(VERIFY_READ, gr32, sizeof(*gr32)) ||
551 !access_ok(VERIFY_WRITE, kgr, sizeof(struct group_req)) ||
552 __get_user(interface, &gr32->gr_interface) ||
553 __put_user(interface, &kgr->gr_interface) ||
554 copy_in_user(&kgr->gr_group, &gr32->gr_group,
555 sizeof(kgr->gr_group)))
556 return -EFAULT;
557 koptval = (char __user *)kgr;
558 koptlen = sizeof(struct group_req);
559 break;
560 }
561 case MCAST_JOIN_SOURCE_GROUP:
562 case MCAST_LEAVE_SOURCE_GROUP:
563 case MCAST_BLOCK_SOURCE:
564 case MCAST_UNBLOCK_SOURCE:
565 {
566 struct compat_group_source_req __user *gsr32 = (void *)optval;
David L Stevensbe666e02008-04-29 03:23:00 -0700567 struct group_source_req __user *kgsr = compat_alloc_user_space(
David L Stevensdae50292008-04-27 01:06:07 -0700568 sizeof(struct group_source_req));
569 u32 interface;
570
571 if (!access_ok(VERIFY_READ, gsr32, sizeof(*gsr32)) ||
572 !access_ok(VERIFY_WRITE, kgsr,
573 sizeof(struct group_source_req)) ||
574 __get_user(interface, &gsr32->gsr_interface) ||
575 __put_user(interface, &kgsr->gsr_interface) ||
576 copy_in_user(&kgsr->gsr_group, &gsr32->gsr_group,
577 sizeof(kgsr->gsr_group)) ||
578 copy_in_user(&kgsr->gsr_source, &gsr32->gsr_source,
579 sizeof(kgsr->gsr_source)))
580 return -EFAULT;
581 koptval = (char __user *)kgsr;
582 koptlen = sizeof(struct group_source_req);
583 break;
584 }
585 case MCAST_MSFILTER:
586 {
587 struct compat_group_filter __user *gf32 = (void *)optval;
David L Stevensbe666e02008-04-29 03:23:00 -0700588 struct group_filter __user *kgf;
David L Stevensdae50292008-04-27 01:06:07 -0700589 u32 interface, fmode, numsrc;
590
David L Stevensbe666e02008-04-29 03:23:00 -0700591 if (!access_ok(VERIFY_READ, gf32, __COMPAT_GF0_SIZE) ||
David L Stevensdae50292008-04-27 01:06:07 -0700592 __get_user(interface, &gf32->gf_interface) ||
593 __get_user(fmode, &gf32->gf_fmode) ||
594 __get_user(numsrc, &gf32->gf_numsrc))
595 return -EFAULT;
596 koptlen = optlen + sizeof(struct group_filter) -
597 sizeof(struct compat_group_filter);
598 if (koptlen < GROUP_FILTER_SIZE(numsrc))
599 return -EINVAL;
600 kgf = compat_alloc_user_space(koptlen);
601 if (!access_ok(VERIFY_WRITE, kgf, koptlen) ||
602 __put_user(interface, &kgf->gf_interface) ||
603 __put_user(fmode, &kgf->gf_fmode) ||
604 __put_user(numsrc, &kgf->gf_numsrc) ||
605 copy_in_user(&kgf->gf_group, &gf32->gf_group,
606 sizeof(kgf->gf_group)) ||
David L Stevensbe666e02008-04-29 03:23:00 -0700607 (numsrc && copy_in_user(kgf->gf_slist, gf32->gf_slist,
David L Stevensdae50292008-04-27 01:06:07 -0700608 numsrc * sizeof(kgf->gf_slist[0]))))
609 return -EFAULT;
610 koptval = (char __user *)kgf;
611 break;
612 }
613
614 default:
615 break;
616 }
617 return setsockopt(sock, level, optname, koptval, koptlen);
618}
David L Stevensdae50292008-04-27 01:06:07 -0700619EXPORT_SYMBOL(compat_mc_setsockopt);
620
David L Stevens42908c62008-04-29 03:23:22 -0700621int compat_mc_getsockopt(struct sock *sock, int level, int optname,
622 char __user *optval, int __user *optlen,
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700623 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
David L Stevens42908c62008-04-29 03:23:22 -0700624{
625 struct compat_group_filter __user *gf32 = (void *)optval;
626 struct group_filter __user *kgf;
627 int __user *koptlen;
628 u32 interface, fmode, numsrc;
629 int klen, ulen, err;
630
631 if (optname != MCAST_MSFILTER)
632 return getsockopt(sock, level, optname, optval, optlen);
633
634 koptlen = compat_alloc_user_space(sizeof(*koptlen));
635 if (!access_ok(VERIFY_READ, optlen, sizeof(*optlen)) ||
636 __get_user(ulen, optlen))
637 return -EFAULT;
638
639 /* adjust len for pad */
640 klen = ulen + sizeof(*kgf) - sizeof(*gf32);
641
642 if (klen < GROUP_FILTER_SIZE(0))
643 return -EINVAL;
644
645 if (!access_ok(VERIFY_WRITE, koptlen, sizeof(*koptlen)) ||
646 __put_user(klen, koptlen))
647 return -EFAULT;
648
649 /* have to allow space for previous compat_alloc_user_space, too */
650 kgf = compat_alloc_user_space(klen+sizeof(*optlen));
651
652 if (!access_ok(VERIFY_READ, gf32, __COMPAT_GF0_SIZE) ||
653 __get_user(interface, &gf32->gf_interface) ||
654 __get_user(fmode, &gf32->gf_fmode) ||
655 __get_user(numsrc, &gf32->gf_numsrc) ||
656 __put_user(interface, &kgf->gf_interface) ||
657 __put_user(fmode, &kgf->gf_fmode) ||
658 __put_user(numsrc, &kgf->gf_numsrc) ||
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700659 copy_in_user(&kgf->gf_group, &gf32->gf_group, sizeof(kgf->gf_group)))
David L Stevens42908c62008-04-29 03:23:22 -0700660 return -EFAULT;
661
662 err = getsockopt(sock, level, optname, (char __user *)kgf, koptlen);
663 if (err)
664 return err;
665
666 if (!access_ok(VERIFY_READ, koptlen, sizeof(*koptlen)) ||
667 __get_user(klen, koptlen))
668 return -EFAULT;
669
670 ulen = klen - (sizeof(*kgf)-sizeof(*gf32));
671
672 if (!access_ok(VERIFY_WRITE, optlen, sizeof(*optlen)) ||
673 __put_user(ulen, optlen))
674 return -EFAULT;
675
676 if (!access_ok(VERIFY_READ, kgf, klen) ||
677 !access_ok(VERIFY_WRITE, gf32, ulen) ||
678 __get_user(interface, &kgf->gf_interface) ||
679 __get_user(fmode, &kgf->gf_fmode) ||
680 __get_user(numsrc, &kgf->gf_numsrc) ||
681 __put_user(interface, &gf32->gf_interface) ||
682 __put_user(fmode, &gf32->gf_fmode) ||
683 __put_user(numsrc, &gf32->gf_numsrc))
684 return -EFAULT;
685 if (numsrc) {
686 int copylen;
687
688 klen -= GROUP_FILTER_SIZE(0);
689 copylen = numsrc * sizeof(gf32->gf_slist[0]);
690 if (copylen > klen)
691 copylen = klen;
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700692 if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen))
David L Stevens42908c62008-04-29 03:23:22 -0700693 return -EFAULT;
694 }
695 return err;
696}
David L Stevens42908c62008-04-29 03:23:22 -0700697EXPORT_SYMBOL(compat_mc_getsockopt);
698
David L Stevensdae50292008-04-27 01:06:07 -0700699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700/* Argument list sizes for compat_sys_socketcall */
701#define AL(x) ((x) * sizeof(u32))
Anton Blanchard228e5482011-05-02 20:21:35 +0000702static unsigned char nas[21] = {
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700703 AL(0), AL(3), AL(3), AL(3), AL(2), AL(3),
704 AL(3), AL(3), AL(4), AL(4), AL(4), AL(6),
705 AL(6), AL(2), AL(5), AL(5), AL(3), AL(3),
Anton Blanchard228e5482011-05-02 20:21:35 +0000706 AL(4), AL(5), AL(4)
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700707};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708#undef AL
709
Heiko Carstens361d93c2014-03-03 16:21:27 +0100710COMPAT_SYSCALL_DEFINE3(sendmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
Andy Lutomirskia7526eb2013-06-05 19:38:26 +0000712 if (flags & MSG_CMSG_COMPAT)
713 return -EINVAL;
Al Viro666547f2014-04-06 14:03:05 -0400714 return __sys_sendmsg(fd, (struct user_msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715}
716
Heiko Carstens361d93c2014-03-03 16:21:27 +0100717COMPAT_SYSCALL_DEFINE4(sendmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
718 unsigned int, vlen, unsigned int, flags)
Anton Blanchard228e5482011-05-02 20:21:35 +0000719{
Andy Lutomirskia7526eb2013-06-05 19:38:26 +0000720 if (flags & MSG_CMSG_COMPAT)
721 return -EINVAL;
Anton Blanchard228e5482011-05-02 20:21:35 +0000722 return __sys_sendmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
723 flags | MSG_CMSG_COMPAT);
724}
725
Heiko Carstens361d93c2014-03-03 16:21:27 +0100726COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
Andy Lutomirskia7526eb2013-06-05 19:38:26 +0000728 if (flags & MSG_CMSG_COMPAT)
729 return -EINVAL;
Al Viro666547f2014-04-06 14:03:05 -0400730 return __sys_recvmsg(fd, (struct user_msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731}
732
Heiko Carstens3a49a0f2014-03-04 17:09:57 +0100733COMPAT_SYSCALL_DEFINE4(recv, int, fd, void __user *, buf, compat_size_t, len, unsigned int, flags)
Johannes Berg1dacc762009-07-01 11:26:02 +0000734{
735 return sys_recv(fd, buf, len, flags | MSG_CMSG_COMPAT);
736}
737
Heiko Carstens3a49a0f2014-03-04 17:09:57 +0100738COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, len,
739 unsigned int, flags, struct sockaddr __user *, addr,
740 int __user *, addrlen)
Johannes Berg1dacc762009-07-01 11:26:02 +0000741{
742 return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen);
743}
744
Heiko Carstens361d93c2014-03-03 16:21:27 +0100745COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
746 unsigned int, vlen, unsigned int, flags,
747 struct compat_timespec __user *, timeout)
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700748{
749 int datagrams;
750 struct timespec ktspec;
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700751
Andy Lutomirskia7526eb2013-06-05 19:38:26 +0000752 if (flags & MSG_CMSG_COMPAT)
753 return -EINVAL;
754
Jean-Mickael Guerin5b231362009-12-01 07:52:16 +0000755 if (timeout == NULL)
756 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
757 flags | MSG_CMSG_COMPAT, NULL);
758
PaX Team2def2ef2014-01-30 16:59:25 -0800759 if (compat_get_timespec(&ktspec, timeout))
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700760 return -EFAULT;
761
762 datagrams = __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
763 flags | MSG_CMSG_COMPAT, &ktspec);
PaX Team2def2ef2014-01-30 16:59:25 -0800764 if (datagrams > 0 && compat_put_timespec(&ktspec, timeout))
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700765 datagrams = -EFAULT;
766
767 return datagrams;
768}
769
Heiko Carstens361d93c2014-03-03 16:21:27 +0100770COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771{
772 int ret;
773 u32 a[6];
774 u32 a0, a1;
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +0900775
Anton Blanchard228e5482011-05-02 20:21:35 +0000776 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 return -EINVAL;
778 if (copy_from_user(a, args, nas[call]))
779 return -EFAULT;
780 a0 = a[0];
781 a1 = a[1];
YOSHIFUJI Hideaki4768fbc2007-02-09 23:25:31 +0900782
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700783 switch (call) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 case SYS_SOCKET:
785 ret = sys_socket(a0, a1, a[2]);
786 break;
787 case SYS_BIND:
788 ret = sys_bind(a0, compat_ptr(a1), a[2]);
789 break;
790 case SYS_CONNECT:
791 ret = sys_connect(a0, compat_ptr(a1), a[2]);
792 break;
793 case SYS_LISTEN:
794 ret = sys_listen(a0, a1);
795 break;
796 case SYS_ACCEPT:
Ulrich Drepperde11def2008-11-19 15:36:14 -0800797 ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 break;
799 case SYS_GETSOCKNAME:
800 ret = sys_getsockname(a0, compat_ptr(a1), compat_ptr(a[2]));
801 break;
802 case SYS_GETPEERNAME:
803 ret = sys_getpeername(a0, compat_ptr(a1), compat_ptr(a[2]));
804 break;
805 case SYS_SOCKETPAIR:
806 ret = sys_socketpair(a0, a1, a[2], compat_ptr(a[3]));
807 break;
808 case SYS_SEND:
809 ret = sys_send(a0, compat_ptr(a1), a[2], a[3]);
810 break;
811 case SYS_SENDTO:
812 ret = sys_sendto(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), a[5]);
813 break;
814 case SYS_RECV:
Johannes Berg1dacc762009-07-01 11:26:02 +0000815 ret = compat_sys_recv(a0, compat_ptr(a1), a[2], a[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 break;
817 case SYS_RECVFROM:
Johannes Berg1dacc762009-07-01 11:26:02 +0000818 ret = compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3],
819 compat_ptr(a[4]), compat_ptr(a[5]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 break;
821 case SYS_SHUTDOWN:
Eric Dumazetc6d409c2010-06-03 20:03:40 -0700822 ret = sys_shutdown(a0, a1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 break;
824 case SYS_SETSOCKOPT:
825 ret = compat_sys_setsockopt(a0, a1, a[2],
826 compat_ptr(a[3]), a[4]);
827 break;
828 case SYS_GETSOCKOPT:
829 ret = compat_sys_getsockopt(a0, a1, a[2],
830 compat_ptr(a[3]), compat_ptr(a[4]));
831 break;
832 case SYS_SENDMSG:
833 ret = compat_sys_sendmsg(a0, compat_ptr(a1), a[2]);
834 break;
Anton Blanchard228e5482011-05-02 20:21:35 +0000835 case SYS_SENDMMSG:
836 ret = compat_sys_sendmmsg(a0, compat_ptr(a1), a[2], a[3]);
837 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 case SYS_RECVMSG:
839 ret = compat_sys_recvmsg(a0, compat_ptr(a1), a[2]);
840 break;
Arnaldo Carvalho de Meloa2e27252009-10-12 23:40:10 -0700841 case SYS_RECVMMSG:
842 ret = compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3],
843 compat_ptr(a[4]));
844 break;
Ulrich Drepperde11def2008-11-19 15:36:14 -0800845 case SYS_ACCEPT4:
846 ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]);
Ulrich Drepperaaca0bd2008-07-23 21:29:20 -0700847 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 default:
849 ret = -EINVAL;
850 break;
851 }
852 return ret;
853}