2 * 32bit Socket syscall emulation. Based on arch/sparc64/kernel/sys_sparc32.c.
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>
11 * Copyright (C) 2000,2001 Andi Kleen, SuSE Labs
14 #include <linux/kernel.h>
15 #include <linux/gfp.h>
17 #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>
24 #include <linux/security.h>
25 #include <linux/export.h>
31 #include <asm/uaccess.h>
32 #include <net/compat.h>
34 ssize_t
get_compat_msghdr(struct msghdr
*kmsg
,
35 struct compat_msghdr __user
*umsg
,
36 struct sockaddr __user
**save_addr
,
39 compat_uptr_t uaddr
, uiov
, tmp3
;
40 compat_size_t nr_segs
;
43 if (!access_ok(VERIFY_READ
, umsg
, sizeof(*umsg
)) ||
44 __get_user(uaddr
, &umsg
->msg_name
) ||
45 __get_user(kmsg
->msg_namelen
, &umsg
->msg_namelen
) ||
46 __get_user(uiov
, &umsg
->msg_iov
) ||
47 __get_user(nr_segs
, &umsg
->msg_iovlen
) ||
48 __get_user(tmp3
, &umsg
->msg_control
) ||
49 __get_user(kmsg
->msg_controllen
, &umsg
->msg_controllen
) ||
50 __get_user(kmsg
->msg_flags
, &umsg
->msg_flags
))
52 if (kmsg
->msg_namelen
> sizeof(struct sockaddr_storage
))
53 kmsg
->msg_namelen
= sizeof(struct sockaddr_storage
);
54 kmsg
->msg_control
= compat_ptr(tmp3
);
57 *save_addr
= compat_ptr(uaddr
);
59 if (uaddr
&& kmsg
->msg_namelen
) {
61 err
= move_addr_to_kernel(compat_ptr(uaddr
),
68 kmsg
->msg_name
= NULL
;
69 kmsg
->msg_namelen
= 0;
72 if (nr_segs
> UIO_MAXIOV
)
75 err
= compat_rw_copy_check_uvector(save_addr
? READ
: WRITE
,
76 compat_ptr(uiov
), nr_segs
,
77 UIO_FASTIOV
, *iov
, iov
);
79 iov_iter_init(&kmsg
->msg_iter
, save_addr
? READ
: WRITE
,
85 #define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32))
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))
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)
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)))
105 static inline struct compat_cmsghdr __user
*cmsg_compat_nxthdr(struct msghdr
*msg
,
106 struct compat_cmsghdr __user
*cmsg
, int cmsg_len
)
108 char __user
*ptr
= (char __user
*)cmsg
+ CMSG_COMPAT_ALIGN(cmsg_len
);
109 if ((unsigned long)(ptr
+ 1 - (char __user
*)msg
->msg_control
) >
112 return (struct compat_cmsghdr __user
*)ptr
;
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
119 int cmsghdr_from_user_compat_to_kern(struct msghdr
*kmsg
, struct sock
*sk
,
120 unsigned char *stackbuf
, int stackbuf_size
)
122 struct compat_cmsghdr __user
*ucmsg
;
123 struct cmsghdr
*kcmsg
, *kcmsg_base
;
124 compat_size_t ucmlen
;
125 __kernel_size_t kcmlen
, tmp
;
129 kcmsg_base
= kcmsg
= (struct cmsghdr
*)stackbuf
;
130 ucmsg
= CMSG_COMPAT_FIRSTHDR(kmsg
);
131 while (ucmsg
!= NULL
) {
132 if (get_user(ucmlen
, &ucmsg
->cmsg_len
))
136 if (!CMSG_COMPAT_OK(ucmlen
, ucmsg
, kmsg
))
139 tmp
= ((ucmlen
- CMSG_COMPAT_ALIGN(sizeof(*ucmsg
))) +
140 CMSG_ALIGN(sizeof(struct cmsghdr
)));
141 tmp
= CMSG_ALIGN(tmp
);
143 ucmsg
= cmsg_compat_nxthdr(kmsg
, ucmsg
, ucmlen
);
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
153 if (kcmlen
> stackbuf_size
)
154 kcmsg_base
= kcmsg
= sock_kmalloc(sk
, kcmlen
, GFP_KERNEL
);
158 /* Now copy them over neatly. */
159 memset(kcmsg
, 0, kcmlen
);
160 ucmsg
= CMSG_COMPAT_FIRSTHDR(kmsg
);
161 while (ucmsg
!= NULL
) {
162 if (__get_user(ucmlen
, &ucmsg
->cmsg_len
))
164 if (!CMSG_COMPAT_OK(ucmlen
, ucmsg
, kmsg
))
166 tmp
= ((ucmlen
- CMSG_COMPAT_ALIGN(sizeof(*ucmsg
))) +
167 CMSG_ALIGN(sizeof(struct cmsghdr
)));
168 if ((char *)kcmsg_base
+ kcmlen
- (char *)kcmsg
< CMSG_ALIGN(tmp
))
170 kcmsg
->cmsg_len
= tmp
;
171 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
)))))
180 kcmsg
= (struct cmsghdr
*)((char *)kcmsg
+ tmp
);
181 ucmsg
= cmsg_compat_nxthdr(kmsg
, ucmsg
, ucmlen
);
184 /* Ok, looks like we made it. Hook it up and return success. */
185 kmsg
->msg_control
= kcmsg_base
;
186 kmsg
->msg_controllen
= kcmlen
;
192 if (kcmsg_base
!= (struct cmsghdr
*)stackbuf
)
193 sock_kfree_s(sk
, kcmsg_base
, kcmlen
);
197 int put_cmsg_compat(struct msghdr
*kmsg
, int level
, int type
, int len
, void *data
)
199 struct compat_cmsghdr __user
*cm
= (struct compat_cmsghdr __user
*) kmsg
->msg_control
;
200 struct compat_cmsghdr cmhdr
;
201 struct compat_timeval ctv
;
202 struct compat_timespec cts
[3];
205 if (cm
== NULL
|| kmsg
->msg_controllen
< sizeof(*cm
)) {
206 kmsg
->msg_flags
|= MSG_CTRUNC
;
207 return 0; /* XXX: return error? check spec. */
210 if (!COMPAT_USE_64BIT_TIME
) {
211 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
;
218 if (level
== SOL_SOCKET
&&
219 (type
== SCM_TIMESTAMPNS
|| type
== SCM_TIMESTAMPING
)) {
220 int count
= type
== SCM_TIMESTAMPNS
? 1 : 3;
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
;
228 len
= sizeof(cts
[0]) * count
;
232 cmlen
= CMSG_COMPAT_LEN(len
);
233 if (kmsg
->msg_controllen
< cmlen
) {
234 kmsg
->msg_flags
|= MSG_CTRUNC
;
235 cmlen
= kmsg
->msg_controllen
;
237 cmhdr
.cmsg_level
= level
;
238 cmhdr
.cmsg_type
= type
;
239 cmhdr
.cmsg_len
= cmlen
;
241 if (copy_to_user(cm
, &cmhdr
, sizeof cmhdr
))
243 if (copy_to_user(CMSG_COMPAT_DATA(cm
), data
, cmlen
- sizeof(struct compat_cmsghdr
)))
245 cmlen
= CMSG_COMPAT_SPACE(len
);
246 if (kmsg
->msg_controllen
< cmlen
)
247 cmlen
= kmsg
->msg_controllen
;
248 kmsg
->msg_control
+= cmlen
;
249 kmsg
->msg_controllen
-= cmlen
;
253 void scm_detach_fds_compat(struct msghdr
*kmsg
, struct scm_cookie
*scm
)
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
;
265 for (i
= 0, cmfptr
= (int __user
*) CMSG_COMPAT_DATA(cm
); i
< fdmax
; i
++, cmfptr
++) {
267 err
= security_file_receive(fp
[i
]);
270 err
= get_unused_fd_flags(MSG_CMSG_CLOEXEC
& kmsg
->msg_flags
275 err
= put_user(new_fd
, cmfptr
);
277 put_unused_fd(new_fd
);
280 /* Bump the usage count and install the file. */
281 fd_install(new_fd
, get_file(fp
[i
]));
285 int cmlen
= CMSG_COMPAT_LEN(i
* sizeof(int));
286 err
= put_user(SOL_SOCKET
, &cm
->cmsg_level
);
288 err
= put_user(SCM_RIGHTS
, &cm
->cmsg_type
);
290 err
= put_user(cmlen
, &cm
->cmsg_len
);
292 cmlen
= CMSG_COMPAT_SPACE(i
* sizeof(int));
293 kmsg
->msg_control
+= cmlen
;
294 kmsg
->msg_controllen
-= cmlen
;
298 kmsg
->msg_flags
|= MSG_CTRUNC
;
301 * All of the files that fit in the message have had their
302 * usage counts incremented, so we just free the list.
307 static int do_set_attach_filter(struct socket
*sock
, int level
, int optname
,
308 char __user
*optval
, unsigned int optlen
)
310 struct compat_sock_fprog __user
*fprog32
= (struct compat_sock_fprog __user
*)optval
;
311 struct sock_fprog __user
*kfprog
= compat_alloc_user_space(sizeof(struct sock_fprog
));
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
))
323 return sock_setsockopt(sock
, level
, optname
, (char __user
*)kfprog
,
324 sizeof(struct sock_fprog
));
327 static int do_set_sock_timeout(struct socket
*sock
, int level
,
328 int optname
, char __user
*optval
, unsigned int optlen
)
330 struct compat_timeval __user
*up
= (struct compat_timeval __user
*)optval
;
331 struct timeval ktime
;
335 if (optlen
< sizeof(*up
))
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
))
343 err
= sock_setsockopt(sock
, level
, optname
, (char *)&ktime
, sizeof(ktime
));
349 static int compat_sock_setsockopt(struct socket
*sock
, int level
, int optname
,
350 char __user
*optval
, unsigned int optlen
)
352 if (optname
== SO_ATTACH_FILTER
)
353 return do_set_attach_filter(sock
, level
, optname
,
355 if (optname
== SO_RCVTIMEO
|| optname
== SO_SNDTIMEO
)
356 return do_set_sock_timeout(sock
, level
, optname
, optval
, optlen
);
358 return sock_setsockopt(sock
, level
, optname
, optval
, optlen
);
361 COMPAT_SYSCALL_DEFINE5(setsockopt
, int, fd
, int, level
, int, optname
,
362 char __user
*, optval
, unsigned int, optlen
)
365 struct socket
*sock
= sockfd_lookup(fd
, &err
);
368 err
= security_socket_setsockopt(sock
, level
, optname
);
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
);
381 err
= sock
->ops
->setsockopt(sock
, level
,
382 optname
, optval
, optlen
);
388 static int do_get_sock_timeout(struct socket
*sock
, int level
, int optname
,
389 char __user
*optval
, int __user
*optlen
)
391 struct compat_timeval __user
*up
;
392 struct timeval ktime
;
396 up
= (struct compat_timeval __user
*) optval
;
397 if (get_user(len
, optlen
))
399 if (len
< sizeof(*up
))
404 err
= sock_getsockopt(sock
, level
, optname
, (char *) &ktime
, &len
);
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
))
417 static int compat_sock_getsockopt(struct socket
*sock
, int level
, int optname
,
418 char __user
*optval
, int __user
*optlen
)
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
);
425 int compat_sock_get_timestamp(struct sock
*sk
, struct timeval __user
*userstamp
)
427 struct compat_timeval __user
*ctv
;
431 if (COMPAT_USE_64BIT_TIME
)
432 return sock_get_timestamp(sk
, userstamp
);
434 ctv
= (struct compat_timeval __user
*) userstamp
;
436 if (!sock_flag(sk
, SOCK_TIMESTAMP
))
437 sock_enable_timestamp(sk
, SOCK_TIMESTAMP
);
438 tv
= ktime_to_timeval(sk
->sk_stamp
);
441 if (tv
.tv_sec
== 0) {
442 sk
->sk_stamp
= ktime_get_real();
443 tv
= ktime_to_timeval(sk
->sk_stamp
);
446 if (put_user(tv
.tv_sec
, &ctv
->tv_sec
) ||
447 put_user(tv
.tv_usec
, &ctv
->tv_usec
))
451 EXPORT_SYMBOL(compat_sock_get_timestamp
);
453 int compat_sock_get_timestampns(struct sock
*sk
, struct timespec __user
*userstamp
)
455 struct compat_timespec __user
*ctv
;
459 if (COMPAT_USE_64BIT_TIME
)
460 return sock_get_timestampns (sk
, userstamp
);
462 ctv
= (struct compat_timespec __user
*) userstamp
;
464 if (!sock_flag(sk
, SOCK_TIMESTAMP
))
465 sock_enable_timestamp(sk
, SOCK_TIMESTAMP
);
466 ts
= ktime_to_timespec(sk
->sk_stamp
);
469 if (ts
.tv_sec
== 0) {
470 sk
->sk_stamp
= ktime_get_real();
471 ts
= ktime_to_timespec(sk
->sk_stamp
);
474 if (put_user(ts
.tv_sec
, &ctv
->tv_sec
) ||
475 put_user(ts
.tv_nsec
, &ctv
->tv_nsec
))
479 EXPORT_SYMBOL(compat_sock_get_timestampns
);
481 COMPAT_SYSCALL_DEFINE5(getsockopt
, int, fd
, int, level
, int, optname
,
482 char __user
*, optval
, int __user
*, optlen
)
485 struct socket
*sock
= sockfd_lookup(fd
, &err
);
488 err
= security_socket_getsockopt(sock
, level
, optname
);
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
);
501 err
= sock
->ops
->getsockopt(sock
, level
,
502 optname
, optval
, optlen
);
508 struct compat_group_req
{
510 struct __kernel_sockaddr_storage gr_group
511 __attribute__ ((aligned(4)));
514 struct compat_group_source_req
{
516 struct __kernel_sockaddr_storage gsr_group
517 __attribute__ ((aligned(4)));
518 struct __kernel_sockaddr_storage gsr_source
519 __attribute__ ((aligned(4)));
522 struct compat_group_filter
{
524 struct __kernel_sockaddr_storage gf_group
525 __attribute__ ((aligned(4)));
528 struct __kernel_sockaddr_storage gf_slist
[1]
529 __attribute__ ((aligned(4)));
532 #define __COMPAT_GF0_SIZE (sizeof(struct compat_group_filter) - \
533 sizeof(struct __kernel_sockaddr_storage))
536 int compat_mc_setsockopt(struct sock
*sock
, int level
, int optname
,
537 char __user
*optval
, unsigned int optlen
,
538 int (*setsockopt
)(struct sock
*, int, int, char __user
*, unsigned int))
540 char __user
*koptval
= optval
;
541 int koptlen
= optlen
;
544 case MCAST_JOIN_GROUP
:
545 case MCAST_LEAVE_GROUP
:
547 struct compat_group_req __user
*gr32
= (void *)optval
;
548 struct group_req __user
*kgr
=
549 compat_alloc_user_space(sizeof(struct group_req
));
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
)))
559 koptval
= (char __user
*)kgr
;
560 koptlen
= sizeof(struct group_req
);
563 case MCAST_JOIN_SOURCE_GROUP
:
564 case MCAST_LEAVE_SOURCE_GROUP
:
565 case MCAST_BLOCK_SOURCE
:
566 case MCAST_UNBLOCK_SOURCE
:
568 struct compat_group_source_req __user
*gsr32
= (void *)optval
;
569 struct group_source_req __user
*kgsr
= compat_alloc_user_space(
570 sizeof(struct group_source_req
));
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
)))
583 koptval
= (char __user
*)kgsr
;
584 koptlen
= sizeof(struct group_source_req
);
589 struct compat_group_filter __user
*gf32
= (void *)optval
;
590 struct group_filter __user
*kgf
;
591 u32 interface
, fmode
, numsrc
;
593 if (!access_ok(VERIFY_READ
, gf32
, __COMPAT_GF0_SIZE
) ||
594 __get_user(interface
, &gf32
->gf_interface
) ||
595 __get_user(fmode
, &gf32
->gf_fmode
) ||
596 __get_user(numsrc
, &gf32
->gf_numsrc
))
598 koptlen
= optlen
+ sizeof(struct group_filter
) -
599 sizeof(struct compat_group_filter
);
600 if (koptlen
< GROUP_FILTER_SIZE(numsrc
))
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
)) ||
609 (numsrc
&& copy_in_user(kgf
->gf_slist
, gf32
->gf_slist
,
610 numsrc
* sizeof(kgf
->gf_slist
[0]))))
612 koptval
= (char __user
*)kgf
;
619 return setsockopt(sock
, level
, optname
, koptval
, koptlen
);
621 EXPORT_SYMBOL(compat_mc_setsockopt
);
623 int compat_mc_getsockopt(struct sock
*sock
, int level
, int optname
,
624 char __user
*optval
, int __user
*optlen
,
625 int (*getsockopt
)(struct sock
*, int, int, char __user
*, int __user
*))
627 struct compat_group_filter __user
*gf32
= (void *)optval
;
628 struct group_filter __user
*kgf
;
630 u32 interface
, fmode
, numsrc
;
633 if (optname
!= MCAST_MSFILTER
)
634 return getsockopt(sock
, level
, optname
, optval
, optlen
);
636 koptlen
= compat_alloc_user_space(sizeof(*koptlen
));
637 if (!access_ok(VERIFY_READ
, optlen
, sizeof(*optlen
)) ||
638 __get_user(ulen
, optlen
))
641 /* adjust len for pad */
642 klen
= ulen
+ sizeof(*kgf
) - sizeof(*gf32
);
644 if (klen
< GROUP_FILTER_SIZE(0))
647 if (!access_ok(VERIFY_WRITE
, koptlen
, sizeof(*koptlen
)) ||
648 __put_user(klen
, koptlen
))
651 /* have to allow space for previous compat_alloc_user_space, too */
652 kgf
= compat_alloc_user_space(klen
+sizeof(*optlen
));
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
) ||
661 copy_in_user(&kgf
->gf_group
, &gf32
->gf_group
, sizeof(kgf
->gf_group
)))
664 err
= getsockopt(sock
, level
, optname
, (char __user
*)kgf
, koptlen
);
668 if (!access_ok(VERIFY_READ
, koptlen
, sizeof(*koptlen
)) ||
669 __get_user(klen
, koptlen
))
672 ulen
= klen
- (sizeof(*kgf
)-sizeof(*gf32
));
674 if (!access_ok(VERIFY_WRITE
, optlen
, sizeof(*optlen
)) ||
675 __put_user(ulen
, optlen
))
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
))
690 klen
-= GROUP_FILTER_SIZE(0);
691 copylen
= numsrc
* sizeof(gf32
->gf_slist
[0]);
694 if (copy_in_user(gf32
->gf_slist
, kgf
->gf_slist
, copylen
))
699 EXPORT_SYMBOL(compat_mc_getsockopt
);
702 /* Argument list sizes for compat_sys_socketcall */
703 #define AL(x) ((x) * sizeof(u32))
704 static unsigned char nas
[21] = {
705 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),
712 COMPAT_SYSCALL_DEFINE3(sendmsg
, int, fd
, struct compat_msghdr __user
*, msg
, unsigned int, flags
)
714 return __sys_sendmsg(fd
, (struct user_msghdr __user
*)msg
, flags
| MSG_CMSG_COMPAT
);
717 COMPAT_SYSCALL_DEFINE4(sendmmsg
, int, fd
, struct compat_mmsghdr __user
*, mmsg
,
718 unsigned int, vlen
, unsigned int, flags
)
720 return __sys_sendmmsg(fd
, (struct mmsghdr __user
*)mmsg
, vlen
,
721 flags
| MSG_CMSG_COMPAT
);
724 COMPAT_SYSCALL_DEFINE3(recvmsg
, int, fd
, struct compat_msghdr __user
*, msg
, unsigned int, flags
)
726 return __sys_recvmsg(fd
, (struct user_msghdr __user
*)msg
, flags
| MSG_CMSG_COMPAT
);
729 COMPAT_SYSCALL_DEFINE4(recv
, int, fd
, void __user
*, buf
, compat_size_t
, len
, unsigned int, flags
)
731 return sys_recv(fd
, buf
, len
, flags
| MSG_CMSG_COMPAT
);
734 COMPAT_SYSCALL_DEFINE6(recvfrom
, int, fd
, void __user
*, buf
, compat_size_t
, len
,
735 unsigned int, flags
, struct sockaddr __user
*, addr
,
736 int __user
*, addrlen
)
738 return sys_recvfrom(fd
, buf
, len
, flags
| MSG_CMSG_COMPAT
, addr
, addrlen
);
741 COMPAT_SYSCALL_DEFINE5(recvmmsg
, int, fd
, struct compat_mmsghdr __user
*, mmsg
,
742 unsigned int, vlen
, unsigned int, flags
,
743 struct compat_timespec __user
*, timeout
)
746 struct timespec ktspec
;
749 return __sys_recvmmsg(fd
, (struct mmsghdr __user
*)mmsg
, vlen
,
750 flags
| MSG_CMSG_COMPAT
, NULL
);
752 if (compat_get_timespec(&ktspec
, timeout
))
755 datagrams
= __sys_recvmmsg(fd
, (struct mmsghdr __user
*)mmsg
, vlen
,
756 flags
| MSG_CMSG_COMPAT
, &ktspec
);
757 if (datagrams
> 0 && compat_put_timespec(&ktspec
, timeout
))
763 COMPAT_SYSCALL_DEFINE2(socketcall
, int, call
, u32 __user
*, args
)
769 if (call
< SYS_SOCKET
|| call
> SYS_SENDMMSG
)
771 if (copy_from_user(a
, args
, nas
[call
]))
778 ret
= sys_socket(a0
, a1
, a
[2]);
781 ret
= sys_bind(a0
, compat_ptr(a1
), a
[2]);
784 ret
= sys_connect(a0
, compat_ptr(a1
), a
[2]);
787 ret
= sys_listen(a0
, a1
);
790 ret
= sys_accept4(a0
, compat_ptr(a1
), compat_ptr(a
[2]), 0);
792 case SYS_GETSOCKNAME
:
793 ret
= sys_getsockname(a0
, compat_ptr(a1
), compat_ptr(a
[2]));
795 case SYS_GETPEERNAME
:
796 ret
= sys_getpeername(a0
, compat_ptr(a1
), compat_ptr(a
[2]));
799 ret
= sys_socketpair(a0
, a1
, a
[2], compat_ptr(a
[3]));
802 ret
= sys_send(a0
, compat_ptr(a1
), a
[2], a
[3]);
805 ret
= sys_sendto(a0
, compat_ptr(a1
), a
[2], a
[3], compat_ptr(a
[4]), a
[5]);
808 ret
= compat_sys_recv(a0
, compat_ptr(a1
), a
[2], a
[3]);
811 ret
= compat_sys_recvfrom(a0
, compat_ptr(a1
), a
[2], a
[3],
812 compat_ptr(a
[4]), compat_ptr(a
[5]));
815 ret
= sys_shutdown(a0
, a1
);
818 ret
= compat_sys_setsockopt(a0
, a1
, a
[2],
819 compat_ptr(a
[3]), a
[4]);
822 ret
= compat_sys_getsockopt(a0
, a1
, a
[2],
823 compat_ptr(a
[3]), compat_ptr(a
[4]));
826 ret
= compat_sys_sendmsg(a0
, compat_ptr(a1
), a
[2]);
829 ret
= compat_sys_sendmmsg(a0
, compat_ptr(a1
), a
[2], a
[3]);
832 ret
= compat_sys_recvmsg(a0
, compat_ptr(a1
), a
[2]);
835 ret
= compat_sys_recvmmsg(a0
, compat_ptr(a1
), a
[2], a
[3],
839 ret
= sys_accept4(a0
, compat_ptr(a1
), compat_ptr(a
[2]), a
[3]);