Commit | Line | Data |
---|---|---|
457c8996 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
4768fbcb | 2 | /* |
1da177e4 LT |
3 | * 32bit Socket syscall emulation. Based on arch/sparc64/kernel/sys_sparc32.c. |
4 | * | |
5 | * Copyright (C) 2000 VA Linux Co | |
6 | * Copyright (C) 2000 Don Dugger <n0ano@valinux.com> | |
7 | * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com> | |
8 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | |
9 | * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) | |
10 | * Copyright (C) 2000 Hewlett-Packard Co. | |
11 | * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com> | |
4768fbcb | 12 | * Copyright (C) 2000,2001 Andi Kleen, SuSE Labs |
1da177e4 LT |
13 | */ |
14 | ||
15 | #include <linux/kernel.h> | |
5a0e3ad6 | 16 | #include <linux/gfp.h> |
1da177e4 | 17 | #include <linux/fs.h> |
1da177e4 LT |
18 | #include <linux/types.h> |
19 | #include <linux/file.h> | |
20 | #include <linux/icmpv6.h> | |
21 | #include <linux/socket.h> | |
22 | #include <linux/syscalls.h> | |
23 | #include <linux/filter.h> | |
24 | #include <linux/compat.h> | |
1da177e4 | 25 | #include <linux/security.h> |
62bc306e | 26 | #include <linux/audit.h> |
bc3b2d7f | 27 | #include <linux/export.h> |
1da177e4 LT |
28 | |
29 | #include <net/scm.h> | |
30 | #include <net/sock.h> | |
dae50295 DS |
31 | #include <net/ip.h> |
32 | #include <net/ipv6.h> | |
7c0f6ba6 | 33 | #include <linux/uaccess.h> |
1da177e4 LT |
34 | #include <net/compat.h> |
35 | ||
0a384abf | 36 | int __get_compat_msghdr(struct msghdr *kmsg, |
72c531f8 DY |
37 | struct compat_msghdr *msg, |
38 | struct sockaddr __user **save_addr) | |
1da177e4 | 39 | { |
08adb7da | 40 | ssize_t err; |
1da177e4 | 41 | |
72c531f8 DY |
42 | kmsg->msg_flags = msg->msg_flags; |
43 | kmsg->msg_namelen = msg->msg_namelen; | |
5da028a8 | 44 | |
72c531f8 | 45 | if (!msg->msg_name) |
91edd096 CM |
46 | kmsg->msg_namelen = 0; |
47 | ||
48 | if (kmsg->msg_namelen < 0) | |
49 | return -EINVAL; | |
50 | ||
1661bf36 | 51 | if (kmsg->msg_namelen > sizeof(struct sockaddr_storage)) |
db31c55a | 52 | kmsg->msg_namelen = sizeof(struct sockaddr_storage); |
5da028a8 | 53 | |
1f466e1f | 54 | kmsg->msg_control_is_user = true; |
d547c1b7 | 55 | kmsg->msg_get_inq = 0; |
72c531f8 DY |
56 | kmsg->msg_control_user = compat_ptr(msg->msg_control); |
57 | kmsg->msg_controllen = msg->msg_controllen; | |
1da177e4 | 58 | |
08adb7da | 59 | if (save_addr) |
72c531f8 | 60 | *save_addr = compat_ptr(msg->msg_name); |
1da177e4 | 61 | |
72c531f8 | 62 | if (msg->msg_name && kmsg->msg_namelen) { |
08adb7da | 63 | if (!save_addr) { |
72c531f8 | 64 | err = move_addr_to_kernel(compat_ptr(msg->msg_name), |
08adb7da AV |
65 | kmsg->msg_namelen, |
66 | kmsg->msg_name); | |
e71a4783 | 67 | if (err < 0) |
1da177e4 LT |
68 | return err; |
69 | } | |
40eea803 | 70 | } else { |
08adb7da AV |
71 | kmsg->msg_name = NULL; |
72 | kmsg->msg_namelen = 0; | |
40eea803 | 73 | } |
1da177e4 | 74 | |
72c531f8 | 75 | if (msg->msg_iovlen > UIO_MAXIOV) |
08449320 AV |
76 | return -EMSGSIZE; |
77 | ||
0345f931 | 78 | kmsg->msg_iocb = NULL; |
7c701d92 | 79 | kmsg->msg_ubuf = NULL; |
0a384abf JA |
80 | return 0; |
81 | } | |
82 | ||
83 | int get_compat_msghdr(struct msghdr *kmsg, | |
84 | struct compat_msghdr __user *umsg, | |
85 | struct sockaddr __user **save_addr, | |
86 | struct iovec **iov) | |
87 | { | |
72c531f8 | 88 | struct compat_msghdr msg; |
0a384abf JA |
89 | ssize_t err; |
90 | ||
72c531f8 DY |
91 | if (copy_from_user(&msg, umsg, sizeof(*umsg))) |
92 | return -EFAULT; | |
93 | ||
4f6a94d3 | 94 | err = __get_compat_msghdr(kmsg, &msg, save_addr); |
0a384abf JA |
95 | if (err) |
96 | return err; | |
0345f931 | 97 | |
de4eda9d AV |
98 | err = import_iovec(save_addr ? ITER_DEST : ITER_SOURCE, |
99 | compat_ptr(msg.msg_iov), msg.msg_iovlen, | |
89cd35c5 | 100 | UIO_FASTIOV, iov, &kmsg->msg_iter); |
87e5e6da | 101 | return err < 0 ? err : 0; |
1da177e4 LT |
102 | } |
103 | ||
104 | /* Bleech... */ | |
105 | #define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32)) | |
106 | ||
107 | #define CMSG_COMPAT_DATA(cmsg) \ | |
1ff8cebf | 108 | ((void __user *)((char __user *)(cmsg) + sizeof(struct compat_cmsghdr))) |
1da177e4 | 109 | #define CMSG_COMPAT_SPACE(len) \ |
1ff8cebf | 110 | (sizeof(struct compat_cmsghdr) + CMSG_COMPAT_ALIGN(len)) |
1da177e4 | 111 | #define CMSG_COMPAT_LEN(len) \ |
1ff8cebf | 112 | (sizeof(struct compat_cmsghdr) + (len)) |
1da177e4 LT |
113 | |
114 | #define CMSG_COMPAT_FIRSTHDR(msg) \ | |
115 | (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \ | |
116 | (struct compat_cmsghdr __user *)((msg)->msg_control) : \ | |
117 | (struct compat_cmsghdr __user *)NULL) | |
118 | ||
119 | #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \ | |
120 | ((ucmlen) >= sizeof(struct compat_cmsghdr) && \ | |
121 | (ucmlen) <= (unsigned long) \ | |
122 | ((mhdr)->msg_controllen - \ | |
1f466e1f | 123 | ((char __user *)(ucmsg) - (char __user *)(mhdr)->msg_control_user))) |
1da177e4 LT |
124 | |
125 | static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg, | |
126 | struct compat_cmsghdr __user *cmsg, int cmsg_len) | |
127 | { | |
128 | char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len); | |
129 | if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) > | |
130 | msg->msg_controllen) | |
131 | return NULL; | |
132 | return (struct compat_cmsghdr __user *)ptr; | |
133 | } | |
134 | ||
135 | /* There is a lot of hair here because the alignment rules (and | |
136 | * thus placement) of cmsg headers and length are different for | |
137 | * 32-bit apps. -DaveM | |
138 | */ | |
8920e8f9 | 139 | int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk, |
1da177e4 LT |
140 | unsigned char *stackbuf, int stackbuf_size) |
141 | { | |
142 | struct compat_cmsghdr __user *ucmsg; | |
143 | struct cmsghdr *kcmsg, *kcmsg_base; | |
144 | compat_size_t ucmlen; | |
145 | __kernel_size_t kcmlen, tmp; | |
8920e8f9 | 146 | int err = -EFAULT; |
1da177e4 | 147 | |
ac4340fc DM |
148 | BUILD_BUG_ON(sizeof(struct compat_cmsghdr) != |
149 | CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))); | |
150 | ||
1da177e4 LT |
151 | kcmlen = 0; |
152 | kcmsg_base = kcmsg = (struct cmsghdr *)stackbuf; | |
153 | ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg); | |
e71a4783 SH |
154 | while (ucmsg != NULL) { |
155 | if (get_user(ucmlen, &ucmsg->cmsg_len)) | |
1da177e4 LT |
156 | return -EFAULT; |
157 | ||
158 | /* Catch bogons. */ | |
159 | if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg)) | |
160 | return -EINVAL; | |
161 | ||
1ff8cebf | 162 | tmp = ((ucmlen - sizeof(*ucmsg)) + sizeof(struct cmsghdr)); |
8920e8f9 | 163 | tmp = CMSG_ALIGN(tmp); |
1da177e4 LT |
164 | kcmlen += tmp; |
165 | ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen); | |
166 | } | |
e71a4783 | 167 | if (kcmlen == 0) |
1da177e4 LT |
168 | return -EINVAL; |
169 | ||
170 | /* The kcmlen holds the 64-bit version of the control length. | |
171 | * It may not be modified as we do not stick it into the kmsg | |
172 | * until we have successfully copied over all of the data | |
173 | * from the user. | |
174 | */ | |
8920e8f9 AV |
175 | if (kcmlen > stackbuf_size) |
176 | kcmsg_base = kcmsg = sock_kmalloc(sk, kcmlen, GFP_KERNEL); | |
177 | if (kcmsg == NULL) | |
49251cd0 | 178 | return -ENOMEM; |
1da177e4 LT |
179 | |
180 | /* Now copy them over neatly. */ | |
181 | memset(kcmsg, 0, kcmlen); | |
182 | ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg); | |
e71a4783 | 183 | while (ucmsg != NULL) { |
547ce4cf AV |
184 | struct compat_cmsghdr cmsg; |
185 | if (copy_from_user(&cmsg, ucmsg, sizeof(cmsg))) | |
8920e8f9 | 186 | goto Efault; |
547ce4cf | 187 | if (!CMSG_COMPAT_OK(cmsg.cmsg_len, ucmsg, kmsg)) |
8920e8f9 | 188 | goto Einval; |
547ce4cf | 189 | tmp = ((cmsg.cmsg_len - sizeof(*ucmsg)) + sizeof(struct cmsghdr)); |
8920e8f9 AV |
190 | if ((char *)kcmsg_base + kcmlen - (char *)kcmsg < CMSG_ALIGN(tmp)) |
191 | goto Einval; | |
1da177e4 | 192 | kcmsg->cmsg_len = tmp; |
547ce4cf AV |
193 | kcmsg->cmsg_level = cmsg.cmsg_level; |
194 | kcmsg->cmsg_type = cmsg.cmsg_type; | |
8920e8f9 | 195 | tmp = CMSG_ALIGN(tmp); |
547ce4cf | 196 | if (copy_from_user(CMSG_DATA(kcmsg), |
8920e8f9 | 197 | CMSG_COMPAT_DATA(ucmsg), |
547ce4cf | 198 | (cmsg.cmsg_len - sizeof(*ucmsg)))) |
8920e8f9 | 199 | goto Efault; |
1da177e4 LT |
200 | |
201 | /* Advance. */ | |
8920e8f9 | 202 | kcmsg = (struct cmsghdr *)((char *)kcmsg + tmp); |
181964e6 | 203 | ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, cmsg.cmsg_len); |
1da177e4 LT |
204 | } |
205 | ||
c2a64bb9 MX |
206 | /* |
207 | * check the length of messages copied in is the same as the | |
208 | * what we get from the first loop | |
209 | */ | |
210 | if ((char *)kcmsg - (char *)kcmsg_base != kcmlen) | |
211 | goto Einval; | |
212 | ||
1da177e4 LT |
213 | /* Ok, looks like we made it. Hook it up and return success. */ |
214 | kmsg->msg_control = kcmsg_base; | |
215 | kmsg->msg_controllen = kcmlen; | |
216 | return 0; | |
217 | ||
8920e8f9 AV |
218 | Einval: |
219 | err = -EINVAL; | |
220 | Efault: | |
221 | if (kcmsg_base != (struct cmsghdr *)stackbuf) | |
222 | sock_kfree_s(sk, kcmsg_base, kcmlen); | |
223 | return err; | |
1da177e4 LT |
224 | } |
225 | ||
226 | int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data) | |
227 | { | |
1da177e4 LT |
228 | struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control; |
229 | struct compat_cmsghdr cmhdr; | |
13c6ee2a DD |
230 | struct old_timeval32 ctv; |
231 | struct old_timespec32 cts[3]; | |
1da177e4 LT |
232 | int cmlen; |
233 | ||
e71a4783 | 234 | if (cm == NULL || kmsg->msg_controllen < sizeof(*cm)) { |
1da177e4 LT |
235 | kmsg->msg_flags |= MSG_CTRUNC; |
236 | return 0; /* XXX: return error? check spec. */ | |
237 | } | |
238 | ||
ee4fa23c | 239 | if (!COMPAT_USE_64BIT_TIME) { |
7f1bc6e9 | 240 | if (level == SOL_SOCKET && type == SO_TIMESTAMP_OLD) { |
13c6ee2a | 241 | struct __kernel_old_timeval *tv = (struct __kernel_old_timeval *)data; |
ee4fa23c L |
242 | ctv.tv_sec = tv->tv_sec; |
243 | ctv.tv_usec = tv->tv_usec; | |
244 | data = &ctv; | |
245 | len = sizeof(ctv); | |
246 | } | |
247 | if (level == SOL_SOCKET && | |
7f1bc6e9 DD |
248 | (type == SO_TIMESTAMPNS_OLD || type == SO_TIMESTAMPING_OLD)) { |
249 | int count = type == SO_TIMESTAMPNS_OLD ? 1 : 3; | |
ee4fa23c | 250 | int i; |
df1b4ba9 | 251 | struct __kernel_old_timespec *ts = data; |
ee4fa23c L |
252 | for (i = 0; i < count; i++) { |
253 | cts[i].tv_sec = ts[i].tv_sec; | |
254 | cts[i].tv_nsec = ts[i].tv_nsec; | |
255 | } | |
256 | data = &cts; | |
257 | len = sizeof(cts[0]) * count; | |
20d49473 | 258 | } |
4768fbcb YH |
259 | } |
260 | ||
1da177e4 | 261 | cmlen = CMSG_COMPAT_LEN(len); |
e71a4783 | 262 | if (kmsg->msg_controllen < cmlen) { |
1da177e4 LT |
263 | kmsg->msg_flags |= MSG_CTRUNC; |
264 | cmlen = kmsg->msg_controllen; | |
265 | } | |
266 | cmhdr.cmsg_level = level; | |
267 | cmhdr.cmsg_type = type; | |
268 | cmhdr.cmsg_len = cmlen; | |
269 | ||
e71a4783 | 270 | if (copy_to_user(cm, &cmhdr, sizeof cmhdr)) |
1da177e4 | 271 | return -EFAULT; |
e71a4783 | 272 | if (copy_to_user(CMSG_COMPAT_DATA(cm), data, cmlen - sizeof(struct compat_cmsghdr))) |
1da177e4 LT |
273 | return -EFAULT; |
274 | cmlen = CMSG_COMPAT_SPACE(len); | |
1ac70e7a WY |
275 | if (kmsg->msg_controllen < cmlen) |
276 | cmlen = kmsg->msg_controllen; | |
1da177e4 LT |
277 | kmsg->msg_control += cmlen; |
278 | kmsg->msg_controllen -= cmlen; | |
279 | return 0; | |
280 | } | |
281 | ||
c0029de5 | 282 | static int scm_max_fds_compat(struct msghdr *msg) |
1da177e4 | 283 | { |
c0029de5 KC |
284 | if (msg->msg_controllen <= sizeof(struct compat_cmsghdr)) |
285 | return 0; | |
286 | return (msg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int); | |
287 | } | |
1da177e4 | 288 | |
c0029de5 KC |
289 | void scm_detach_fds_compat(struct msghdr *msg, struct scm_cookie *scm) |
290 | { | |
291 | struct compat_cmsghdr __user *cm = | |
292 | (struct compat_cmsghdr __user *)msg->msg_control; | |
293 | unsigned int o_flags = (msg->msg_flags & MSG_CMSG_CLOEXEC) ? O_CLOEXEC : 0; | |
294 | int fdmax = min_t(int, scm_max_fds_compat(msg), scm->fp->count); | |
16b89f69 | 295 | int __user *cmsg_data = CMSG_COMPAT_DATA(cm); |
c0029de5 | 296 | int err = 0, i; |
1da177e4 | 297 | |
c0029de5 | 298 | for (i = 0; i < fdmax; i++) { |
66590610 | 299 | err = receive_fd_user(scm->fp->fp[i], cmsg_data + i, o_flags); |
1da177e4 LT |
300 | if (err < 0) |
301 | break; | |
1da177e4 LT |
302 | } |
303 | ||
304 | if (i > 0) { | |
305 | int cmlen = CMSG_COMPAT_LEN(i * sizeof(int)); | |
c0029de5 | 306 | |
effee6a0 | 307 | err = put_user(SOL_SOCKET, &cm->cmsg_level); |
1da177e4 LT |
308 | if (!err) |
309 | err = put_user(SCM_RIGHTS, &cm->cmsg_type); | |
310 | if (!err) | |
311 | err = put_user(cmlen, &cm->cmsg_len); | |
312 | if (!err) { | |
313 | cmlen = CMSG_COMPAT_SPACE(i * sizeof(int)); | |
c0029de5 KC |
314 | if (msg->msg_controllen < cmlen) |
315 | cmlen = msg->msg_controllen; | |
316 | msg->msg_control += cmlen; | |
317 | msg->msg_controllen -= cmlen; | |
1da177e4 LT |
318 | } |
319 | } | |
c0029de5 KC |
320 | |
321 | if (i < scm->fp->count || (scm->fp->count && fdmax <= 0)) | |
322 | msg->msg_flags |= MSG_CTRUNC; | |
1da177e4 LT |
323 | |
324 | /* | |
c0029de5 KC |
325 | * All of the files that fit in the message have had their usage counts |
326 | * incremented, so we just free the list. | |
1da177e4 LT |
327 | */ |
328 | __scm_destroy(scm); | |
329 | } | |
330 | ||
1da177e4 LT |
331 | /* Argument list sizes for compat_sys_socketcall */ |
332 | #define AL(x) ((x) * sizeof(u32)) | |
228e548e | 333 | static unsigned char nas[21] = { |
c6d409cf ED |
334 | AL(0), AL(3), AL(3), AL(3), AL(2), AL(3), |
335 | AL(3), AL(3), AL(4), AL(4), AL(4), AL(6), | |
336 | AL(6), AL(2), AL(5), AL(5), AL(3), AL(3), | |
228e548e | 337 | AL(4), AL(5), AL(4) |
c6d409cf | 338 | }; |
1da177e4 LT |
339 | #undef AL |
340 | ||
6df35465 DB |
341 | static inline long __compat_sys_sendmsg(int fd, |
342 | struct compat_msghdr __user *msg, | |
343 | unsigned int flags) | |
1da177e4 | 344 | { |
e1834a32 DB |
345 | return __sys_sendmsg(fd, (struct user_msghdr __user *)msg, |
346 | flags | MSG_CMSG_COMPAT, false); | |
1da177e4 LT |
347 | } |
348 | ||
6df35465 DB |
349 | COMPAT_SYSCALL_DEFINE3(sendmsg, int, fd, struct compat_msghdr __user *, msg, |
350 | unsigned int, flags) | |
351 | { | |
352 | return __compat_sys_sendmsg(fd, msg, flags); | |
353 | } | |
354 | ||
355 | static inline long __compat_sys_sendmmsg(int fd, | |
356 | struct compat_mmsghdr __user *mmsg, | |
357 | unsigned int vlen, unsigned int flags) | |
228e548e AB |
358 | { |
359 | return __sys_sendmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, | |
e1834a32 | 360 | flags | MSG_CMSG_COMPAT, false); |
228e548e AB |
361 | } |
362 | ||
6df35465 DB |
363 | COMPAT_SYSCALL_DEFINE4(sendmmsg, int, fd, struct compat_mmsghdr __user *, mmsg, |
364 | unsigned int, vlen, unsigned int, flags) | |
365 | { | |
366 | return __compat_sys_sendmmsg(fd, mmsg, vlen, flags); | |
367 | } | |
368 | ||
369 | static inline long __compat_sys_recvmsg(int fd, | |
370 | struct compat_msghdr __user *msg, | |
371 | unsigned int flags) | |
1da177e4 | 372 | { |
e1834a32 DB |
373 | return __sys_recvmsg(fd, (struct user_msghdr __user *)msg, |
374 | flags | MSG_CMSG_COMPAT, false); | |
1da177e4 LT |
375 | } |
376 | ||
6df35465 DB |
377 | COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *, msg, |
378 | unsigned int, flags) | |
379 | { | |
380 | return __compat_sys_recvmsg(fd, msg, flags); | |
381 | } | |
382 | ||
fd4e82f5 DB |
383 | static inline long __compat_sys_recvfrom(int fd, void __user *buf, |
384 | compat_size_t len, unsigned int flags, | |
385 | struct sockaddr __user *addr, | |
386 | int __user *addrlen) | |
387 | { | |
388 | return __sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, | |
389 | addrlen); | |
390 | } | |
391 | ||
3a49a0f7 | 392 | COMPAT_SYSCALL_DEFINE4(recv, int, fd, void __user *, buf, compat_size_t, len, unsigned int, flags) |
1dacc76d | 393 | { |
fd4e82f5 | 394 | return __compat_sys_recvfrom(fd, buf, len, flags, NULL, NULL); |
1dacc76d JB |
395 | } |
396 | ||
3a49a0f7 HC |
397 | COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, len, |
398 | unsigned int, flags, struct sockaddr __user *, addr, | |
399 | int __user *, addrlen) | |
1dacc76d | 400 | { |
fd4e82f5 | 401 | return __compat_sys_recvfrom(fd, buf, len, flags, addr, addrlen); |
1dacc76d JB |
402 | } |
403 | ||
e11d4284 AB |
404 | COMPAT_SYSCALL_DEFINE5(recvmmsg_time64, int, fd, struct compat_mmsghdr __user *, mmsg, |
405 | unsigned int, vlen, unsigned int, flags, | |
406 | struct __kernel_timespec __user *, timeout) | |
a2e27255 | 407 | { |
e11d4284 AB |
408 | return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, |
409 | flags | MSG_CMSG_COMPAT, timeout, NULL); | |
a2e27255 ACM |
410 | } |
411 | ||
e11d4284 | 412 | #ifdef CONFIG_COMPAT_32BIT_TIME |
8dabe724 | 413 | COMPAT_SYSCALL_DEFINE5(recvmmsg_time32, int, fd, struct compat_mmsghdr __user *, mmsg, |
157b334a | 414 | unsigned int, vlen, unsigned int, flags, |
9afc5eee | 415 | struct old_timespec32 __user *, timeout) |
157b334a | 416 | { |
e11d4284 AB |
417 | return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, |
418 | flags | MSG_CMSG_COMPAT, NULL, timeout); | |
157b334a | 419 | } |
e11d4284 | 420 | #endif |
157b334a | 421 | |
361d93c4 | 422 | COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args) |
1da177e4 | 423 | { |
62bc306e RGB |
424 | u32 a[AUDITSC_ARGS]; |
425 | unsigned int len; | |
1da177e4 | 426 | u32 a0, a1; |
62bc306e | 427 | int ret; |
4768fbcb | 428 | |
228e548e | 429 | if (call < SYS_SOCKET || call > SYS_SENDMMSG) |
1da177e4 | 430 | return -EINVAL; |
62bc306e RGB |
431 | len = nas[call]; |
432 | if (len > sizeof(a)) | |
433 | return -EINVAL; | |
434 | ||
435 | if (copy_from_user(a, args, len)) | |
1da177e4 | 436 | return -EFAULT; |
62bc306e RGB |
437 | |
438 | ret = audit_socketcall_compat(len / sizeof(a[0]), a); | |
439 | if (ret) | |
440 | return ret; | |
441 | ||
1da177e4 LT |
442 | a0 = a[0]; |
443 | a1 = a[1]; | |
4768fbcb | 444 | |
e71a4783 | 445 | switch (call) { |
1da177e4 | 446 | case SYS_SOCKET: |
9d6a15c3 | 447 | ret = __sys_socket(a0, a1, a[2]); |
1da177e4 LT |
448 | break; |
449 | case SYS_BIND: | |
a87d35d8 | 450 | ret = __sys_bind(a0, compat_ptr(a1), a[2]); |
1da177e4 LT |
451 | break; |
452 | case SYS_CONNECT: | |
1387c2c2 | 453 | ret = __sys_connect(a0, compat_ptr(a1), a[2]); |
1da177e4 LT |
454 | break; |
455 | case SYS_LISTEN: | |
25e290ee | 456 | ret = __sys_listen(a0, a1); |
1da177e4 LT |
457 | break; |
458 | case SYS_ACCEPT: | |
4541e805 | 459 | ret = __sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), 0); |
1da177e4 LT |
460 | break; |
461 | case SYS_GETSOCKNAME: | |
8882a107 | 462 | ret = __sys_getsockname(a0, compat_ptr(a1), compat_ptr(a[2])); |
1da177e4 LT |
463 | break; |
464 | case SYS_GETPEERNAME: | |
b21c8f83 | 465 | ret = __sys_getpeername(a0, compat_ptr(a1), compat_ptr(a[2])); |
1da177e4 LT |
466 | break; |
467 | case SYS_SOCKETPAIR: | |
6debc8d8 | 468 | ret = __sys_socketpair(a0, a1, a[2], compat_ptr(a[3])); |
1da177e4 LT |
469 | break; |
470 | case SYS_SEND: | |
f3bf896b | 471 | ret = __sys_sendto(a0, compat_ptr(a1), a[2], a[3], NULL, 0); |
1da177e4 LT |
472 | break; |
473 | case SYS_SENDTO: | |
211b634b DB |
474 | ret = __sys_sendto(a0, compat_ptr(a1), a[2], a[3], |
475 | compat_ptr(a[4]), a[5]); | |
1da177e4 LT |
476 | break; |
477 | case SYS_RECV: | |
fd4e82f5 DB |
478 | ret = __compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3], |
479 | NULL, NULL); | |
1da177e4 LT |
480 | break; |
481 | case SYS_RECVFROM: | |
fd4e82f5 DB |
482 | ret = __compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3], |
483 | compat_ptr(a[4]), | |
484 | compat_ptr(a[5])); | |
1da177e4 LT |
485 | break; |
486 | case SYS_SHUTDOWN: | |
005a1aea | 487 | ret = __sys_shutdown(a0, a1); |
1da177e4 LT |
488 | break; |
489 | case SYS_SETSOCKOPT: | |
55db9c0e | 490 | ret = __sys_setsockopt(a0, a1, a[2], compat_ptr(a[3]), a[4]); |
1da177e4 LT |
491 | break; |
492 | case SYS_GETSOCKOPT: | |
55db9c0e CH |
493 | ret = __sys_getsockopt(a0, a1, a[2], compat_ptr(a[3]), |
494 | compat_ptr(a[4])); | |
1da177e4 LT |
495 | break; |
496 | case SYS_SENDMSG: | |
6df35465 | 497 | ret = __compat_sys_sendmsg(a0, compat_ptr(a1), a[2]); |
1da177e4 | 498 | break; |
228e548e | 499 | case SYS_SENDMMSG: |
6df35465 | 500 | ret = __compat_sys_sendmmsg(a0, compat_ptr(a1), a[2], a[3]); |
228e548e | 501 | break; |
1da177e4 | 502 | case SYS_RECVMSG: |
6df35465 | 503 | ret = __compat_sys_recvmsg(a0, compat_ptr(a1), a[2]); |
1da177e4 | 504 | break; |
a2e27255 | 505 | case SYS_RECVMMSG: |
e11d4284 AB |
506 | ret = __sys_recvmmsg(a0, compat_ptr(a1), a[2], |
507 | a[3] | MSG_CMSG_COMPAT, NULL, | |
508 | compat_ptr(a[4])); | |
a2e27255 | 509 | break; |
de11defe | 510 | case SYS_ACCEPT4: |
4541e805 | 511 | ret = __sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]); |
aaca0bdc | 512 | break; |
1da177e4 LT |
513 | default: |
514 | ret = -EINVAL; | |
515 | break; | |
516 | } | |
517 | return ret; | |
518 | } |