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>
16 #include <linux/types.h>
17 #include <linux/file.h>
18 #include <linux/icmpv6.h>
19 #include <linux/socket.h>
20 #include <linux/syscalls.h>
21 #include <linux/filter.h>
22 #include <linux/compat.h>
23 #include <linux/security.h>
29 #include <asm/uaccess.h>
30 #include <net/compat.h>
32 static inline int iov_from_user_compat_to_kern(struct iovec
*kiov
,
33 struct compat_iovec __user
*uiov32
,
42 if (get_user(len
, &uiov32
->iov_len
) ||
43 get_user(buf
, &uiov32
->iov_base
))
46 if (len
> INT_MAX
- tot_len
)
47 len
= INT_MAX
- tot_len
;
50 kiov
->iov_base
= compat_ptr(buf
);
51 kiov
->iov_len
= (__kernel_size_t
) len
;
59 int get_compat_msghdr(struct msghdr
*kmsg
, struct compat_msghdr __user
*umsg
)
61 compat_uptr_t tmp1
, tmp2
, tmp3
;
63 if (!access_ok(VERIFY_READ
, umsg
, sizeof(*umsg
)) ||
64 __get_user(tmp1
, &umsg
->msg_name
) ||
65 __get_user(kmsg
->msg_namelen
, &umsg
->msg_namelen
) ||
66 __get_user(tmp2
, &umsg
->msg_iov
) ||
67 __get_user(kmsg
->msg_iovlen
, &umsg
->msg_iovlen
) ||
68 __get_user(tmp3
, &umsg
->msg_control
) ||
69 __get_user(kmsg
->msg_controllen
, &umsg
->msg_controllen
) ||
70 __get_user(kmsg
->msg_flags
, &umsg
->msg_flags
))
72 kmsg
->msg_name
= compat_ptr(tmp1
);
73 kmsg
->msg_iov
= compat_ptr(tmp2
);
74 kmsg
->msg_control
= compat_ptr(tmp3
);
78 /* I've named the args so it is easy to tell whose space the pointers are in. */
79 int verify_compat_iovec(struct msghdr
*kern_msg
, struct iovec
*kern_iov
,
80 struct sockaddr
*kern_address
, int mode
)
84 if (kern_msg
->msg_namelen
) {
85 if (mode
==VERIFY_READ
) {
86 int err
= move_addr_to_kernel(kern_msg
->msg_name
,
87 kern_msg
->msg_namelen
,
92 kern_msg
->msg_name
= kern_address
;
94 kern_msg
->msg_name
= NULL
;
96 tot_len
= iov_from_user_compat_to_kern(kern_iov
,
97 (struct compat_iovec __user
*)kern_msg
->msg_iov
,
98 kern_msg
->msg_iovlen
);
100 kern_msg
->msg_iov
= kern_iov
;
106 #define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32))
108 #define CMSG_COMPAT_DATA(cmsg) \
109 ((void __user *)((char __user *)(cmsg) + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))))
110 #define CMSG_COMPAT_SPACE(len) \
111 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + CMSG_COMPAT_ALIGN(len))
112 #define CMSG_COMPAT_LEN(len) \
113 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + (len))
115 #define CMSG_COMPAT_FIRSTHDR(msg) \
116 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
117 (struct compat_cmsghdr __user *)((msg)->msg_control) : \
118 (struct compat_cmsghdr __user *)NULL)
120 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
121 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
122 (ucmlen) <= (unsigned long) \
123 ((mhdr)->msg_controllen - \
124 ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
126 static inline struct compat_cmsghdr __user
*cmsg_compat_nxthdr(struct msghdr
*msg
,
127 struct compat_cmsghdr __user
*cmsg
, int cmsg_len
)
129 char __user
*ptr
= (char __user
*)cmsg
+ CMSG_COMPAT_ALIGN(cmsg_len
);
130 if ((unsigned long)(ptr
+ 1 - (char __user
*)msg
->msg_control
) >
133 return (struct compat_cmsghdr __user
*)ptr
;
136 /* There is a lot of hair here because the alignment rules (and
137 * thus placement) of cmsg headers and length are different for
138 * 32-bit apps. -DaveM
140 int cmsghdr_from_user_compat_to_kern(struct msghdr
*kmsg
, struct sock
*sk
,
141 unsigned char *stackbuf
, int stackbuf_size
)
143 struct compat_cmsghdr __user
*ucmsg
;
144 struct cmsghdr
*kcmsg
, *kcmsg_base
;
145 compat_size_t ucmlen
;
146 __kernel_size_t kcmlen
, tmp
;
150 kcmsg_base
= kcmsg
= (struct cmsghdr
*)stackbuf
;
151 ucmsg
= CMSG_COMPAT_FIRSTHDR(kmsg
);
152 while (ucmsg
!= NULL
) {
153 if (get_user(ucmlen
, &ucmsg
->cmsg_len
))
157 if (!CMSG_COMPAT_OK(ucmlen
, ucmsg
, kmsg
))
160 tmp
= ((ucmlen
- CMSG_COMPAT_ALIGN(sizeof(*ucmsg
))) +
161 CMSG_ALIGN(sizeof(struct cmsghdr
)));
162 tmp
= CMSG_ALIGN(tmp
);
164 ucmsg
= cmsg_compat_nxthdr(kmsg
, ucmsg
, ucmlen
);
169 /* The kcmlen holds the 64-bit version of the control length.
170 * It may not be modified as we do not stick it into the kmsg
171 * until we have successfully copied over all of the data
174 if (kcmlen
> stackbuf_size
)
175 kcmsg_base
= kcmsg
= sock_kmalloc(sk
, kcmlen
, GFP_KERNEL
);
179 /* Now copy them over neatly. */
180 memset(kcmsg
, 0, kcmlen
);
181 ucmsg
= CMSG_COMPAT_FIRSTHDR(kmsg
);
182 while (ucmsg
!= NULL
) {
183 if (__get_user(ucmlen
, &ucmsg
->cmsg_len
))
185 if (!CMSG_COMPAT_OK(ucmlen
, ucmsg
, kmsg
))
187 tmp
= ((ucmlen
- CMSG_COMPAT_ALIGN(sizeof(*ucmsg
))) +
188 CMSG_ALIGN(sizeof(struct cmsghdr
)));
189 if ((char *)kcmsg_base
+ kcmlen
- (char *)kcmsg
< CMSG_ALIGN(tmp
))
191 kcmsg
->cmsg_len
= tmp
;
192 tmp
= CMSG_ALIGN(tmp
);
193 if (__get_user(kcmsg
->cmsg_level
, &ucmsg
->cmsg_level
) ||
194 __get_user(kcmsg
->cmsg_type
, &ucmsg
->cmsg_type
) ||
195 copy_from_user(CMSG_DATA(kcmsg
),
196 CMSG_COMPAT_DATA(ucmsg
),
197 (ucmlen
- CMSG_COMPAT_ALIGN(sizeof(*ucmsg
)))))
201 kcmsg
= (struct cmsghdr
*)((char *)kcmsg
+ tmp
);
202 ucmsg
= cmsg_compat_nxthdr(kmsg
, ucmsg
, ucmlen
);
205 /* Ok, looks like we made it. Hook it up and return success. */
206 kmsg
->msg_control
= kcmsg_base
;
207 kmsg
->msg_controllen
= kcmlen
;
213 if (kcmsg_base
!= (struct cmsghdr
*)stackbuf
)
214 sock_kfree_s(sk
, kcmsg_base
, kcmlen
);
218 int put_cmsg_compat(struct msghdr
*kmsg
, int level
, int type
, int len
, void *data
)
220 struct compat_timeval ctv
;
221 struct compat_timespec cts
[3];
222 struct compat_cmsghdr __user
*cm
= (struct compat_cmsghdr __user
*) kmsg
->msg_control
;
223 struct compat_cmsghdr cmhdr
;
226 if (cm
== NULL
|| kmsg
->msg_controllen
< sizeof(*cm
)) {
227 kmsg
->msg_flags
|= MSG_CTRUNC
;
228 return 0; /* XXX: return error? check spec. */
231 if (level
== SOL_SOCKET
&& type
== SCM_TIMESTAMP
) {
232 struct timeval
*tv
= (struct timeval
*)data
;
233 ctv
.tv_sec
= tv
->tv_sec
;
234 ctv
.tv_usec
= tv
->tv_usec
;
238 if (level
== SOL_SOCKET
&&
239 (type
== SCM_TIMESTAMPNS
|| type
== SCM_TIMESTAMPING
)) {
240 int count
= type
== SCM_TIMESTAMPNS
? 1 : 3;
242 struct timespec
*ts
= (struct timespec
*)data
;
243 for (i
= 0; i
< count
; i
++) {
244 cts
[i
].tv_sec
= ts
[i
].tv_sec
;
245 cts
[i
].tv_nsec
= ts
[i
].tv_nsec
;
248 len
= sizeof(cts
[0]) * count
;
251 cmlen
= CMSG_COMPAT_LEN(len
);
252 if (kmsg
->msg_controllen
< cmlen
) {
253 kmsg
->msg_flags
|= MSG_CTRUNC
;
254 cmlen
= kmsg
->msg_controllen
;
256 cmhdr
.cmsg_level
= level
;
257 cmhdr
.cmsg_type
= type
;
258 cmhdr
.cmsg_len
= cmlen
;
260 if (copy_to_user(cm
, &cmhdr
, sizeof cmhdr
))
262 if (copy_to_user(CMSG_COMPAT_DATA(cm
), data
, cmlen
- sizeof(struct compat_cmsghdr
)))
264 cmlen
= CMSG_COMPAT_SPACE(len
);
265 if (kmsg
->msg_controllen
< cmlen
)
266 cmlen
= kmsg
->msg_controllen
;
267 kmsg
->msg_control
+= cmlen
;
268 kmsg
->msg_controllen
-= cmlen
;
272 void scm_detach_fds_compat(struct msghdr
*kmsg
, struct scm_cookie
*scm
)
274 struct compat_cmsghdr __user
*cm
= (struct compat_cmsghdr __user
*) kmsg
->msg_control
;
275 int fdmax
= (kmsg
->msg_controllen
- sizeof(struct compat_cmsghdr
)) / sizeof(int);
276 int fdnum
= scm
->fp
->count
;
277 struct file
**fp
= scm
->fp
->fp
;
284 for (i
= 0, cmfptr
= (int __user
*) CMSG_COMPAT_DATA(cm
); i
< fdmax
; i
++, cmfptr
++) {
286 err
= security_file_receive(fp
[i
]);
289 err
= get_unused_fd_flags(MSG_CMSG_CLOEXEC
& kmsg
->msg_flags
294 err
= put_user(new_fd
, cmfptr
);
296 put_unused_fd(new_fd
);
299 /* Bump the usage count and install the file. */
301 fd_install(new_fd
, fp
[i
]);
305 int cmlen
= CMSG_COMPAT_LEN(i
* sizeof(int));
306 err
= put_user(SOL_SOCKET
, &cm
->cmsg_level
);
308 err
= put_user(SCM_RIGHTS
, &cm
->cmsg_type
);
310 err
= put_user(cmlen
, &cm
->cmsg_len
);
312 cmlen
= CMSG_COMPAT_SPACE(i
* sizeof(int));
313 kmsg
->msg_control
+= cmlen
;
314 kmsg
->msg_controllen
-= cmlen
;
318 kmsg
->msg_flags
|= MSG_CTRUNC
;
321 * All of the files that fit in the message have had their
322 * usage counts incremented, so we just free the list.
328 * A struct sock_filter is architecture independent.
330 struct compat_sock_fprog
{
332 compat_uptr_t filter
; /* struct sock_filter * */
335 static int do_set_attach_filter(struct socket
*sock
, int level
, int optname
,
336 char __user
*optval
, unsigned int optlen
)
338 struct compat_sock_fprog __user
*fprog32
= (struct compat_sock_fprog __user
*)optval
;
339 struct sock_fprog __user
*kfprog
= compat_alloc_user_space(sizeof(struct sock_fprog
));
343 if (!access_ok(VERIFY_READ
, fprog32
, sizeof(*fprog32
)) ||
344 !access_ok(VERIFY_WRITE
, kfprog
, sizeof(struct sock_fprog
)) ||
345 __get_user(len
, &fprog32
->len
) ||
346 __get_user(ptr
, &fprog32
->filter
) ||
347 __put_user(len
, &kfprog
->len
) ||
348 __put_user(compat_ptr(ptr
), &kfprog
->filter
))
351 return sock_setsockopt(sock
, level
, optname
, (char __user
*)kfprog
,
352 sizeof(struct sock_fprog
));
355 static int do_set_sock_timeout(struct socket
*sock
, int level
,
356 int optname
, char __user
*optval
, unsigned int optlen
)
358 struct compat_timeval __user
*up
= (struct compat_timeval __user
*) optval
;
359 struct timeval ktime
;
363 if (optlen
< sizeof(*up
))
365 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)) ||
366 __get_user(ktime
.tv_sec
, &up
->tv_sec
) ||
367 __get_user(ktime
.tv_usec
, &up
->tv_usec
))
371 err
= sock_setsockopt(sock
, level
, optname
, (char *) &ktime
, sizeof(ktime
));
377 static int compat_sock_setsockopt(struct socket
*sock
, int level
, int optname
,
378 char __user
*optval
, unsigned int optlen
)
380 if (optname
== SO_ATTACH_FILTER
)
381 return do_set_attach_filter(sock
, level
, optname
,
383 if (optname
== SO_RCVTIMEO
|| optname
== SO_SNDTIMEO
)
384 return do_set_sock_timeout(sock
, level
, optname
, optval
, optlen
);
386 return sock_setsockopt(sock
, level
, optname
, optval
, optlen
);
389 asmlinkage
long compat_sys_setsockopt(int fd
, int level
, int optname
,
390 char __user
*optval
, unsigned int optlen
)
398 if ((sock
= sockfd_lookup(fd
, &err
))!=NULL
)
400 err
= security_socket_setsockopt(sock
,level
,optname
);
406 if (level
== SOL_SOCKET
)
407 err
= compat_sock_setsockopt(sock
, level
,
408 optname
, optval
, optlen
);
409 else if (sock
->ops
->compat_setsockopt
)
410 err
= sock
->ops
->compat_setsockopt(sock
, level
,
411 optname
, optval
, optlen
);
413 err
= sock
->ops
->setsockopt(sock
, level
,
414 optname
, optval
, optlen
);
420 static int do_get_sock_timeout(struct socket
*sock
, int level
, int optname
,
421 char __user
*optval
, int __user
*optlen
)
423 struct compat_timeval __user
*up
;
424 struct timeval ktime
;
428 up
= (struct compat_timeval __user
*) optval
;
429 if (get_user(len
, optlen
))
431 if (len
< sizeof(*up
))
436 err
= sock_getsockopt(sock
, level
, optname
, (char *) &ktime
, &len
);
440 if (put_user(sizeof(*up
), optlen
) ||
441 !access_ok(VERIFY_WRITE
, up
, sizeof(*up
)) ||
442 __put_user(ktime
.tv_sec
, &up
->tv_sec
) ||
443 __put_user(ktime
.tv_usec
, &up
->tv_usec
))
449 static int compat_sock_getsockopt(struct socket
*sock
, int level
, int optname
,
450 char __user
*optval
, int __user
*optlen
)
452 if (optname
== SO_RCVTIMEO
|| optname
== SO_SNDTIMEO
)
453 return do_get_sock_timeout(sock
, level
, optname
, optval
, optlen
);
454 return sock_getsockopt(sock
, level
, optname
, optval
, optlen
);
457 int compat_sock_get_timestamp(struct sock
*sk
, struct timeval __user
*userstamp
)
459 struct compat_timeval __user
*ctv
=
460 (struct compat_timeval __user
*) userstamp
;
464 if (!sock_flag(sk
, SOCK_TIMESTAMP
))
465 sock_enable_timestamp(sk
, SOCK_TIMESTAMP
);
466 tv
= ktime_to_timeval(sk
->sk_stamp
);
469 if (tv
.tv_sec
== 0) {
470 sk
->sk_stamp
= ktime_get_real();
471 tv
= ktime_to_timeval(sk
->sk_stamp
);
474 if (put_user(tv
.tv_sec
, &ctv
->tv_sec
) ||
475 put_user(tv
.tv_usec
, &ctv
->tv_usec
))
479 EXPORT_SYMBOL(compat_sock_get_timestamp
);
481 int compat_sock_get_timestampns(struct sock
*sk
, struct timespec __user
*userstamp
)
483 struct compat_timespec __user
*ctv
=
484 (struct compat_timespec __user
*) userstamp
;
488 if (!sock_flag(sk
, SOCK_TIMESTAMP
))
489 sock_enable_timestamp(sk
, SOCK_TIMESTAMP
);
490 ts
= ktime_to_timespec(sk
->sk_stamp
);
493 if (ts
.tv_sec
== 0) {
494 sk
->sk_stamp
= ktime_get_real();
495 ts
= ktime_to_timespec(sk
->sk_stamp
);
498 if (put_user(ts
.tv_sec
, &ctv
->tv_sec
) ||
499 put_user(ts
.tv_nsec
, &ctv
->tv_nsec
))
503 EXPORT_SYMBOL(compat_sock_get_timestampns
);
505 asmlinkage
long compat_sys_getsockopt(int fd
, int level
, int optname
,
506 char __user
*optval
, int __user
*optlen
)
511 if ((sock
= sockfd_lookup(fd
, &err
))!=NULL
)
513 err
= security_socket_getsockopt(sock
, level
,
520 if (level
== SOL_SOCKET
)
521 err
= compat_sock_getsockopt(sock
, level
,
522 optname
, optval
, optlen
);
523 else if (sock
->ops
->compat_getsockopt
)
524 err
= sock
->ops
->compat_getsockopt(sock
, level
,
525 optname
, optval
, optlen
);
527 err
= sock
->ops
->getsockopt(sock
, level
,
528 optname
, optval
, optlen
);
534 struct compat_group_req
{
536 struct __kernel_sockaddr_storage gr_group
537 __attribute__ ((aligned(4)));
538 } __attribute__ ((packed
));
540 struct compat_group_source_req
{
542 struct __kernel_sockaddr_storage gsr_group
543 __attribute__ ((aligned(4)));
544 struct __kernel_sockaddr_storage gsr_source
545 __attribute__ ((aligned(4)));
546 } __attribute__ ((packed
));
548 struct compat_group_filter
{
550 struct __kernel_sockaddr_storage gf_group
551 __attribute__ ((aligned(4)));
554 struct __kernel_sockaddr_storage gf_slist
[1]
555 __attribute__ ((aligned(4)));
556 } __attribute__ ((packed
));
558 #define __COMPAT_GF0_SIZE (sizeof(struct compat_group_filter) - \
559 sizeof(struct __kernel_sockaddr_storage))
562 int compat_mc_setsockopt(struct sock
*sock
, int level
, int optname
,
563 char __user
*optval
, unsigned int optlen
,
564 int (*setsockopt
)(struct sock
*,int,int,char __user
*,unsigned int))
566 char __user
*koptval
= optval
;
567 int koptlen
= optlen
;
570 case MCAST_JOIN_GROUP
:
571 case MCAST_LEAVE_GROUP
:
573 struct compat_group_req __user
*gr32
= (void *)optval
;
574 struct group_req __user
*kgr
=
575 compat_alloc_user_space(sizeof(struct group_req
));
578 if (!access_ok(VERIFY_READ
, gr32
, sizeof(*gr32
)) ||
579 !access_ok(VERIFY_WRITE
, kgr
, sizeof(struct group_req
)) ||
580 __get_user(interface
, &gr32
->gr_interface
) ||
581 __put_user(interface
, &kgr
->gr_interface
) ||
582 copy_in_user(&kgr
->gr_group
, &gr32
->gr_group
,
583 sizeof(kgr
->gr_group
)))
585 koptval
= (char __user
*)kgr
;
586 koptlen
= sizeof(struct group_req
);
589 case MCAST_JOIN_SOURCE_GROUP
:
590 case MCAST_LEAVE_SOURCE_GROUP
:
591 case MCAST_BLOCK_SOURCE
:
592 case MCAST_UNBLOCK_SOURCE
:
594 struct compat_group_source_req __user
*gsr32
= (void *)optval
;
595 struct group_source_req __user
*kgsr
= compat_alloc_user_space(
596 sizeof(struct group_source_req
));
599 if (!access_ok(VERIFY_READ
, gsr32
, sizeof(*gsr32
)) ||
600 !access_ok(VERIFY_WRITE
, kgsr
,
601 sizeof(struct group_source_req
)) ||
602 __get_user(interface
, &gsr32
->gsr_interface
) ||
603 __put_user(interface
, &kgsr
->gsr_interface
) ||
604 copy_in_user(&kgsr
->gsr_group
, &gsr32
->gsr_group
,
605 sizeof(kgsr
->gsr_group
)) ||
606 copy_in_user(&kgsr
->gsr_source
, &gsr32
->gsr_source
,
607 sizeof(kgsr
->gsr_source
)))
609 koptval
= (char __user
*)kgsr
;
610 koptlen
= sizeof(struct group_source_req
);
615 struct compat_group_filter __user
*gf32
= (void *)optval
;
616 struct group_filter __user
*kgf
;
617 u32 interface
, fmode
, numsrc
;
619 if (!access_ok(VERIFY_READ
, gf32
, __COMPAT_GF0_SIZE
) ||
620 __get_user(interface
, &gf32
->gf_interface
) ||
621 __get_user(fmode
, &gf32
->gf_fmode
) ||
622 __get_user(numsrc
, &gf32
->gf_numsrc
))
624 koptlen
= optlen
+ sizeof(struct group_filter
) -
625 sizeof(struct compat_group_filter
);
626 if (koptlen
< GROUP_FILTER_SIZE(numsrc
))
628 kgf
= compat_alloc_user_space(koptlen
);
629 if (!access_ok(VERIFY_WRITE
, kgf
, koptlen
) ||
630 __put_user(interface
, &kgf
->gf_interface
) ||
631 __put_user(fmode
, &kgf
->gf_fmode
) ||
632 __put_user(numsrc
, &kgf
->gf_numsrc
) ||
633 copy_in_user(&kgf
->gf_group
, &gf32
->gf_group
,
634 sizeof(kgf
->gf_group
)) ||
635 (numsrc
&& copy_in_user(kgf
->gf_slist
, gf32
->gf_slist
,
636 numsrc
* sizeof(kgf
->gf_slist
[0]))))
638 koptval
= (char __user
*)kgf
;
645 return setsockopt(sock
, level
, optname
, koptval
, koptlen
);
648 EXPORT_SYMBOL(compat_mc_setsockopt
);
650 int compat_mc_getsockopt(struct sock
*sock
, int level
, int optname
,
651 char __user
*optval
, int __user
*optlen
,
652 int (*getsockopt
)(struct sock
*,int,int,char __user
*,int __user
*))
654 struct compat_group_filter __user
*gf32
= (void *)optval
;
655 struct group_filter __user
*kgf
;
657 u32 interface
, fmode
, numsrc
;
660 if (optname
!= MCAST_MSFILTER
)
661 return getsockopt(sock
, level
, optname
, optval
, optlen
);
663 koptlen
= compat_alloc_user_space(sizeof(*koptlen
));
664 if (!access_ok(VERIFY_READ
, optlen
, sizeof(*optlen
)) ||
665 __get_user(ulen
, optlen
))
668 /* adjust len for pad */
669 klen
= ulen
+ sizeof(*kgf
) - sizeof(*gf32
);
671 if (klen
< GROUP_FILTER_SIZE(0))
674 if (!access_ok(VERIFY_WRITE
, koptlen
, sizeof(*koptlen
)) ||
675 __put_user(klen
, koptlen
))
678 /* have to allow space for previous compat_alloc_user_space, too */
679 kgf
= compat_alloc_user_space(klen
+sizeof(*optlen
));
681 if (!access_ok(VERIFY_READ
, gf32
, __COMPAT_GF0_SIZE
) ||
682 __get_user(interface
, &gf32
->gf_interface
) ||
683 __get_user(fmode
, &gf32
->gf_fmode
) ||
684 __get_user(numsrc
, &gf32
->gf_numsrc
) ||
685 __put_user(interface
, &kgf
->gf_interface
) ||
686 __put_user(fmode
, &kgf
->gf_fmode
) ||
687 __put_user(numsrc
, &kgf
->gf_numsrc
) ||
688 copy_in_user(&kgf
->gf_group
,&gf32
->gf_group
,sizeof(kgf
->gf_group
)))
691 err
= getsockopt(sock
, level
, optname
, (char __user
*)kgf
, koptlen
);
695 if (!access_ok(VERIFY_READ
, koptlen
, sizeof(*koptlen
)) ||
696 __get_user(klen
, koptlen
))
699 ulen
= klen
- (sizeof(*kgf
)-sizeof(*gf32
));
701 if (!access_ok(VERIFY_WRITE
, optlen
, sizeof(*optlen
)) ||
702 __put_user(ulen
, optlen
))
705 if (!access_ok(VERIFY_READ
, kgf
, klen
) ||
706 !access_ok(VERIFY_WRITE
, gf32
, ulen
) ||
707 __get_user(interface
, &kgf
->gf_interface
) ||
708 __get_user(fmode
, &kgf
->gf_fmode
) ||
709 __get_user(numsrc
, &kgf
->gf_numsrc
) ||
710 __put_user(interface
, &gf32
->gf_interface
) ||
711 __put_user(fmode
, &gf32
->gf_fmode
) ||
712 __put_user(numsrc
, &gf32
->gf_numsrc
))
717 klen
-= GROUP_FILTER_SIZE(0);
718 copylen
= numsrc
* sizeof(gf32
->gf_slist
[0]);
721 if (copy_in_user(gf32
->gf_slist
, kgf
->gf_slist
, copylen
))
727 EXPORT_SYMBOL(compat_mc_getsockopt
);
730 /* Argument list sizes for compat_sys_socketcall */
731 #define AL(x) ((x) * sizeof(u32))
732 static unsigned char nas
[19]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
733 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
734 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3),
738 asmlinkage
long compat_sys_sendmsg(int fd
, struct compat_msghdr __user
*msg
, unsigned flags
)
740 return sys_sendmsg(fd
, (struct msghdr __user
*)msg
, flags
| MSG_CMSG_COMPAT
);
743 asmlinkage
long compat_sys_recvmsg(int fd
, struct compat_msghdr __user
*msg
, unsigned int flags
)
745 return sys_recvmsg(fd
, (struct msghdr __user
*)msg
, flags
| MSG_CMSG_COMPAT
);
748 asmlinkage
long compat_sys_recv(int fd
, void __user
*buf
, size_t len
, unsigned flags
)
750 return sys_recv(fd
, buf
, len
, flags
| MSG_CMSG_COMPAT
);
753 asmlinkage
long compat_sys_recvfrom(int fd
, void __user
*buf
, size_t len
,
754 unsigned flags
, struct sockaddr __user
*addr
,
757 return sys_recvfrom(fd
, buf
, len
, flags
| MSG_CMSG_COMPAT
, addr
, addrlen
);
760 asmlinkage
long compat_sys_socketcall(int call
, u32 __user
*args
)
766 if (call
< SYS_SOCKET
|| call
> SYS_ACCEPT4
)
768 if (copy_from_user(a
, args
, nas
[call
]))
775 ret
= sys_socket(a0
, a1
, a
[2]);
778 ret
= sys_bind(a0
, compat_ptr(a1
), a
[2]);
781 ret
= sys_connect(a0
, compat_ptr(a1
), a
[2]);
784 ret
= sys_listen(a0
, a1
);
787 ret
= sys_accept4(a0
, compat_ptr(a1
), compat_ptr(a
[2]), 0);
789 case SYS_GETSOCKNAME
:
790 ret
= sys_getsockname(a0
, compat_ptr(a1
), compat_ptr(a
[2]));
792 case SYS_GETPEERNAME
:
793 ret
= sys_getpeername(a0
, compat_ptr(a1
), compat_ptr(a
[2]));
796 ret
= sys_socketpair(a0
, a1
, a
[2], compat_ptr(a
[3]));
799 ret
= sys_send(a0
, compat_ptr(a1
), a
[2], a
[3]);
802 ret
= sys_sendto(a0
, compat_ptr(a1
), a
[2], a
[3], compat_ptr(a
[4]), a
[5]);
805 ret
= compat_sys_recv(a0
, compat_ptr(a1
), a
[2], a
[3]);
808 ret
= compat_sys_recvfrom(a0
, compat_ptr(a1
), a
[2], a
[3],
809 compat_ptr(a
[4]), compat_ptr(a
[5]));
812 ret
= sys_shutdown(a0
,a1
);
815 ret
= compat_sys_setsockopt(a0
, a1
, a
[2],
816 compat_ptr(a
[3]), a
[4]);
819 ret
= compat_sys_getsockopt(a0
, a1
, a
[2],
820 compat_ptr(a
[3]), compat_ptr(a
[4]));
823 ret
= compat_sys_sendmsg(a0
, compat_ptr(a1
), a
[2]);
826 ret
= compat_sys_recvmsg(a0
, compat_ptr(a1
), a
[2]);
829 ret
= sys_accept4(a0
, compat_ptr(a1
), compat_ptr(a
[2]), a
[3]);