4 * Kernel compatibililty routines for e.g. 32 bit syscall support
7 * Copyright (C) 2002 Stephen Rothwell, IBM Corporation
8 * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
9 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
10 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
11 * Copyright (C) 2003 Pavel Machek (pavel@suse.cz)
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
18 #include <linux/linkage.h>
19 #include <linux/compat.h>
20 #include <linux/errno.h>
21 #include <linux/time.h>
23 #include <linux/fcntl.h>
24 #include <linux/namei.h>
25 #include <linux/file.h>
26 #include <linux/vfs.h>
27 #include <linux/ioctl32.h>
28 #include <linux/ioctl.h>
29 #include <linux/init.h>
30 #include <linux/sockios.h> /* for SIOCDEVPRIVATE */
31 #include <linux/smb.h>
32 #include <linux/smb_mount.h>
33 #include <linux/ncp_mount.h>
34 #include <linux/nfs4_mount.h>
35 #include <linux/smp_lock.h>
36 #include <linux/syscalls.h>
37 #include <linux/ctype.h>
38 #include <linux/module.h>
39 #include <linux/dirent.h>
40 #include <linux/fsnotify.h>
41 #include <linux/highuid.h>
42 #include <linux/sunrpc/svc.h>
43 #include <linux/nfsd/nfsd.h>
44 #include <linux/nfsd/syscall.h>
45 #include <linux/personality.h>
46 #include <linux/rwsem.h>
47 #include <linux/tsacct_kern.h>
48 #include <linux/highmem.h>
49 #include <linux/poll.h>
51 #include <linux/eventpoll.h>
53 #include <net/sock.h> /* siocdevprivate_ioctl */
55 #include <asm/uaccess.h>
56 #include <asm/mmu_context.h>
57 #include <asm/ioctls.h>
62 int compat_printk(const char *fmt
, ...)
69 ret
= vprintk(fmt
, ap
);
74 #include "read_write.h"
77 * Not all architectures have sys_utime, so implement this in terms
80 asmlinkage
long compat_sys_utime(char __user
*filename
, struct compat_utimbuf __user
*t
)
85 if (get_user(tv
[0].tv_sec
, &t
->actime
) ||
86 get_user(tv
[1].tv_sec
, &t
->modtime
))
91 return do_utimes(AT_FDCWD
, filename
, t
? tv
: NULL
);
94 asmlinkage
long compat_sys_futimesat(unsigned int dfd
, char __user
*filename
, struct compat_timeval __user
*t
)
99 if (get_user(tv
[0].tv_sec
, &t
[0].tv_sec
) ||
100 get_user(tv
[0].tv_usec
, &t
[0].tv_usec
) ||
101 get_user(tv
[1].tv_sec
, &t
[1].tv_sec
) ||
102 get_user(tv
[1].tv_usec
, &t
[1].tv_usec
))
105 return do_utimes(dfd
, filename
, t
? tv
: NULL
);
108 asmlinkage
long compat_sys_utimes(char __user
*filename
, struct compat_timeval __user
*t
)
110 return compat_sys_futimesat(AT_FDCWD
, filename
, t
);
113 asmlinkage
long compat_sys_newstat(char __user
* filename
,
114 struct compat_stat __user
*statbuf
)
117 int error
= vfs_stat_fd(AT_FDCWD
, filename
, &stat
);
120 error
= cp_compat_stat(&stat
, statbuf
);
124 asmlinkage
long compat_sys_newlstat(char __user
* filename
,
125 struct compat_stat __user
*statbuf
)
128 int error
= vfs_lstat_fd(AT_FDCWD
, filename
, &stat
);
131 error
= cp_compat_stat(&stat
, statbuf
);
135 #ifndef __ARCH_WANT_STAT64
136 asmlinkage
long compat_sys_newfstatat(unsigned int dfd
, char __user
*filename
,
137 struct compat_stat __user
*statbuf
, int flag
)
142 if ((flag
& ~AT_SYMLINK_NOFOLLOW
) != 0)
145 if (flag
& AT_SYMLINK_NOFOLLOW
)
146 error
= vfs_lstat_fd(dfd
, filename
, &stat
);
148 error
= vfs_stat_fd(dfd
, filename
, &stat
);
151 error
= cp_compat_stat(&stat
, statbuf
);
158 asmlinkage
long compat_sys_newfstat(unsigned int fd
,
159 struct compat_stat __user
* statbuf
)
162 int error
= vfs_fstat(fd
, &stat
);
165 error
= cp_compat_stat(&stat
, statbuf
);
169 static int put_compat_statfs(struct compat_statfs __user
*ubuf
, struct kstatfs
*kbuf
)
172 if (sizeof ubuf
->f_blocks
== 4) {
173 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
174 0xffffffff00000000ULL
)
176 /* f_files and f_ffree may be -1; it's okay
177 * to stuff that into 32 bits */
178 if (kbuf
->f_files
!= 0xffffffffffffffffULL
179 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
181 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
182 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
185 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
186 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
187 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
188 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
189 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
190 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
191 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
192 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
193 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
194 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
195 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
196 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
) ||
197 __put_user(0, &ubuf
->f_spare
[0]) ||
198 __put_user(0, &ubuf
->f_spare
[1]) ||
199 __put_user(0, &ubuf
->f_spare
[2]) ||
200 __put_user(0, &ubuf
->f_spare
[3]) ||
201 __put_user(0, &ubuf
->f_spare
[4]))
207 * The following statfs calls are copies of code from fs/open.c and
208 * should be checked against those from time to time
210 asmlinkage
long compat_sys_statfs(const char __user
*path
, struct compat_statfs __user
*buf
)
215 error
= user_path_walk(path
, &nd
);
218 error
= vfs_statfs(nd
.dentry
, &tmp
);
220 error
= put_compat_statfs(buf
, &tmp
);
226 asmlinkage
long compat_sys_fstatfs(unsigned int fd
, struct compat_statfs __user
*buf
)
236 error
= vfs_statfs(file
->f_path
.dentry
, &tmp
);
238 error
= put_compat_statfs(buf
, &tmp
);
244 static int put_compat_statfs64(struct compat_statfs64 __user
*ubuf
, struct kstatfs
*kbuf
)
246 if (sizeof ubuf
->f_blocks
== 4) {
247 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
248 0xffffffff00000000ULL
)
250 /* f_files and f_ffree may be -1; it's okay
251 * to stuff that into 32 bits */
252 if (kbuf
->f_files
!= 0xffffffffffffffffULL
253 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
255 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
256 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
259 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
260 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
261 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
262 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
263 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
264 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
265 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
266 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
267 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
268 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
269 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
270 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
))
275 asmlinkage
long compat_sys_statfs64(const char __user
*path
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
280 if (sz
!= sizeof(*buf
))
283 error
= user_path_walk(path
, &nd
);
286 error
= vfs_statfs(nd
.dentry
, &tmp
);
288 error
= put_compat_statfs64(buf
, &tmp
);
294 asmlinkage
long compat_sys_fstatfs64(unsigned int fd
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
300 if (sz
!= sizeof(*buf
))
307 error
= vfs_statfs(file
->f_path
.dentry
, &tmp
);
309 error
= put_compat_statfs64(buf
, &tmp
);
315 /* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */
317 #define IOCTL_HASHSIZE 256
318 static struct ioctl_trans
*ioctl32_hash_table
[IOCTL_HASHSIZE
];
320 static inline unsigned long ioctl32_hash(unsigned long cmd
)
322 return (((cmd
>> 6) ^ (cmd
>> 4) ^ cmd
)) % IOCTL_HASHSIZE
;
325 static void ioctl32_insert_translation(struct ioctl_trans
*trans
)
328 struct ioctl_trans
*t
;
330 hash
= ioctl32_hash (trans
->cmd
);
331 if (!ioctl32_hash_table
[hash
])
332 ioctl32_hash_table
[hash
] = trans
;
334 t
= ioctl32_hash_table
[hash
];
342 static int __init
init_sys32_ioctl(void)
346 for (i
= 0; i
< ioctl_table_size
; i
++) {
347 if (ioctl_start
[i
].next
!= 0) {
348 printk("ioctl translation %d bad\n",i
);
352 ioctl32_insert_translation(&ioctl_start
[i
]);
357 __initcall(init_sys32_ioctl
);
359 static void compat_ioctl_error(struct file
*filp
, unsigned int fd
,
360 unsigned int cmd
, unsigned long arg
)
366 /* find the name of the device. */
367 path
= (char *)__get_free_page(GFP_KERNEL
);
369 fn
= d_path(filp
->f_path
.dentry
, filp
->f_path
.mnt
, path
, PAGE_SIZE
);
374 sprintf(buf
,"'%c'", (cmd
>>24) & 0x3f);
375 if (!isprint(buf
[1]))
376 sprintf(buf
, "%02x", buf
[1]);
377 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
378 "cmd(%08x){%s} arg(%08x) on %s\n",
379 current
->comm
, current
->pid
,
380 (int)fd
, (unsigned int)cmd
, buf
,
381 (unsigned int)arg
, fn
);
384 free_page((unsigned long)path
);
387 asmlinkage
long compat_sys_ioctl(unsigned int fd
, unsigned int cmd
,
392 struct ioctl_trans
*t
;
395 filp
= fget_light(fd
, &fput_needed
);
399 /* RED-PEN how should LSM module know it's handling 32bit? */
400 error
= security_file_ioctl(filp
, cmd
, arg
);
405 * To allow the compat_ioctl handlers to be self contained
406 * we need to check the common ioctls here first.
407 * Just handle them with the standard handlers below.
420 if (S_ISREG(filp
->f_path
.dentry
->d_inode
->i_mode
))
425 if (filp
->f_op
&& filp
->f_op
->compat_ioctl
) {
426 error
= filp
->f_op
->compat_ioctl(filp
, cmd
, arg
);
427 if (error
!= -ENOIOCTLCMD
)
432 (!filp
->f_op
->ioctl
&& !filp
->f_op
->unlocked_ioctl
))
437 for (t
= ioctl32_hash_table
[ioctl32_hash(cmd
)]; t
; t
= t
->next
) {
442 if (S_ISSOCK(filp
->f_path
.dentry
->d_inode
->i_mode
) &&
443 cmd
>= SIOCDEVPRIVATE
&& cmd
<= (SIOCDEVPRIVATE
+ 15)) {
444 error
= siocdevprivate_ioctl(fd
, cmd
, arg
);
449 compat_ioctl_error(filp
, fd
, cmd
, arg
);
458 error
= t
->handler(fd
, cmd
, arg
, filp
);
464 error
= vfs_ioctl(filp
, fd
, cmd
, arg
);
466 fput_light(filp
, fput_needed
);
471 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
473 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
474 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
475 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
476 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
477 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
478 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
483 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
485 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
486 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
487 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
488 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
489 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
490 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
495 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
496 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
498 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
499 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
500 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
501 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
502 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
503 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
509 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
510 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
512 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
513 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
514 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
515 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
516 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
517 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
523 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
534 ret
= get_compat_flock(&f
, compat_ptr(arg
));
539 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
541 if (cmd
== F_GETLK
&& ret
== 0) {
542 /* GETLK was successfule and we need to return the data...
543 * but it needs to fit in the compat structure.
544 * l_start shouldn't be too big, unless the original
545 * start + end is greater than COMPAT_OFF_T_MAX, in which
546 * case the app was asking for trouble, so we return
547 * -EOVERFLOW in that case.
548 * l_len could be too big, in which case we just truncate it,
549 * and only allow the app to see that part of the conflicting
550 * lock that might make sense to it anyway
553 if (f
.l_start
> COMPAT_OFF_T_MAX
)
555 if (f
.l_len
> COMPAT_OFF_T_MAX
)
556 f
.l_len
= COMPAT_OFF_T_MAX
;
558 ret
= put_compat_flock(&f
, compat_ptr(arg
));
565 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
570 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
571 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
574 if (cmd
== F_GETLK64
&& ret
== 0) {
575 /* need to return lock information - see above for commentary */
576 if (f
.l_start
> COMPAT_LOFF_T_MAX
)
578 if (f
.l_len
> COMPAT_LOFF_T_MAX
)
579 f
.l_len
= COMPAT_LOFF_T_MAX
;
581 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
586 ret
= sys_fcntl(fd
, cmd
, arg
);
592 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
595 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
597 return compat_sys_fcntl64(fd
, cmd
, arg
);
601 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
606 mm_segment_t oldfs
= get_fs();
607 if (unlikely(get_user(ctx64
, ctx32p
)))
611 /* The __user pointer cast is valid because of the set_fs() */
612 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
614 /* truncating is ok because it's a user address */
616 ret
= put_user((u32
) ctx64
, ctx32p
);
621 compat_sys_io_getevents(aio_context_t ctx_id
,
622 unsigned long min_nr
,
624 struct io_event __user
*events
,
625 struct compat_timespec __user
*timeout
)
629 struct timespec __user
*ut
= NULL
;
632 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
633 nr
* sizeof(struct io_event
))))
636 if (get_compat_timespec(&t
, timeout
))
639 ut
= compat_alloc_user_space(sizeof(*ut
));
640 if (copy_to_user(ut
, &t
, sizeof(t
)) )
643 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
649 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
654 for (i
= 0; i
< nr
; ++i
) {
655 if (get_user(uptr
, ptr32
+ i
))
657 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
663 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
666 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
668 struct iocb __user
* __user
*iocb64
;
671 if (unlikely(nr
< 0))
674 if (nr
> MAX_AIO_SUBMITS
)
675 nr
= MAX_AIO_SUBMITS
;
677 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
678 ret
= copy_iocb(nr
, iocb
, iocb64
);
680 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
684 struct compat_ncp_mount_data
{
685 compat_int_t version
;
686 compat_uint_t ncp_fd
;
687 __compat_uid_t mounted_uid
;
688 compat_pid_t wdog_pid
;
689 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
690 compat_uint_t time_out
;
691 compat_uint_t retry_count
;
695 compat_mode_t file_mode
;
696 compat_mode_t dir_mode
;
699 struct compat_ncp_mount_data_v4
{
700 compat_int_t version
;
701 compat_ulong_t flags
;
702 compat_ulong_t mounted_uid
;
703 compat_long_t wdog_pid
;
704 compat_uint_t ncp_fd
;
705 compat_uint_t time_out
;
706 compat_uint_t retry_count
;
709 compat_ulong_t file_mode
;
710 compat_ulong_t dir_mode
;
713 static void *do_ncp_super_data_conv(void *raw_data
)
715 int version
= *(unsigned int *)raw_data
;
718 struct compat_ncp_mount_data
*c_n
= raw_data
;
719 struct ncp_mount_data
*n
= raw_data
;
721 n
->dir_mode
= c_n
->dir_mode
;
722 n
->file_mode
= c_n
->file_mode
;
725 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
726 n
->wdog_pid
= c_n
->wdog_pid
;
727 n
->mounted_uid
= c_n
->mounted_uid
;
728 } else if (version
== 4) {
729 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
730 struct ncp_mount_data_v4
*n
= raw_data
;
732 n
->dir_mode
= c_n
->dir_mode
;
733 n
->file_mode
= c_n
->file_mode
;
736 n
->retry_count
= c_n
->retry_count
;
737 n
->time_out
= c_n
->time_out
;
738 n
->ncp_fd
= c_n
->ncp_fd
;
739 n
->wdog_pid
= c_n
->wdog_pid
;
740 n
->mounted_uid
= c_n
->mounted_uid
;
741 n
->flags
= c_n
->flags
;
742 } else if (version
!= 5) {
749 struct compat_smb_mount_data
{
750 compat_int_t version
;
751 __compat_uid_t mounted_uid
;
754 compat_mode_t file_mode
;
755 compat_mode_t dir_mode
;
758 static void *do_smb_super_data_conv(void *raw_data
)
760 struct smb_mount_data
*s
= raw_data
;
761 struct compat_smb_mount_data
*c_s
= raw_data
;
763 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
765 s
->dir_mode
= c_s
->dir_mode
;
766 s
->file_mode
= c_s
->file_mode
;
769 s
->mounted_uid
= c_s
->mounted_uid
;
774 struct compat_nfs_string
{
779 static inline void compat_nfs_string(struct nfs_string
*dst
,
780 struct compat_nfs_string
*src
)
782 dst
->data
= compat_ptr(src
->data
);
786 struct compat_nfs4_mount_data_v1
{
787 compat_int_t version
;
792 compat_int_t retrans
;
793 compat_int_t acregmin
;
794 compat_int_t acregmax
;
795 compat_int_t acdirmin
;
796 compat_int_t acdirmax
;
797 struct compat_nfs_string client_addr
;
798 struct compat_nfs_string mnt_path
;
799 struct compat_nfs_string hostname
;
800 compat_uint_t host_addrlen
;
801 compat_uptr_t host_addr
;
803 compat_int_t auth_flavourlen
;
804 compat_uptr_t auth_flavours
;
807 static int do_nfs4_super_data_conv(void *raw_data
)
809 int version
= *(compat_uint_t
*) raw_data
;
812 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
813 struct nfs4_mount_data
*real
= raw_data
;
815 /* copy the fields backwards */
816 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
817 real
->auth_flavourlen
= raw
->auth_flavourlen
;
818 real
->proto
= raw
->proto
;
819 real
->host_addr
= compat_ptr(raw
->host_addr
);
820 real
->host_addrlen
= raw
->host_addrlen
;
821 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
822 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
823 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
824 real
->acdirmax
= raw
->acdirmax
;
825 real
->acdirmin
= raw
->acdirmin
;
826 real
->acregmax
= raw
->acregmax
;
827 real
->acregmin
= raw
->acregmin
;
828 real
->retrans
= raw
->retrans
;
829 real
->timeo
= raw
->timeo
;
830 real
->wsize
= raw
->wsize
;
831 real
->rsize
= raw
->rsize
;
832 real
->flags
= raw
->flags
;
833 real
->version
= raw
->version
;
842 #define SMBFS_NAME "smbfs"
843 #define NCPFS_NAME "ncpfs"
844 #define NFS4_NAME "nfs4"
846 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
847 char __user
* type
, unsigned long flags
,
850 unsigned long type_page
;
851 unsigned long data_page
;
852 unsigned long dev_page
;
856 retval
= copy_mount_options (type
, &type_page
);
860 dir_page
= getname(dir_name
);
861 retval
= PTR_ERR(dir_page
);
862 if (IS_ERR(dir_page
))
865 retval
= copy_mount_options (dev_name
, &dev_page
);
869 retval
= copy_mount_options (data
, &data_page
);
875 if (type_page
&& data_page
) {
876 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
877 do_smb_super_data_conv((void *)data_page
);
878 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
879 do_ncp_super_data_conv((void *)data_page
);
880 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
881 if (do_nfs4_super_data_conv((void *) data_page
))
887 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
888 flags
, (void*)data_page
);
892 free_page(data_page
);
898 free_page(type_page
);
903 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
904 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
905 ~(sizeof(compat_long_t)-1))
907 struct compat_old_linux_dirent
{
908 compat_ulong_t d_ino
;
909 compat_ulong_t d_offset
;
910 unsigned short d_namlen
;
914 struct compat_readdir_callback
{
915 struct compat_old_linux_dirent __user
*dirent
;
919 static int compat_fillonedir(void *__buf
, const char *name
, int namlen
,
920 loff_t offset
, u64 ino
, unsigned int d_type
)
922 struct compat_readdir_callback
*buf
= __buf
;
923 struct compat_old_linux_dirent __user
*dirent
;
924 compat_ulong_t d_ino
;
929 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
932 dirent
= buf
->dirent
;
933 if (!access_ok(VERIFY_WRITE
, dirent
,
934 (unsigned long)(dirent
->d_name
+ namlen
+ 1) -
935 (unsigned long)dirent
))
937 if ( __put_user(d_ino
, &dirent
->d_ino
) ||
938 __put_user(offset
, &dirent
->d_offset
) ||
939 __put_user(namlen
, &dirent
->d_namlen
) ||
940 __copy_to_user(dirent
->d_name
, name
, namlen
) ||
941 __put_user(0, dirent
->d_name
+ namlen
))
945 buf
->result
= -EFAULT
;
949 asmlinkage
long compat_sys_old_readdir(unsigned int fd
,
950 struct compat_old_linux_dirent __user
*dirent
, unsigned int count
)
954 struct compat_readdir_callback buf
;
964 error
= vfs_readdir(file
, compat_fillonedir
, &buf
);
973 struct compat_linux_dirent
{
974 compat_ulong_t d_ino
;
975 compat_ulong_t d_off
;
976 unsigned short d_reclen
;
980 struct compat_getdents_callback
{
981 struct compat_linux_dirent __user
*current_dir
;
982 struct compat_linux_dirent __user
*previous
;
987 static int compat_filldir(void *__buf
, const char *name
, int namlen
,
988 loff_t offset
, u64 ino
, unsigned int d_type
)
990 struct compat_linux_dirent __user
* dirent
;
991 struct compat_getdents_callback
*buf
= __buf
;
992 compat_ulong_t d_ino
;
993 int reclen
= COMPAT_ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 2);
995 buf
->error
= -EINVAL
; /* only used if we fail.. */
996 if (reclen
> buf
->count
)
999 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
1001 dirent
= buf
->previous
;
1003 if (__put_user(offset
, &dirent
->d_off
))
1006 dirent
= buf
->current_dir
;
1007 if (__put_user(d_ino
, &dirent
->d_ino
))
1009 if (__put_user(reclen
, &dirent
->d_reclen
))
1011 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1013 if (__put_user(0, dirent
->d_name
+ namlen
))
1015 if (__put_user(d_type
, (char __user
*) dirent
+ reclen
- 1))
1017 buf
->previous
= dirent
;
1018 dirent
= (void __user
*)dirent
+ reclen
;
1019 buf
->current_dir
= dirent
;
1020 buf
->count
-= reclen
;
1023 buf
->error
= -EFAULT
;
1027 asmlinkage
long compat_sys_getdents(unsigned int fd
,
1028 struct compat_linux_dirent __user
*dirent
, unsigned int count
)
1031 struct compat_linux_dirent __user
* lastdirent
;
1032 struct compat_getdents_callback buf
;
1036 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1044 buf
.current_dir
= dirent
;
1045 buf
.previous
= NULL
;
1049 error
= vfs_readdir(file
, compat_filldir
, &buf
);
1053 lastdirent
= buf
.previous
;
1055 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
1058 error
= count
- buf
.count
;
1067 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1068 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1070 struct compat_getdents_callback64
{
1071 struct linux_dirent64 __user
*current_dir
;
1072 struct linux_dirent64 __user
*previous
;
1077 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
1078 u64 ino
, unsigned int d_type
)
1080 struct linux_dirent64 __user
*dirent
;
1081 struct compat_getdents_callback64
*buf
= __buf
;
1082 int jj
= NAME_OFFSET(dirent
);
1083 int reclen
= COMPAT_ROUND_UP64(jj
+ namlen
+ 1);
1086 buf
->error
= -EINVAL
; /* only used if we fail.. */
1087 if (reclen
> buf
->count
)
1089 dirent
= buf
->previous
;
1092 if (__put_user_unaligned(offset
, &dirent
->d_off
))
1095 dirent
= buf
->current_dir
;
1096 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
1099 if (__put_user_unaligned(off
, &dirent
->d_off
))
1101 if (__put_user(reclen
, &dirent
->d_reclen
))
1103 if (__put_user(d_type
, &dirent
->d_type
))
1105 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1107 if (__put_user(0, dirent
->d_name
+ namlen
))
1109 buf
->previous
= dirent
;
1110 dirent
= (void __user
*)dirent
+ reclen
;
1111 buf
->current_dir
= dirent
;
1112 buf
->count
-= reclen
;
1115 buf
->error
= -EFAULT
;
1119 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
1120 struct linux_dirent64 __user
* dirent
, unsigned int count
)
1123 struct linux_dirent64 __user
* lastdirent
;
1124 struct compat_getdents_callback64 buf
;
1128 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1136 buf
.current_dir
= dirent
;
1137 buf
.previous
= NULL
;
1141 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1145 lastdirent
= buf
.previous
;
1147 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1149 if (__put_user_unaligned(d_off
, &lastdirent
->d_off
))
1151 error
= count
- buf
.count
;
1159 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1161 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1162 const struct compat_iovec __user
*uvector
,
1163 unsigned long nr_segs
, loff_t
*pos
)
1165 compat_ssize_t tot_len
;
1166 struct iovec iovstack
[UIO_FASTIOV
];
1167 struct iovec
*iov
=iovstack
, *vector
;
1174 * SuS says "The readv() function *may* fail if the iovcnt argument
1175 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1176 * traditionally returned zero for zero segments, so...
1183 * First get the "struct iovec" from user memory and
1184 * verify all the pointers
1187 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1191 if (nr_segs
> UIO_FASTIOV
) {
1193 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1198 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1202 * Single unix specification:
1203 * We should -EINVAL if an element length is not >= 0 and fitting an
1204 * ssize_t. The total length is fitting an ssize_t
1206 * Be careful here because iov_len is a size_t not an ssize_t
1211 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1212 compat_ssize_t tmp
= tot_len
;
1216 if (__get_user(len
, &uvector
->iov_len
) ||
1217 __get_user(buf
, &uvector
->iov_base
)) {
1221 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1224 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1226 vector
->iov_base
= compat_ptr(buf
);
1227 vector
->iov_len
= (compat_size_t
) len
;
1236 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1240 ret
= security_file_permission(file
, type
== READ
? MAY_READ
:MAY_WRITE
);
1246 fn
= file
->f_op
->read
;
1247 fnv
= file
->f_op
->aio_read
;
1249 fn
= (io_fn_t
)file
->f_op
->write
;
1250 fnv
= file
->f_op
->aio_write
;
1254 ret
= do_sync_readv_writev(file
, iov
, nr_segs
, tot_len
,
1257 ret
= do_loop_readv_writev(file
, iov
, nr_segs
, pos
, fn
);
1260 if (iov
!= iovstack
)
1262 if ((ret
+ (type
== READ
)) > 0) {
1263 struct dentry
*dentry
= file
->f_path
.dentry
;
1265 fsnotify_access(dentry
);
1267 fsnotify_modify(dentry
);
1273 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1276 ssize_t ret
= -EBADF
;
1282 if (!(file
->f_mode
& FMODE_READ
))
1286 if (!file
->f_op
|| (!file
->f_op
->aio_read
&& !file
->f_op
->read
))
1289 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1297 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1300 ssize_t ret
= -EBADF
;
1305 if (!(file
->f_mode
& FMODE_WRITE
))
1309 if (!file
->f_op
|| (!file
->f_op
->aio_write
&& !file
->f_op
->write
))
1312 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1320 compat_sys_vmsplice(int fd
, const struct compat_iovec __user
*iov32
,
1321 unsigned int nr_segs
, unsigned int flags
)
1324 struct iovec __user
*iov
;
1325 if (nr_segs
> UIO_MAXIOV
)
1327 iov
= compat_alloc_user_space(nr_segs
* sizeof(struct iovec
));
1328 for (i
= 0; i
< nr_segs
; i
++) {
1329 struct compat_iovec v
;
1330 if (get_user(v
.iov_base
, &iov32
[i
].iov_base
) ||
1331 get_user(v
.iov_len
, &iov32
[i
].iov_len
) ||
1332 put_user(compat_ptr(v
.iov_base
), &iov
[i
].iov_base
) ||
1333 put_user(v
.iov_len
, &iov
[i
].iov_len
))
1336 return sys_vmsplice(fd
, iov
, nr_segs
, flags
);
1340 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1344 compat_sys_open(const char __user
*filename
, int flags
, int mode
)
1346 return do_sys_open(AT_FDCWD
, filename
, flags
, mode
);
1350 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1354 compat_sys_openat(unsigned int dfd
, const char __user
*filename
, int flags
, int mode
)
1356 return do_sys_open(dfd
, filename
, flags
, mode
);
1360 * compat_count() counts the number of arguments/envelopes. It is basically
1361 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1362 * and envp pointers.
1364 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1372 if (get_user(p
, argv
))
1385 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1386 * except that it works with 32 bit argv and envp pointers.
1388 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1389 struct linux_binprm
*bprm
)
1391 struct page
*kmapped_page
= NULL
;
1395 while (argc
-- > 0) {
1400 if (get_user(str
, argv
+argc
) ||
1401 !(len
= strnlen_user(compat_ptr(str
), bprm
->p
))) {
1406 if (bprm
->p
< len
) {
1412 /* XXX: add architecture specific overflow check here. */
1417 int offset
, bytes_to_copy
;
1420 offset
= pos
% PAGE_SIZE
;
1422 page
= bprm
->page
[i
];
1425 page
= alloc_page(GFP_HIGHUSER
);
1426 bprm
->page
[i
] = page
;
1434 if (page
!= kmapped_page
) {
1436 kunmap(kmapped_page
);
1437 kmapped_page
= page
;
1438 kaddr
= kmap(kmapped_page
);
1441 memset(kaddr
, 0, offset
);
1442 bytes_to_copy
= PAGE_SIZE
- offset
;
1443 if (bytes_to_copy
> len
) {
1444 bytes_to_copy
= len
;
1446 memset(kaddr
+offset
+len
, 0,
1447 PAGE_SIZE
-offset
-len
);
1449 err
= copy_from_user(kaddr
+offset
, compat_ptr(str
),
1456 pos
+= bytes_to_copy
;
1457 str
+= bytes_to_copy
;
1458 len
-= bytes_to_copy
;
1464 kunmap(kmapped_page
);
1470 #define free_arg_pages(bprm) do { } while (0)
1474 static inline void free_arg_pages(struct linux_binprm
*bprm
)
1478 for (i
= 0; i
< MAX_ARG_PAGES
; i
++) {
1480 __free_page(bprm
->page
[i
]);
1481 bprm
->page
[i
] = NULL
;
1485 #endif /* CONFIG_MMU */
1488 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1489 * that it processes 32 bit argv and envp pointers.
1491 int compat_do_execve(char * filename
,
1492 compat_uptr_t __user
*argv
,
1493 compat_uptr_t __user
*envp
,
1494 struct pt_regs
* regs
)
1496 struct linux_binprm
*bprm
;
1502 bprm
= kzalloc(sizeof(*bprm
), GFP_KERNEL
);
1506 file
= open_exec(filename
);
1507 retval
= PTR_ERR(file
);
1513 bprm
->p
= PAGE_SIZE
*MAX_ARG_PAGES
-sizeof(void *);
1515 bprm
->filename
= filename
;
1516 bprm
->interp
= filename
;
1517 bprm
->mm
= mm_alloc();
1522 retval
= init_new_context(current
, bprm
->mm
);
1526 bprm
->argc
= compat_count(argv
, bprm
->p
/ sizeof(compat_uptr_t
));
1527 if ((retval
= bprm
->argc
) < 0)
1530 bprm
->envc
= compat_count(envp
, bprm
->p
/ sizeof(compat_uptr_t
));
1531 if ((retval
= bprm
->envc
) < 0)
1534 retval
= security_bprm_alloc(bprm
);
1538 retval
= prepare_binprm(bprm
);
1542 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1546 bprm
->exec
= bprm
->p
;
1547 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1551 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1555 retval
= search_binary_handler(bprm
, regs
);
1557 free_arg_pages(bprm
);
1559 /* execve success */
1560 security_bprm_free(bprm
);
1561 acct_update_integrals(current
);
1567 /* Something went wrong, return the inode and free the argument pages*/
1568 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
1569 struct page
* page
= bprm
->page
[i
];
1575 security_bprm_free(bprm
);
1583 allow_write_access(bprm
->file
);
1594 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1596 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1599 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1600 * 64-bit unsigned longs.
1603 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1604 unsigned long *fdset
)
1606 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1610 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1617 if (__get_user(l
, ufdset
) || __get_user(h
, ufdset
+1))
1620 *fdset
++ = h
<< 32 | l
;
1623 if (odd
&& __get_user(*fdset
, ufdset
))
1626 /* Tricky, must clear full unsigned long in the
1627 * kernel fdset at the end, this makes sure that
1630 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1636 int compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1637 unsigned long *fdset
)
1640 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1651 if (__put_user(l
, ufdset
) || __put_user(h
, ufdset
+1))
1656 if (odd
&& __put_user(*fdset
, ufdset
))
1663 * This is a virtual copy of sys_select from fs/select.c and probably
1664 * should be compared to it from time to time
1668 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1669 * like to be certain this leads to no problems. So I return
1670 * EINTR just for safety.
1672 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1673 * I'm trying ERESTARTNOHAND which restart only when you want to.
1675 #define MAX_SELECT_SECONDS \
1676 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1678 int compat_core_sys_select(int n
, compat_ulong_t __user
*inp
,
1679 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
, s64
*timeout
)
1683 int size
, max_fds
, ret
= -EINVAL
;
1684 struct fdtable
*fdt
;
1689 /* max_fds can increase, so grab it once to avoid race */
1691 fdt
= files_fdtable(current
->files
);
1692 max_fds
= fdt
->max_fds
;
1698 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1699 * since we used fdset we need to allocate memory in units of
1703 size
= FDS_BYTES(n
);
1704 bits
= kmalloc(6 * size
, GFP_KERNEL
);
1707 fds
.in
= (unsigned long *) bits
;
1708 fds
.out
= (unsigned long *) (bits
+ size
);
1709 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1710 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1711 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1712 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1714 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1715 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1716 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1718 zero_fd_set(n
, fds
.res_in
);
1719 zero_fd_set(n
, fds
.res_out
);
1720 zero_fd_set(n
, fds
.res_ex
);
1722 ret
= do_select(n
, &fds
, timeout
);
1727 ret
= -ERESTARTNOHAND
;
1728 if (signal_pending(current
))
1733 if (compat_set_fd_set(n
, inp
, fds
.res_in
) ||
1734 compat_set_fd_set(n
, outp
, fds
.res_out
) ||
1735 compat_set_fd_set(n
, exp
, fds
.res_ex
))
1743 asmlinkage
long compat_sys_select(int n
, compat_ulong_t __user
*inp
,
1744 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1745 struct compat_timeval __user
*tvp
)
1748 struct compat_timeval tv
;
1752 if (copy_from_user(&tv
, tvp
, sizeof(tv
)))
1755 if (tv
.tv_sec
< 0 || tv
.tv_usec
< 0)
1758 /* Cast to u64 to make GCC stop complaining */
1759 if ((u64
)tv
.tv_sec
>= (u64
)MAX_INT64_SECONDS
)
1760 timeout
= -1; /* infinite */
1762 timeout
= ROUND_UP(tv
.tv_usec
, 1000000/HZ
);
1763 timeout
+= tv
.tv_sec
* HZ
;
1767 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1770 struct compat_timeval rtv
;
1772 if (current
->personality
& STICKY_TIMEOUTS
)
1774 rtv
.tv_usec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
));
1775 rtv
.tv_sec
= timeout
;
1776 if (compat_timeval_compare(&rtv
, &tv
) >= 0)
1778 if (copy_to_user(tvp
, &rtv
, sizeof(rtv
))) {
1781 * If an application puts its timeval in read-only
1782 * memory, we don't want the Linux-specific update to
1783 * the timeval to cause a fault after the select has
1784 * completed successfully. However, because we're not
1785 * updating the timeval, we can't restart the system
1788 if (ret
== -ERESTARTNOHAND
)
1796 #ifdef TIF_RESTORE_SIGMASK
1797 asmlinkage
long compat_sys_pselect7(int n
, compat_ulong_t __user
*inp
,
1798 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1799 struct compat_timespec __user
*tsp
, compat_sigset_t __user
*sigmask
,
1800 compat_size_t sigsetsize
)
1802 compat_sigset_t ss32
;
1803 sigset_t ksigmask
, sigsaved
;
1804 s64 timeout
= MAX_SCHEDULE_TIMEOUT
;
1805 struct compat_timespec ts
;
1809 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1812 if (ts
.tv_sec
< 0 || ts
.tv_nsec
< 0)
1817 if (sigsetsize
!= sizeof(compat_sigset_t
))
1819 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1821 sigset_from_compat(&ksigmask
, &ss32
);
1823 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1824 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1829 if ((unsigned long)ts
.tv_sec
< MAX_SELECT_SECONDS
) {
1830 timeout
= ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1831 timeout
+= ts
.tv_sec
* (unsigned long)HZ
;
1835 ts
.tv_sec
-= MAX_SELECT_SECONDS
;
1836 timeout
= MAX_SELECT_SECONDS
* HZ
;
1840 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1842 } while (!ret
&& !timeout
&& tsp
&& (ts
.tv_sec
|| ts
.tv_nsec
));
1845 struct compat_timespec rts
;
1847 if (current
->personality
& STICKY_TIMEOUTS
)
1850 rts
.tv_sec
= timeout
/ HZ
;
1851 rts
.tv_nsec
= (timeout
% HZ
) * (NSEC_PER_SEC
/HZ
);
1852 if (rts
.tv_nsec
>= NSEC_PER_SEC
) {
1854 rts
.tv_nsec
-= NSEC_PER_SEC
;
1856 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1858 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1861 * If an application puts its timeval in read-only
1862 * memory, we don't want the Linux-specific update to
1863 * the timeval to cause a fault after the select has
1864 * completed successfully. However, because we're not
1865 * updating the timeval, we can't restart the system
1868 if (ret
== -ERESTARTNOHAND
)
1873 if (ret
== -ERESTARTNOHAND
) {
1875 * Don't restore the signal mask yet. Let do_signal() deliver
1876 * the signal on the way back to userspace, before the signal
1880 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1882 set_thread_flag(TIF_RESTORE_SIGMASK
);
1885 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1890 asmlinkage
long compat_sys_pselect6(int n
, compat_ulong_t __user
*inp
,
1891 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1892 struct compat_timespec __user
*tsp
, void __user
*sig
)
1894 compat_size_t sigsetsize
= 0;
1895 compat_uptr_t up
= 0;
1898 if (!access_ok(VERIFY_READ
, sig
,
1899 sizeof(compat_uptr_t
)+sizeof(compat_size_t
)) ||
1900 __get_user(up
, (compat_uptr_t __user
*)sig
) ||
1901 __get_user(sigsetsize
,
1902 (compat_size_t __user
*)(sig
+sizeof(up
))))
1905 return compat_sys_pselect7(n
, inp
, outp
, exp
, tsp
, compat_ptr(up
),
1909 asmlinkage
long compat_sys_ppoll(struct pollfd __user
*ufds
,
1910 unsigned int nfds
, struct compat_timespec __user
*tsp
,
1911 const compat_sigset_t __user
*sigmask
, compat_size_t sigsetsize
)
1913 compat_sigset_t ss32
;
1914 sigset_t ksigmask
, sigsaved
;
1915 struct compat_timespec ts
;
1920 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1923 /* We assume that ts.tv_sec is always lower than
1924 the number of seconds that can be expressed in
1925 an s64. Otherwise the compiler bitches at us */
1926 timeout
= ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1927 timeout
+= ts
.tv_sec
* HZ
;
1931 if (sigsetsize
!= sizeof(compat_sigset_t
))
1933 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1935 sigset_from_compat(&ksigmask
, &ss32
);
1937 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1938 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1941 ret
= do_sys_poll(ufds
, nfds
, &timeout
);
1943 /* We can restart this syscall, usually */
1944 if (ret
== -EINTR
) {
1946 * Don't restore the signal mask yet. Let do_signal() deliver
1947 * the signal on the way back to userspace, before the signal
1951 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1953 set_thread_flag(TIF_RESTORE_SIGMASK
);
1955 ret
= -ERESTARTNOHAND
;
1957 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1959 if (tsp
&& timeout
>= 0) {
1960 struct compat_timespec rts
;
1962 if (current
->personality
& STICKY_TIMEOUTS
)
1964 /* Yes, we know it's actually an s64, but it's also positive. */
1965 rts
.tv_nsec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
)) *
1967 rts
.tv_sec
= timeout
;
1968 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1970 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1973 * If an application puts its timeval in read-only
1974 * memory, we don't want the Linux-specific update to
1975 * the timeval to cause a fault after the select has
1976 * completed successfully. However, because we're not
1977 * updating the timeval, we can't restart the system
1980 if (ret
== -ERESTARTNOHAND
&& timeout
>= 0)
1987 #endif /* TIF_RESTORE_SIGMASK */
1989 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1990 /* Stuff for NFS server syscalls... */
1991 struct compat_nfsctl_svc
{
1996 struct compat_nfsctl_client
{
1997 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
1999 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
2002 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
2005 struct compat_nfsctl_export
{
2006 char ex32_client
[NFSCLNT_IDMAX
+1];
2007 char ex32_path
[NFS_MAXPATHLEN
+1];
2008 compat_dev_t ex32_dev
;
2009 compat_ino_t ex32_ino
;
2010 compat_int_t ex32_flags
;
2011 __compat_uid_t ex32_anon_uid
;
2012 __compat_gid_t ex32_anon_gid
;
2015 struct compat_nfsctl_fdparm
{
2016 struct sockaddr gd32_addr
;
2017 s8 gd32_path
[NFS_MAXPATHLEN
+1];
2018 compat_int_t gd32_version
;
2021 struct compat_nfsctl_fsparm
{
2022 struct sockaddr gd32_addr
;
2023 s8 gd32_path
[NFS_MAXPATHLEN
+1];
2024 compat_int_t gd32_maxlen
;
2027 struct compat_nfsctl_arg
{
2028 compat_int_t ca32_version
; /* safeguard */
2030 struct compat_nfsctl_svc u32_svc
;
2031 struct compat_nfsctl_client u32_client
;
2032 struct compat_nfsctl_export u32_export
;
2033 struct compat_nfsctl_fdparm u32_getfd
;
2034 struct compat_nfsctl_fsparm u32_getfs
;
2036 #define ca32_svc u.u32_svc
2037 #define ca32_client u.u32_client
2038 #define ca32_export u.u32_export
2039 #define ca32_getfd u.u32_getfd
2040 #define ca32_getfs u.u32_getfs
2043 union compat_nfsctl_res
{
2044 __u8 cr32_getfh
[NFS_FHSIZE
];
2045 struct knfsd_fh cr32_getfs
;
2048 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
,
2049 struct compat_nfsctl_arg __user
*arg
)
2051 if (!access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
)) ||
2052 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2053 __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
) ||
2054 __get_user(karg
->ca_svc
.svc_nthreads
,
2055 &arg
->ca32_svc
.svc32_nthreads
))
2060 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
,
2061 struct compat_nfsctl_arg __user
*arg
)
2063 if (!access_ok(VERIFY_READ
, &arg
->ca32_client
,
2064 sizeof(arg
->ca32_client
)) ||
2065 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2066 __copy_from_user(&karg
->ca_client
.cl_ident
[0],
2067 &arg
->ca32_client
.cl32_ident
[0],
2069 __get_user(karg
->ca_client
.cl_naddr
,
2070 &arg
->ca32_client
.cl32_naddr
) ||
2071 __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
2072 &arg
->ca32_client
.cl32_addrlist
[0],
2073 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
)) ||
2074 __get_user(karg
->ca_client
.cl_fhkeytype
,
2075 &arg
->ca32_client
.cl32_fhkeytype
) ||
2076 __get_user(karg
->ca_client
.cl_fhkeylen
,
2077 &arg
->ca32_client
.cl32_fhkeylen
) ||
2078 __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
2079 &arg
->ca32_client
.cl32_fhkey
[0],
2086 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
,
2087 struct compat_nfsctl_arg __user
*arg
)
2089 if (!access_ok(VERIFY_READ
, &arg
->ca32_export
,
2090 sizeof(arg
->ca32_export
)) ||
2091 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2092 __copy_from_user(&karg
->ca_export
.ex_client
[0],
2093 &arg
->ca32_export
.ex32_client
[0],
2095 __copy_from_user(&karg
->ca_export
.ex_path
[0],
2096 &arg
->ca32_export
.ex32_path
[0],
2098 __get_user(karg
->ca_export
.ex_dev
,
2099 &arg
->ca32_export
.ex32_dev
) ||
2100 __get_user(karg
->ca_export
.ex_ino
,
2101 &arg
->ca32_export
.ex32_ino
) ||
2102 __get_user(karg
->ca_export
.ex_flags
,
2103 &arg
->ca32_export
.ex32_flags
) ||
2104 __get_user(karg
->ca_export
.ex_anon_uid
,
2105 &arg
->ca32_export
.ex32_anon_uid
) ||
2106 __get_user(karg
->ca_export
.ex_anon_gid
,
2107 &arg
->ca32_export
.ex32_anon_gid
))
2109 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
2110 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
2115 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
,
2116 struct compat_nfsctl_arg __user
*arg
)
2118 if (!access_ok(VERIFY_READ
, &arg
->ca32_getfd
,
2119 sizeof(arg
->ca32_getfd
)) ||
2120 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2121 __copy_from_user(&karg
->ca_getfd
.gd_addr
,
2122 &arg
->ca32_getfd
.gd32_addr
,
2123 (sizeof(struct sockaddr
))) ||
2124 __copy_from_user(&karg
->ca_getfd
.gd_path
,
2125 &arg
->ca32_getfd
.gd32_path
,
2126 (NFS_MAXPATHLEN
+1)) ||
2127 __get_user(karg
->ca_getfd
.gd_version
,
2128 &arg
->ca32_getfd
.gd32_version
))
2134 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
,
2135 struct compat_nfsctl_arg __user
*arg
)
2137 if (!access_ok(VERIFY_READ
,&arg
->ca32_getfs
,sizeof(arg
->ca32_getfs
)) ||
2138 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2139 __copy_from_user(&karg
->ca_getfs
.gd_addr
,
2140 &arg
->ca32_getfs
.gd32_addr
,
2141 (sizeof(struct sockaddr
))) ||
2142 __copy_from_user(&karg
->ca_getfs
.gd_path
,
2143 &arg
->ca32_getfs
.gd32_path
,
2144 (NFS_MAXPATHLEN
+1)) ||
2145 __get_user(karg
->ca_getfs
.gd_maxlen
,
2146 &arg
->ca32_getfs
.gd32_maxlen
))
2152 /* This really doesn't need translations, we are only passing
2153 * back a union which contains opaque nfs file handle data.
2155 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
,
2156 union compat_nfsctl_res __user
*res
)
2160 err
= copy_to_user(res
, kres
, sizeof(*res
));
2162 return (err
) ? -EFAULT
: 0;
2165 asmlinkage
long compat_sys_nfsservctl(int cmd
,
2166 struct compat_nfsctl_arg __user
*arg
,
2167 union compat_nfsctl_res __user
*res
)
2169 struct nfsctl_arg
*karg
;
2170 union nfsctl_res
*kres
;
2174 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
2175 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
2176 if(!karg
|| !kres
) {
2183 err
= compat_nfs_svc_trans(karg
, arg
);
2186 case NFSCTL_ADDCLIENT
:
2187 err
= compat_nfs_clnt_trans(karg
, arg
);
2190 case NFSCTL_DELCLIENT
:
2191 err
= compat_nfs_clnt_trans(karg
, arg
);
2195 case NFSCTL_UNEXPORT
:
2196 err
= compat_nfs_exp_trans(karg
, arg
);
2200 err
= compat_nfs_getfd_trans(karg
, arg
);
2204 err
= compat_nfs_getfs_trans(karg
, arg
);
2217 /* The __user pointer casts are valid because of the set_fs() */
2218 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
2224 if((cmd
== NFSCTL_GETFD
) ||
2225 (cmd
== NFSCTL_GETFS
))
2226 err
= compat_nfs_getfh_res_trans(kres
, res
);
2234 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
2236 return sys_ni_syscall();
2242 #ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
2243 asmlinkage
long compat_sys_epoll_ctl(int epfd
, int op
, int fd
,
2244 struct compat_epoll_event __user
*event
)
2247 struct compat_epoll_event user
;
2248 struct epoll_event __user
*kernel
= NULL
;
2251 if (copy_from_user(&user
, event
, sizeof(user
)))
2253 kernel
= compat_alloc_user_space(sizeof(struct epoll_event
));
2254 err
|= __put_user(user
.events
, &kernel
->events
);
2255 err
|= __put_user(user
.data
, &kernel
->data
);
2258 return err
? err
: sys_epoll_ctl(epfd
, op
, fd
, kernel
);
2262 asmlinkage
long compat_sys_epoll_wait(int epfd
,
2263 struct compat_epoll_event __user
*events
,
2264 int maxevents
, int timeout
)
2266 long i
, ret
, err
= 0;
2267 struct epoll_event __user
*kbuf
;
2268 struct epoll_event ev
;
2270 if ((maxevents
<= 0) ||
2271 (maxevents
> (INT_MAX
/ sizeof(struct epoll_event
))))
2273 kbuf
= compat_alloc_user_space(sizeof(struct epoll_event
) * maxevents
);
2274 ret
= sys_epoll_wait(epfd
, kbuf
, maxevents
, timeout
);
2275 for (i
= 0; i
< ret
; i
++) {
2276 err
|= __get_user(ev
.events
, &kbuf
[i
].events
);
2277 err
|= __get_user(ev
.data
, &kbuf
[i
].data
);
2278 err
|= __put_user(ev
.events
, &events
->events
);
2279 err
|= __put_user_unaligned(ev
.data
, &events
->data
);
2283 return err
? -EFAULT
: ret
;
2285 #endif /* CONFIG_HAS_COMPAT_EPOLL_EVENT */
2287 #ifdef TIF_RESTORE_SIGMASK
2288 asmlinkage
long compat_sys_epoll_pwait(int epfd
,
2289 struct compat_epoll_event __user
*events
,
2290 int maxevents
, int timeout
,
2291 const compat_sigset_t __user
*sigmask
,
2292 compat_size_t sigsetsize
)
2295 compat_sigset_t csigmask
;
2296 sigset_t ksigmask
, sigsaved
;
2299 * If the caller wants a certain signal mask to be set during the wait,
2303 if (sigsetsize
!= sizeof(compat_sigset_t
))
2305 if (copy_from_user(&csigmask
, sigmask
, sizeof(csigmask
)))
2307 sigset_from_compat(&ksigmask
, &csigmask
);
2308 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
) | sigmask(SIGSTOP
));
2309 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
2312 #ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
2313 err
= compat_sys_epoll_wait(epfd
, events
, maxevents
, timeout
);
2315 err
= sys_epoll_wait(epfd
, events
, maxevents
, timeout
);
2319 * If we changed the signal mask, we need to restore the original one.
2320 * In case we've got a signal while waiting, we do not restore the
2321 * signal mask yet, and we allow do_signal() to deliver the signal on
2322 * the way back to userspace, before the signal mask is restored.
2325 if (err
== -EINTR
) {
2326 memcpy(¤t
->saved_sigmask
, &sigsaved
,
2328 set_thread_flag(TIF_RESTORE_SIGMASK
);
2330 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
2335 #endif /* TIF_RESTORE_SIGMASK */
2337 #endif /* CONFIG_EPOLL */