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 static inline int iov_from_user_compat_to_kern(struct iovec
*kiov
,
35 struct compat_iovec __user
*uiov32
,
44 if (get_user(len
, &uiov32
->iov_len
) ||
45 get_user(buf
, &uiov32
->iov_base
))
48 if (len
> INT_MAX
- tot_len
)
49 len
= INT_MAX
- tot_len
;
52 kiov
->iov_base
= compat_ptr(buf
);
53 kiov
->iov_len
= (__kernel_size_t
) len
;
61 int get_compat_msghdr(struct msghdr
*kmsg
, struct compat_msghdr __user
*umsg
)
63 compat_uptr_t tmp1
, tmp2
, tmp3
;
65 if (!access_ok(VERIFY_READ
, umsg
, sizeof(*umsg
)) ||
66 __get_user(tmp1
, &umsg
->msg_name
) ||
67 __get_user(kmsg
->msg_namelen
, &umsg
->msg_namelen
) ||
68 __get_user(tmp2
, &umsg
->msg_iov
) ||
69 __get_user(kmsg
->msg_iovlen
, &umsg
->msg_iovlen
) ||
70 __get_user(tmp3
, &umsg
->msg_control
) ||
71 __get_user(kmsg
->msg_controllen
, &umsg
->msg_controllen
) ||
72 __get_user(kmsg
->msg_flags
, &umsg
->msg_flags
))
76 kmsg
->msg_namelen
= 0;
78 if (kmsg
->msg_namelen
< 0)
81 if (kmsg
->msg_namelen
> sizeof(struct sockaddr_storage
))
82 kmsg
->msg_namelen
= sizeof(struct sockaddr_storage
);
83 kmsg
->msg_name
= compat_ptr(tmp1
);
84 kmsg
->msg_iov
= compat_ptr(tmp2
);
85 kmsg
->msg_control
= compat_ptr(tmp3
);
89 /* I've named the args so it is easy to tell whose space the pointers are in. */
90 int verify_compat_iovec(struct msghdr
*kern_msg
, struct iovec
*kern_iov
,
91 struct sockaddr_storage
*kern_address
, int mode
)
95 if (kern_msg
->msg_name
&& kern_msg
->msg_namelen
) {
96 if (mode
== VERIFY_READ
) {
97 int err
= move_addr_to_kernel(kern_msg
->msg_name
,
98 kern_msg
->msg_namelen
,
103 kern_msg
->msg_name
= kern_address
;
105 kern_msg
->msg_name
= NULL
;
106 kern_msg
->msg_namelen
= 0;
109 tot_len
= iov_from_user_compat_to_kern(kern_iov
,
110 (struct compat_iovec __user
*)kern_msg
->msg_iov
,
111 kern_msg
->msg_iovlen
);
113 kern_msg
->msg_iov
= kern_iov
;
119 #define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32))
121 #define CMSG_COMPAT_DATA(cmsg) \
122 ((void __user *)((char __user *)(cmsg) + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))))
123 #define CMSG_COMPAT_SPACE(len) \
124 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + CMSG_COMPAT_ALIGN(len))
125 #define CMSG_COMPAT_LEN(len) \
126 (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + (len))
128 #define CMSG_COMPAT_FIRSTHDR(msg) \
129 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
130 (struct compat_cmsghdr __user *)((msg)->msg_control) : \
131 (struct compat_cmsghdr __user *)NULL)
133 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
134 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
135 (ucmlen) <= (unsigned long) \
136 ((mhdr)->msg_controllen - \
137 ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
139 static inline struct compat_cmsghdr __user
*cmsg_compat_nxthdr(struct msghdr
*msg
,
140 struct compat_cmsghdr __user
*cmsg
, int cmsg_len
)
142 char __user
*ptr
= (char __user
*)cmsg
+ CMSG_COMPAT_ALIGN(cmsg_len
);
143 if ((unsigned long)(ptr
+ 1 - (char __user
*)msg
->msg_control
) >
146 return (struct compat_cmsghdr __user
*)ptr
;
149 /* There is a lot of hair here because the alignment rules (and
150 * thus placement) of cmsg headers and length are different for
151 * 32-bit apps. -DaveM
153 int cmsghdr_from_user_compat_to_kern(struct msghdr
*kmsg
, struct sock
*sk
,
154 unsigned char *stackbuf
, int stackbuf_size
)
156 struct compat_cmsghdr __user
*ucmsg
;
157 struct cmsghdr
*kcmsg
, *kcmsg_base
;
158 compat_size_t ucmlen
;
159 __kernel_size_t kcmlen
, tmp
;
163 kcmsg_base
= kcmsg
= (struct cmsghdr
*)stackbuf
;
164 ucmsg
= CMSG_COMPAT_FIRSTHDR(kmsg
);
165 while (ucmsg
!= NULL
) {
166 if (get_user(ucmlen
, &ucmsg
->cmsg_len
))
170 if (!CMSG_COMPAT_OK(ucmlen
, ucmsg
, kmsg
))
173 tmp
= ((ucmlen
- CMSG_COMPAT_ALIGN(sizeof(*ucmsg
))) +
174 CMSG_ALIGN(sizeof(struct cmsghdr
)));
175 tmp
= CMSG_ALIGN(tmp
);
177 ucmsg
= cmsg_compat_nxthdr(kmsg
, ucmsg
, ucmlen
);
182 /* The kcmlen holds the 64-bit version of the control length.
183 * It may not be modified as we do not stick it into the kmsg
184 * until we have successfully copied over all of the data
187 if (kcmlen
> stackbuf_size
)
188 kcmsg_base
= kcmsg
= sock_kmalloc(sk
, kcmlen
, GFP_KERNEL
);
192 /* Now copy them over neatly. */
193 memset(kcmsg
, 0, kcmlen
);
194 ucmsg
= CMSG_COMPAT_FIRSTHDR(kmsg
);
195 while (ucmsg
!= NULL
) {
196 if (__get_user(ucmlen
, &ucmsg
->cmsg_len
))
198 if (!CMSG_COMPAT_OK(ucmlen
, ucmsg
, kmsg
))
200 tmp
= ((ucmlen
- CMSG_COMPAT_ALIGN(sizeof(*ucmsg
))) +
201 CMSG_ALIGN(sizeof(struct cmsghdr
)));
202 if ((char *)kcmsg_base
+ kcmlen
- (char *)kcmsg
< CMSG_ALIGN(tmp
))
204 kcmsg
->cmsg_len
= tmp
;
205 tmp
= CMSG_ALIGN(tmp
);
206 if (__get_user(kcmsg
->cmsg_level
, &ucmsg
->cmsg_level
) ||
207 __get_user(kcmsg
->cmsg_type
, &ucmsg
->cmsg_type
) ||
208 copy_from_user(CMSG_DATA(kcmsg
),
209 CMSG_COMPAT_DATA(ucmsg
),
210 (ucmlen
- CMSG_COMPAT_ALIGN(sizeof(*ucmsg
)))))
214 kcmsg
= (struct cmsghdr
*)((char *)kcmsg
+ tmp
);
215 ucmsg
= cmsg_compat_nxthdr(kmsg
, ucmsg
, ucmlen
);
218 /* Ok, looks like we made it. Hook it up and return success. */
219 kmsg
->msg_control
= kcmsg_base
;
220 kmsg
->msg_controllen
= kcmlen
;
226 if (kcmsg_base
!= (struct cmsghdr
*)stackbuf
)
227 sock_kfree_s(sk
, kcmsg_base
, kcmlen
);
231 int put_cmsg_compat(struct msghdr
*kmsg
, int level
, int type
, int len
, void *data
)
233 struct compat_cmsghdr __user
*cm
= (struct compat_cmsghdr __user
*) kmsg
->msg_control
;
234 struct compat_cmsghdr cmhdr
;
235 struct compat_timeval ctv
;
236 struct compat_timespec cts
[3];
239 if (cm
== NULL
|| kmsg
->msg_controllen
< sizeof(*cm
)) {
240 kmsg
->msg_flags
|= MSG_CTRUNC
;
241 return 0; /* XXX: return error? check spec. */
244 if (!COMPAT_USE_64BIT_TIME
) {
245 if (level
== SOL_SOCKET
&& type
== SCM_TIMESTAMP
) {
246 struct timeval
*tv
= (struct timeval
*)data
;
247 ctv
.tv_sec
= tv
->tv_sec
;
248 ctv
.tv_usec
= tv
->tv_usec
;
252 if (level
== SOL_SOCKET
&&
253 (type
== SCM_TIMESTAMPNS
|| type
== SCM_TIMESTAMPING
)) {
254 int count
= type
== SCM_TIMESTAMPNS
? 1 : 3;
256 struct timespec
*ts
= (struct timespec
*)data
;
257 for (i
= 0; i
< count
; i
++) {
258 cts
[i
].tv_sec
= ts
[i
].tv_sec
;
259 cts
[i
].tv_nsec
= ts
[i
].tv_nsec
;
262 len
= sizeof(cts
[0]) * count
;
266 cmlen
= CMSG_COMPAT_LEN(len
);
267 if (kmsg
->msg_controllen
< cmlen
) {
268 kmsg
->msg_flags
|= MSG_CTRUNC
;
269 cmlen
= kmsg
->msg_controllen
;
271 cmhdr
.cmsg_level
= level
;
272 cmhdr
.cmsg_type
= type
;
273 cmhdr
.cmsg_len
= cmlen
;
275 if (copy_to_user(cm
, &cmhdr
, sizeof cmhdr
))
277 if (copy_to_user(CMSG_COMPAT_DATA(cm
), data
, cmlen
- sizeof(struct compat_cmsghdr
)))
279 cmlen
= CMSG_COMPAT_SPACE(len
);
280 if (kmsg
->msg_controllen
< cmlen
)
281 cmlen
= kmsg
->msg_controllen
;
282 kmsg
->msg_control
+= cmlen
;
283 kmsg
->msg_controllen
-= cmlen
;
287 void scm_detach_fds_compat(struct msghdr
*kmsg
, struct scm_cookie
*scm
)
289 struct compat_cmsghdr __user
*cm
= (struct compat_cmsghdr __user
*) kmsg
->msg_control
;
290 int fdmax
= (kmsg
->msg_controllen
- sizeof(struct compat_cmsghdr
)) / sizeof(int);
291 int fdnum
= scm
->fp
->count
;
292 struct file
**fp
= scm
->fp
->fp
;
299 for (i
= 0, cmfptr
= (int __user
*) CMSG_COMPAT_DATA(cm
); i
< fdmax
; i
++, cmfptr
++) {
301 err
= security_file_receive(fp
[i
]);
304 err
= get_unused_fd_flags(MSG_CMSG_CLOEXEC
& kmsg
->msg_flags
309 err
= put_user(new_fd
, cmfptr
);
311 put_unused_fd(new_fd
);
314 /* Bump the usage count and install the file. */
315 fd_install(new_fd
, get_file(fp
[i
]));
319 int cmlen
= CMSG_COMPAT_LEN(i
* sizeof(int));
320 err
= put_user(SOL_SOCKET
, &cm
->cmsg_level
);
322 err
= put_user(SCM_RIGHTS
, &cm
->cmsg_type
);
324 err
= put_user(cmlen
, &cm
->cmsg_len
);
326 cmlen
= CMSG_COMPAT_SPACE(i
* sizeof(int));
327 kmsg
->msg_control
+= cmlen
;
328 kmsg
->msg_controllen
-= cmlen
;
332 kmsg
->msg_flags
|= MSG_CTRUNC
;
335 * All of the files that fit in the message have had their
336 * usage counts incremented, so we just free the list.
341 static int do_set_attach_filter(struct socket
*sock
, int level
, int optname
,
342 char __user
*optval
, unsigned int optlen
)
344 struct compat_sock_fprog __user
*fprog32
= (struct compat_sock_fprog __user
*)optval
;
345 struct sock_fprog __user
*kfprog
= compat_alloc_user_space(sizeof(struct sock_fprog
));
349 if (!access_ok(VERIFY_READ
, fprog32
, sizeof(*fprog32
)) ||
350 !access_ok(VERIFY_WRITE
, kfprog
, sizeof(struct sock_fprog
)) ||
351 __get_user(len
, &fprog32
->len
) ||
352 __get_user(ptr
, &fprog32
->filter
) ||
353 __put_user(len
, &kfprog
->len
) ||
354 __put_user(compat_ptr(ptr
), &kfprog
->filter
))
357 return sock_setsockopt(sock
, level
, optname
, (char __user
*)kfprog
,
358 sizeof(struct sock_fprog
));
361 static int do_set_sock_timeout(struct socket
*sock
, int level
,
362 int optname
, char __user
*optval
, unsigned int optlen
)
364 struct compat_timeval __user
*up
= (struct compat_timeval __user
*)optval
;
365 struct timeval ktime
;
369 if (optlen
< sizeof(*up
))
371 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)) ||
372 __get_user(ktime
.tv_sec
, &up
->tv_sec
) ||
373 __get_user(ktime
.tv_usec
, &up
->tv_usec
))
377 err
= sock_setsockopt(sock
, level
, optname
, (char *)&ktime
, sizeof(ktime
));
383 static int compat_sock_setsockopt(struct socket
*sock
, int level
, int optname
,
384 char __user
*optval
, unsigned int optlen
)
386 if (optname
== SO_ATTACH_FILTER
)
387 return do_set_attach_filter(sock
, level
, optname
,
389 if (optname
== SO_RCVTIMEO
|| optname
== SO_SNDTIMEO
)
390 return do_set_sock_timeout(sock
, level
, optname
, optval
, optlen
);
392 return sock_setsockopt(sock
, level
, optname
, optval
, optlen
);
395 COMPAT_SYSCALL_DEFINE5(setsockopt
, int, fd
, int, level
, int, optname
,
396 char __user
*, optval
, unsigned int, optlen
)
399 struct socket
*sock
= sockfd_lookup(fd
, &err
);
402 err
= security_socket_setsockopt(sock
, level
, optname
);
408 if (level
== SOL_SOCKET
)
409 err
= compat_sock_setsockopt(sock
, level
,
410 optname
, optval
, optlen
);
411 else if (sock
->ops
->compat_setsockopt
)
412 err
= sock
->ops
->compat_setsockopt(sock
, level
,
413 optname
, optval
, optlen
);
415 err
= sock
->ops
->setsockopt(sock
, level
,
416 optname
, optval
, optlen
);
422 static int do_get_sock_timeout(struct socket
*sock
, int level
, int optname
,
423 char __user
*optval
, int __user
*optlen
)
425 struct compat_timeval __user
*up
;
426 struct timeval ktime
;
430 up
= (struct compat_timeval __user
*) optval
;
431 if (get_user(len
, optlen
))
433 if (len
< sizeof(*up
))
438 err
= sock_getsockopt(sock
, level
, optname
, (char *) &ktime
, &len
);
442 if (put_user(sizeof(*up
), optlen
) ||
443 !access_ok(VERIFY_WRITE
, up
, sizeof(*up
)) ||
444 __put_user(ktime
.tv_sec
, &up
->tv_sec
) ||
445 __put_user(ktime
.tv_usec
, &up
->tv_usec
))
451 static int compat_sock_getsockopt(struct socket
*sock
, int level
, int optname
,
452 char __user
*optval
, int __user
*optlen
)
454 if (optname
== SO_RCVTIMEO
|| optname
== SO_SNDTIMEO
)
455 return do_get_sock_timeout(sock
, level
, optname
, optval
, optlen
);
456 return sock_getsockopt(sock
, level
, optname
, optval
, optlen
);
459 int compat_sock_get_timestamp(struct sock
*sk
, struct timeval __user
*userstamp
)
461 struct compat_timeval __user
*ctv
;
465 if (COMPAT_USE_64BIT_TIME
)
466 return sock_get_timestamp(sk
, userstamp
);
468 ctv
= (struct compat_timeval __user
*) userstamp
;
470 if (!sock_flag(sk
, SOCK_TIMESTAMP
))
471 sock_enable_timestamp(sk
, SOCK_TIMESTAMP
);
472 tv
= ktime_to_timeval(sk
->sk_stamp
);
475 if (tv
.tv_sec
== 0) {
476 sk
->sk_stamp
= ktime_get_real();
477 tv
= ktime_to_timeval(sk
->sk_stamp
);
480 if (put_user(tv
.tv_sec
, &ctv
->tv_sec
) ||
481 put_user(tv
.tv_usec
, &ctv
->tv_usec
))
485 EXPORT_SYMBOL(compat_sock_get_timestamp
);
487 int compat_sock_get_timestampns(struct sock
*sk
, struct timespec __user
*userstamp
)
489 struct compat_timespec __user
*ctv
;
493 if (COMPAT_USE_64BIT_TIME
)
494 return sock_get_timestampns (sk
, userstamp
);
496 ctv
= (struct compat_timespec __user
*) userstamp
;
498 if (!sock_flag(sk
, SOCK_TIMESTAMP
))
499 sock_enable_timestamp(sk
, SOCK_TIMESTAMP
);
500 ts
= ktime_to_timespec(sk
->sk_stamp
);
503 if (ts
.tv_sec
== 0) {
504 sk
->sk_stamp
= ktime_get_real();
505 ts
= ktime_to_timespec(sk
->sk_stamp
);
508 if (put_user(ts
.tv_sec
, &ctv
->tv_sec
) ||
509 put_user(ts
.tv_nsec
, &ctv
->tv_nsec
))
513 EXPORT_SYMBOL(compat_sock_get_timestampns
);
515 COMPAT_SYSCALL_DEFINE5(getsockopt
, int, fd
, int, level
, int, optname
,
516 char __user
*, optval
, int __user
*, optlen
)
519 struct socket
*sock
= sockfd_lookup(fd
, &err
);
522 err
= security_socket_getsockopt(sock
, level
, optname
);
528 if (level
== SOL_SOCKET
)
529 err
= compat_sock_getsockopt(sock
, level
,
530 optname
, optval
, optlen
);
531 else if (sock
->ops
->compat_getsockopt
)
532 err
= sock
->ops
->compat_getsockopt(sock
, level
,
533 optname
, optval
, optlen
);
535 err
= sock
->ops
->getsockopt(sock
, level
,
536 optname
, optval
, optlen
);
542 struct compat_group_req
{
544 struct __kernel_sockaddr_storage gr_group
545 __attribute__ ((aligned(4)));
548 struct compat_group_source_req
{
550 struct __kernel_sockaddr_storage gsr_group
551 __attribute__ ((aligned(4)));
552 struct __kernel_sockaddr_storage gsr_source
553 __attribute__ ((aligned(4)));
556 struct compat_group_filter
{
558 struct __kernel_sockaddr_storage gf_group
559 __attribute__ ((aligned(4)));
562 struct __kernel_sockaddr_storage gf_slist
[1]
563 __attribute__ ((aligned(4)));
566 #define __COMPAT_GF0_SIZE (sizeof(struct compat_group_filter) - \
567 sizeof(struct __kernel_sockaddr_storage))
570 int compat_mc_setsockopt(struct sock
*sock
, int level
, int optname
,
571 char __user
*optval
, unsigned int optlen
,
572 int (*setsockopt
)(struct sock
*, int, int, char __user
*, unsigned int))
574 char __user
*koptval
= optval
;
575 int koptlen
= optlen
;
578 case MCAST_JOIN_GROUP
:
579 case MCAST_LEAVE_GROUP
:
581 struct compat_group_req __user
*gr32
= (void *)optval
;
582 struct group_req __user
*kgr
=
583 compat_alloc_user_space(sizeof(struct group_req
));
586 if (!access_ok(VERIFY_READ
, gr32
, sizeof(*gr32
)) ||
587 !access_ok(VERIFY_WRITE
, kgr
, sizeof(struct group_req
)) ||
588 __get_user(interface
, &gr32
->gr_interface
) ||
589 __put_user(interface
, &kgr
->gr_interface
) ||
590 copy_in_user(&kgr
->gr_group
, &gr32
->gr_group
,
591 sizeof(kgr
->gr_group
)))
593 koptval
= (char __user
*)kgr
;
594 koptlen
= sizeof(struct group_req
);
597 case MCAST_JOIN_SOURCE_GROUP
:
598 case MCAST_LEAVE_SOURCE_GROUP
:
599 case MCAST_BLOCK_SOURCE
:
600 case MCAST_UNBLOCK_SOURCE
:
602 struct compat_group_source_req __user
*gsr32
= (void *)optval
;
603 struct group_source_req __user
*kgsr
= compat_alloc_user_space(
604 sizeof(struct group_source_req
));
607 if (!access_ok(VERIFY_READ
, gsr32
, sizeof(*gsr32
)) ||
608 !access_ok(VERIFY_WRITE
, kgsr
,
609 sizeof(struct group_source_req
)) ||
610 __get_user(interface
, &gsr32
->gsr_interface
) ||
611 __put_user(interface
, &kgsr
->gsr_interface
) ||
612 copy_in_user(&kgsr
->gsr_group
, &gsr32
->gsr_group
,
613 sizeof(kgsr
->gsr_group
)) ||
614 copy_in_user(&kgsr
->gsr_source
, &gsr32
->gsr_source
,
615 sizeof(kgsr
->gsr_source
)))
617 koptval
= (char __user
*)kgsr
;
618 koptlen
= sizeof(struct group_source_req
);
623 struct compat_group_filter __user
*gf32
= (void *)optval
;
624 struct group_filter __user
*kgf
;
625 u32 interface
, fmode
, numsrc
;
627 if (!access_ok(VERIFY_READ
, gf32
, __COMPAT_GF0_SIZE
) ||
628 __get_user(interface
, &gf32
->gf_interface
) ||
629 __get_user(fmode
, &gf32
->gf_fmode
) ||
630 __get_user(numsrc
, &gf32
->gf_numsrc
))
632 koptlen
= optlen
+ sizeof(struct group_filter
) -
633 sizeof(struct compat_group_filter
);
634 if (koptlen
< GROUP_FILTER_SIZE(numsrc
))
636 kgf
= compat_alloc_user_space(koptlen
);
637 if (!access_ok(VERIFY_WRITE
, kgf
, koptlen
) ||
638 __put_user(interface
, &kgf
->gf_interface
) ||
639 __put_user(fmode
, &kgf
->gf_fmode
) ||
640 __put_user(numsrc
, &kgf
->gf_numsrc
) ||
641 copy_in_user(&kgf
->gf_group
, &gf32
->gf_group
,
642 sizeof(kgf
->gf_group
)) ||
643 (numsrc
&& copy_in_user(kgf
->gf_slist
, gf32
->gf_slist
,
644 numsrc
* sizeof(kgf
->gf_slist
[0]))))
646 koptval
= (char __user
*)kgf
;
653 return setsockopt(sock
, level
, optname
, koptval
, koptlen
);
655 EXPORT_SYMBOL(compat_mc_setsockopt
);
657 int compat_mc_getsockopt(struct sock
*sock
, int level
, int optname
,
658 char __user
*optval
, int __user
*optlen
,
659 int (*getsockopt
)(struct sock
*, int, int, char __user
*, int __user
*))
661 struct compat_group_filter __user
*gf32
= (void *)optval
;
662 struct group_filter __user
*kgf
;
664 u32 interface
, fmode
, numsrc
;
667 if (optname
!= MCAST_MSFILTER
)
668 return getsockopt(sock
, level
, optname
, optval
, optlen
);
670 koptlen
= compat_alloc_user_space(sizeof(*koptlen
));
671 if (!access_ok(VERIFY_READ
, optlen
, sizeof(*optlen
)) ||
672 __get_user(ulen
, optlen
))
675 /* adjust len for pad */
676 klen
= ulen
+ sizeof(*kgf
) - sizeof(*gf32
);
678 if (klen
< GROUP_FILTER_SIZE(0))
681 if (!access_ok(VERIFY_WRITE
, koptlen
, sizeof(*koptlen
)) ||
682 __put_user(klen
, koptlen
))
685 /* have to allow space for previous compat_alloc_user_space, too */
686 kgf
= compat_alloc_user_space(klen
+sizeof(*optlen
));
688 if (!access_ok(VERIFY_READ
, gf32
, __COMPAT_GF0_SIZE
) ||
689 __get_user(interface
, &gf32
->gf_interface
) ||
690 __get_user(fmode
, &gf32
->gf_fmode
) ||
691 __get_user(numsrc
, &gf32
->gf_numsrc
) ||
692 __put_user(interface
, &kgf
->gf_interface
) ||
693 __put_user(fmode
, &kgf
->gf_fmode
) ||
694 __put_user(numsrc
, &kgf
->gf_numsrc
) ||
695 copy_in_user(&kgf
->gf_group
, &gf32
->gf_group
, sizeof(kgf
->gf_group
)))
698 err
= getsockopt(sock
, level
, optname
, (char __user
*)kgf
, koptlen
);
702 if (!access_ok(VERIFY_READ
, koptlen
, sizeof(*koptlen
)) ||
703 __get_user(klen
, koptlen
))
706 ulen
= klen
- (sizeof(*kgf
)-sizeof(*gf32
));
708 if (!access_ok(VERIFY_WRITE
, optlen
, sizeof(*optlen
)) ||
709 __put_user(ulen
, optlen
))
712 if (!access_ok(VERIFY_READ
, kgf
, klen
) ||
713 !access_ok(VERIFY_WRITE
, gf32
, ulen
) ||
714 __get_user(interface
, &kgf
->gf_interface
) ||
715 __get_user(fmode
, &kgf
->gf_fmode
) ||
716 __get_user(numsrc
, &kgf
->gf_numsrc
) ||
717 __put_user(interface
, &gf32
->gf_interface
) ||
718 __put_user(fmode
, &gf32
->gf_fmode
) ||
719 __put_user(numsrc
, &gf32
->gf_numsrc
))
724 klen
-= GROUP_FILTER_SIZE(0);
725 copylen
= numsrc
* sizeof(gf32
->gf_slist
[0]);
728 if (copy_in_user(gf32
->gf_slist
, kgf
->gf_slist
, copylen
))
733 EXPORT_SYMBOL(compat_mc_getsockopt
);
736 /* Argument list sizes for compat_sys_socketcall */
737 #define AL(x) ((x) * sizeof(u32))
738 static unsigned char nas
[21] = {
739 AL(0), AL(3), AL(3), AL(3), AL(2), AL(3),
740 AL(3), AL(3), AL(4), AL(4), AL(4), AL(6),
741 AL(6), AL(2), AL(5), AL(5), AL(3), AL(3),
746 COMPAT_SYSCALL_DEFINE3(sendmsg
, int, fd
, struct compat_msghdr __user
*, msg
, unsigned int, flags
)
748 return __sys_sendmsg(fd
, (struct msghdr __user
*)msg
, flags
| MSG_CMSG_COMPAT
);
751 COMPAT_SYSCALL_DEFINE4(sendmmsg
, int, fd
, struct compat_mmsghdr __user
*, mmsg
,
752 unsigned int, vlen
, unsigned int, flags
)
754 return __sys_sendmmsg(fd
, (struct mmsghdr __user
*)mmsg
, vlen
,
755 flags
| MSG_CMSG_COMPAT
);
758 COMPAT_SYSCALL_DEFINE3(recvmsg
, int, fd
, struct compat_msghdr __user
*, msg
, unsigned int, flags
)
760 return __sys_recvmsg(fd
, (struct msghdr __user
*)msg
, flags
| MSG_CMSG_COMPAT
);
763 COMPAT_SYSCALL_DEFINE4(recv
, int, fd
, void __user
*, buf
, compat_size_t
, len
, unsigned int, flags
)
765 return sys_recv(fd
, buf
, len
, flags
| MSG_CMSG_COMPAT
);
768 COMPAT_SYSCALL_DEFINE6(recvfrom
, int, fd
, void __user
*, buf
, compat_size_t
, len
,
769 unsigned int, flags
, struct sockaddr __user
*, addr
,
770 int __user
*, addrlen
)
772 return sys_recvfrom(fd
, buf
, len
, flags
| MSG_CMSG_COMPAT
, addr
, addrlen
);
775 COMPAT_SYSCALL_DEFINE5(recvmmsg
, int, fd
, struct compat_mmsghdr __user
*, mmsg
,
776 unsigned int, vlen
, unsigned int, flags
,
777 struct compat_timespec __user
*, timeout
)
780 struct timespec ktspec
;
783 return __sys_recvmmsg(fd
, (struct mmsghdr __user
*)mmsg
, vlen
,
784 flags
| MSG_CMSG_COMPAT
, NULL
);
786 if (compat_get_timespec(&ktspec
, timeout
))
789 datagrams
= __sys_recvmmsg(fd
, (struct mmsghdr __user
*)mmsg
, vlen
,
790 flags
| MSG_CMSG_COMPAT
, &ktspec
);
791 if (datagrams
> 0 && compat_put_timespec(&ktspec
, timeout
))
797 COMPAT_SYSCALL_DEFINE2(socketcall
, int, call
, u32 __user
*, args
)
803 if (call
< SYS_SOCKET
|| call
> SYS_SENDMMSG
)
805 if (copy_from_user(a
, args
, nas
[call
]))
812 ret
= sys_socket(a0
, a1
, a
[2]);
815 ret
= sys_bind(a0
, compat_ptr(a1
), a
[2]);
818 ret
= sys_connect(a0
, compat_ptr(a1
), a
[2]);
821 ret
= sys_listen(a0
, a1
);
824 ret
= sys_accept4(a0
, compat_ptr(a1
), compat_ptr(a
[2]), 0);
826 case SYS_GETSOCKNAME
:
827 ret
= sys_getsockname(a0
, compat_ptr(a1
), compat_ptr(a
[2]));
829 case SYS_GETPEERNAME
:
830 ret
= sys_getpeername(a0
, compat_ptr(a1
), compat_ptr(a
[2]));
833 ret
= sys_socketpair(a0
, a1
, a
[2], compat_ptr(a
[3]));
836 ret
= sys_send(a0
, compat_ptr(a1
), a
[2], a
[3]);
839 ret
= sys_sendto(a0
, compat_ptr(a1
), a
[2], a
[3], compat_ptr(a
[4]), a
[5]);
842 ret
= compat_sys_recv(a0
, compat_ptr(a1
), a
[2], a
[3]);
845 ret
= compat_sys_recvfrom(a0
, compat_ptr(a1
), a
[2], a
[3],
846 compat_ptr(a
[4]), compat_ptr(a
[5]));
849 ret
= sys_shutdown(a0
, a1
);
852 ret
= compat_sys_setsockopt(a0
, a1
, a
[2],
853 compat_ptr(a
[3]), a
[4]);
856 ret
= compat_sys_getsockopt(a0
, a1
, a
[2],
857 compat_ptr(a
[3]), compat_ptr(a
[4]));
860 ret
= compat_sys_sendmsg(a0
, compat_ptr(a1
), a
[2]);
863 ret
= compat_sys_sendmmsg(a0
, compat_ptr(a1
), a
[2], a
[3]);
866 ret
= compat_sys_recvmsg(a0
, compat_ptr(a1
), a
[2]);
869 ret
= compat_sys_recvmmsg(a0
, compat_ptr(a1
), a
[2], a
[3],
873 ret
= sys_accept4(a0
, compat_ptr(a1
), compat_ptr(a
[2]), a
[3]);