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
>>_IOC_TYPESHIFT
) & _IOC_TYPEMASK
);
375 if (!isprint(buf
[1]))
376 sprintf(buf
, "%02x", buf
[1]);
377 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
378 "cmd(%08x){t:%s;sz:%u} arg(%08x) on %s\n",
379 current
->comm
, current
->pid
,
380 (int)fd
, (unsigned int)cmd
, buf
,
381 (cmd
>> _IOC_SIZESHIFT
) & _IOC_SIZEMASK
,
382 (unsigned int)arg
, fn
);
385 free_page((unsigned long)path
);
388 asmlinkage
long compat_sys_ioctl(unsigned int fd
, unsigned int cmd
,
393 struct ioctl_trans
*t
;
396 filp
= fget_light(fd
, &fput_needed
);
400 /* RED-PEN how should LSM module know it's handling 32bit? */
401 error
= security_file_ioctl(filp
, cmd
, arg
);
406 * To allow the compat_ioctl handlers to be self contained
407 * we need to check the common ioctls here first.
408 * Just handle them with the standard handlers below.
421 if (S_ISREG(filp
->f_path
.dentry
->d_inode
->i_mode
))
426 if (filp
->f_op
&& filp
->f_op
->compat_ioctl
) {
427 error
= filp
->f_op
->compat_ioctl(filp
, cmd
, arg
);
428 if (error
!= -ENOIOCTLCMD
)
433 (!filp
->f_op
->ioctl
&& !filp
->f_op
->unlocked_ioctl
))
438 for (t
= ioctl32_hash_table
[ioctl32_hash(cmd
)]; t
; t
= t
->next
) {
443 if (S_ISSOCK(filp
->f_path
.dentry
->d_inode
->i_mode
) &&
444 cmd
>= SIOCDEVPRIVATE
&& cmd
<= (SIOCDEVPRIVATE
+ 15)) {
445 error
= siocdevprivate_ioctl(fd
, cmd
, arg
);
450 compat_ioctl_error(filp
, fd
, cmd
, arg
);
459 error
= t
->handler(fd
, cmd
, arg
, filp
);
465 error
= vfs_ioctl(filp
, fd
, cmd
, arg
);
467 fput_light(filp
, fput_needed
);
472 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
474 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
475 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
476 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
477 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
478 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
479 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
484 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
486 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
487 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
488 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
489 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
490 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
491 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
496 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
497 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
499 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
500 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
501 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
502 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
503 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
504 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
510 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
511 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
513 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
514 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
515 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
516 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
517 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
518 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
524 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
535 ret
= get_compat_flock(&f
, compat_ptr(arg
));
540 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
542 if (cmd
== F_GETLK
&& ret
== 0) {
543 /* GETLK was successfule and we need to return the data...
544 * but it needs to fit in the compat structure.
545 * l_start shouldn't be too big, unless the original
546 * start + end is greater than COMPAT_OFF_T_MAX, in which
547 * case the app was asking for trouble, so we return
548 * -EOVERFLOW in that case.
549 * l_len could be too big, in which case we just truncate it,
550 * and only allow the app to see that part of the conflicting
551 * lock that might make sense to it anyway
554 if (f
.l_start
> COMPAT_OFF_T_MAX
)
556 if (f
.l_len
> COMPAT_OFF_T_MAX
)
557 f
.l_len
= COMPAT_OFF_T_MAX
;
559 ret
= put_compat_flock(&f
, compat_ptr(arg
));
566 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
571 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
572 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
575 if (cmd
== F_GETLK64
&& ret
== 0) {
576 /* need to return lock information - see above for commentary */
577 if (f
.l_start
> COMPAT_LOFF_T_MAX
)
579 if (f
.l_len
> COMPAT_LOFF_T_MAX
)
580 f
.l_len
= COMPAT_LOFF_T_MAX
;
582 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
587 ret
= sys_fcntl(fd
, cmd
, arg
);
593 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
596 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
598 return compat_sys_fcntl64(fd
, cmd
, arg
);
602 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
607 mm_segment_t oldfs
= get_fs();
608 if (unlikely(get_user(ctx64
, ctx32p
)))
612 /* The __user pointer cast is valid because of the set_fs() */
613 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
615 /* truncating is ok because it's a user address */
617 ret
= put_user((u32
) ctx64
, ctx32p
);
622 compat_sys_io_getevents(aio_context_t ctx_id
,
623 unsigned long min_nr
,
625 struct io_event __user
*events
,
626 struct compat_timespec __user
*timeout
)
630 struct timespec __user
*ut
= NULL
;
633 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
634 nr
* sizeof(struct io_event
))))
637 if (get_compat_timespec(&t
, timeout
))
640 ut
= compat_alloc_user_space(sizeof(*ut
));
641 if (copy_to_user(ut
, &t
, sizeof(t
)) )
644 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
650 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
655 for (i
= 0; i
< nr
; ++i
) {
656 if (get_user(uptr
, ptr32
+ i
))
658 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
664 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
667 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
669 struct iocb __user
* __user
*iocb64
;
672 if (unlikely(nr
< 0))
675 if (nr
> MAX_AIO_SUBMITS
)
676 nr
= MAX_AIO_SUBMITS
;
678 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
679 ret
= copy_iocb(nr
, iocb
, iocb64
);
681 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
685 struct compat_ncp_mount_data
{
686 compat_int_t version
;
687 compat_uint_t ncp_fd
;
688 __compat_uid_t mounted_uid
;
689 compat_pid_t wdog_pid
;
690 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
691 compat_uint_t time_out
;
692 compat_uint_t retry_count
;
696 compat_mode_t file_mode
;
697 compat_mode_t dir_mode
;
700 struct compat_ncp_mount_data_v4
{
701 compat_int_t version
;
702 compat_ulong_t flags
;
703 compat_ulong_t mounted_uid
;
704 compat_long_t wdog_pid
;
705 compat_uint_t ncp_fd
;
706 compat_uint_t time_out
;
707 compat_uint_t retry_count
;
710 compat_ulong_t file_mode
;
711 compat_ulong_t dir_mode
;
714 static void *do_ncp_super_data_conv(void *raw_data
)
716 int version
= *(unsigned int *)raw_data
;
719 struct compat_ncp_mount_data
*c_n
= raw_data
;
720 struct ncp_mount_data
*n
= raw_data
;
722 n
->dir_mode
= c_n
->dir_mode
;
723 n
->file_mode
= c_n
->file_mode
;
726 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
727 n
->wdog_pid
= c_n
->wdog_pid
;
728 n
->mounted_uid
= c_n
->mounted_uid
;
729 } else if (version
== 4) {
730 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
731 struct ncp_mount_data_v4
*n
= raw_data
;
733 n
->dir_mode
= c_n
->dir_mode
;
734 n
->file_mode
= c_n
->file_mode
;
737 n
->retry_count
= c_n
->retry_count
;
738 n
->time_out
= c_n
->time_out
;
739 n
->ncp_fd
= c_n
->ncp_fd
;
740 n
->wdog_pid
= c_n
->wdog_pid
;
741 n
->mounted_uid
= c_n
->mounted_uid
;
742 n
->flags
= c_n
->flags
;
743 } else if (version
!= 5) {
750 struct compat_smb_mount_data
{
751 compat_int_t version
;
752 __compat_uid_t mounted_uid
;
755 compat_mode_t file_mode
;
756 compat_mode_t dir_mode
;
759 static void *do_smb_super_data_conv(void *raw_data
)
761 struct smb_mount_data
*s
= raw_data
;
762 struct compat_smb_mount_data
*c_s
= raw_data
;
764 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
766 s
->dir_mode
= c_s
->dir_mode
;
767 s
->file_mode
= c_s
->file_mode
;
770 s
->mounted_uid
= c_s
->mounted_uid
;
775 struct compat_nfs_string
{
780 static inline void compat_nfs_string(struct nfs_string
*dst
,
781 struct compat_nfs_string
*src
)
783 dst
->data
= compat_ptr(src
->data
);
787 struct compat_nfs4_mount_data_v1
{
788 compat_int_t version
;
793 compat_int_t retrans
;
794 compat_int_t acregmin
;
795 compat_int_t acregmax
;
796 compat_int_t acdirmin
;
797 compat_int_t acdirmax
;
798 struct compat_nfs_string client_addr
;
799 struct compat_nfs_string mnt_path
;
800 struct compat_nfs_string hostname
;
801 compat_uint_t host_addrlen
;
802 compat_uptr_t host_addr
;
804 compat_int_t auth_flavourlen
;
805 compat_uptr_t auth_flavours
;
808 static int do_nfs4_super_data_conv(void *raw_data
)
810 int version
= *(compat_uint_t
*) raw_data
;
813 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
814 struct nfs4_mount_data
*real
= raw_data
;
816 /* copy the fields backwards */
817 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
818 real
->auth_flavourlen
= raw
->auth_flavourlen
;
819 real
->proto
= raw
->proto
;
820 real
->host_addr
= compat_ptr(raw
->host_addr
);
821 real
->host_addrlen
= raw
->host_addrlen
;
822 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
823 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
824 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
825 real
->acdirmax
= raw
->acdirmax
;
826 real
->acdirmin
= raw
->acdirmin
;
827 real
->acregmax
= raw
->acregmax
;
828 real
->acregmin
= raw
->acregmin
;
829 real
->retrans
= raw
->retrans
;
830 real
->timeo
= raw
->timeo
;
831 real
->wsize
= raw
->wsize
;
832 real
->rsize
= raw
->rsize
;
833 real
->flags
= raw
->flags
;
834 real
->version
= raw
->version
;
843 #define SMBFS_NAME "smbfs"
844 #define NCPFS_NAME "ncpfs"
845 #define NFS4_NAME "nfs4"
847 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
848 char __user
* type
, unsigned long flags
,
851 unsigned long type_page
;
852 unsigned long data_page
;
853 unsigned long dev_page
;
857 retval
= copy_mount_options (type
, &type_page
);
861 dir_page
= getname(dir_name
);
862 retval
= PTR_ERR(dir_page
);
863 if (IS_ERR(dir_page
))
866 retval
= copy_mount_options (dev_name
, &dev_page
);
870 retval
= copy_mount_options (data
, &data_page
);
876 if (type_page
&& data_page
) {
877 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
878 do_smb_super_data_conv((void *)data_page
);
879 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
880 do_ncp_super_data_conv((void *)data_page
);
881 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
882 if (do_nfs4_super_data_conv((void *) data_page
))
888 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
889 flags
, (void*)data_page
);
893 free_page(data_page
);
899 free_page(type_page
);
904 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
905 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
906 ~(sizeof(compat_long_t)-1))
908 struct compat_old_linux_dirent
{
909 compat_ulong_t d_ino
;
910 compat_ulong_t d_offset
;
911 unsigned short d_namlen
;
915 struct compat_readdir_callback
{
916 struct compat_old_linux_dirent __user
*dirent
;
920 static int compat_fillonedir(void *__buf
, const char *name
, int namlen
,
921 loff_t offset
, u64 ino
, unsigned int d_type
)
923 struct compat_readdir_callback
*buf
= __buf
;
924 struct compat_old_linux_dirent __user
*dirent
;
925 compat_ulong_t d_ino
;
930 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
933 dirent
= buf
->dirent
;
934 if (!access_ok(VERIFY_WRITE
, dirent
,
935 (unsigned long)(dirent
->d_name
+ namlen
+ 1) -
936 (unsigned long)dirent
))
938 if ( __put_user(d_ino
, &dirent
->d_ino
) ||
939 __put_user(offset
, &dirent
->d_offset
) ||
940 __put_user(namlen
, &dirent
->d_namlen
) ||
941 __copy_to_user(dirent
->d_name
, name
, namlen
) ||
942 __put_user(0, dirent
->d_name
+ namlen
))
946 buf
->result
= -EFAULT
;
950 asmlinkage
long compat_sys_old_readdir(unsigned int fd
,
951 struct compat_old_linux_dirent __user
*dirent
, unsigned int count
)
955 struct compat_readdir_callback buf
;
965 error
= vfs_readdir(file
, compat_fillonedir
, &buf
);
974 struct compat_linux_dirent
{
975 compat_ulong_t d_ino
;
976 compat_ulong_t d_off
;
977 unsigned short d_reclen
;
981 struct compat_getdents_callback
{
982 struct compat_linux_dirent __user
*current_dir
;
983 struct compat_linux_dirent __user
*previous
;
988 static int compat_filldir(void *__buf
, const char *name
, int namlen
,
989 loff_t offset
, u64 ino
, unsigned int d_type
)
991 struct compat_linux_dirent __user
* dirent
;
992 struct compat_getdents_callback
*buf
= __buf
;
993 compat_ulong_t d_ino
;
994 int reclen
= COMPAT_ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 2);
996 buf
->error
= -EINVAL
; /* only used if we fail.. */
997 if (reclen
> buf
->count
)
1000 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
1002 dirent
= buf
->previous
;
1004 if (__put_user(offset
, &dirent
->d_off
))
1007 dirent
= buf
->current_dir
;
1008 if (__put_user(d_ino
, &dirent
->d_ino
))
1010 if (__put_user(reclen
, &dirent
->d_reclen
))
1012 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1014 if (__put_user(0, dirent
->d_name
+ namlen
))
1016 if (__put_user(d_type
, (char __user
*) dirent
+ reclen
- 1))
1018 buf
->previous
= dirent
;
1019 dirent
= (void __user
*)dirent
+ reclen
;
1020 buf
->current_dir
= dirent
;
1021 buf
->count
-= reclen
;
1024 buf
->error
= -EFAULT
;
1028 asmlinkage
long compat_sys_getdents(unsigned int fd
,
1029 struct compat_linux_dirent __user
*dirent
, unsigned int count
)
1032 struct compat_linux_dirent __user
* lastdirent
;
1033 struct compat_getdents_callback buf
;
1037 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1045 buf
.current_dir
= dirent
;
1046 buf
.previous
= NULL
;
1050 error
= vfs_readdir(file
, compat_filldir
, &buf
);
1054 lastdirent
= buf
.previous
;
1056 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
1059 error
= count
- buf
.count
;
1068 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1069 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1071 struct compat_getdents_callback64
{
1072 struct linux_dirent64 __user
*current_dir
;
1073 struct linux_dirent64 __user
*previous
;
1078 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
1079 u64 ino
, unsigned int d_type
)
1081 struct linux_dirent64 __user
*dirent
;
1082 struct compat_getdents_callback64
*buf
= __buf
;
1083 int jj
= NAME_OFFSET(dirent
);
1084 int reclen
= COMPAT_ROUND_UP64(jj
+ namlen
+ 1);
1087 buf
->error
= -EINVAL
; /* only used if we fail.. */
1088 if (reclen
> buf
->count
)
1090 dirent
= buf
->previous
;
1093 if (__put_user_unaligned(offset
, &dirent
->d_off
))
1096 dirent
= buf
->current_dir
;
1097 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
1100 if (__put_user_unaligned(off
, &dirent
->d_off
))
1102 if (__put_user(reclen
, &dirent
->d_reclen
))
1104 if (__put_user(d_type
, &dirent
->d_type
))
1106 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1108 if (__put_user(0, dirent
->d_name
+ namlen
))
1110 buf
->previous
= dirent
;
1111 dirent
= (void __user
*)dirent
+ reclen
;
1112 buf
->current_dir
= dirent
;
1113 buf
->count
-= reclen
;
1116 buf
->error
= -EFAULT
;
1120 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
1121 struct linux_dirent64 __user
* dirent
, unsigned int count
)
1124 struct linux_dirent64 __user
* lastdirent
;
1125 struct compat_getdents_callback64 buf
;
1129 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1137 buf
.current_dir
= dirent
;
1138 buf
.previous
= NULL
;
1142 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1146 lastdirent
= buf
.previous
;
1148 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1150 if (__put_user_unaligned(d_off
, &lastdirent
->d_off
))
1152 error
= count
- buf
.count
;
1160 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1162 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1163 const struct compat_iovec __user
*uvector
,
1164 unsigned long nr_segs
, loff_t
*pos
)
1166 compat_ssize_t tot_len
;
1167 struct iovec iovstack
[UIO_FASTIOV
];
1168 struct iovec
*iov
=iovstack
, *vector
;
1175 * SuS says "The readv() function *may* fail if the iovcnt argument
1176 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1177 * traditionally returned zero for zero segments, so...
1184 * First get the "struct iovec" from user memory and
1185 * verify all the pointers
1188 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1192 if (nr_segs
> UIO_FASTIOV
) {
1194 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1199 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1203 * Single unix specification:
1204 * We should -EINVAL if an element length is not >= 0 and fitting an
1205 * ssize_t. The total length is fitting an ssize_t
1207 * Be careful here because iov_len is a size_t not an ssize_t
1212 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1213 compat_ssize_t tmp
= tot_len
;
1217 if (__get_user(len
, &uvector
->iov_len
) ||
1218 __get_user(buf
, &uvector
->iov_base
)) {
1222 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1225 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1227 vector
->iov_base
= compat_ptr(buf
);
1228 vector
->iov_len
= (compat_size_t
) len
;
1237 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1241 ret
= security_file_permission(file
, type
== READ
? MAY_READ
:MAY_WRITE
);
1247 fn
= file
->f_op
->read
;
1248 fnv
= file
->f_op
->aio_read
;
1250 fn
= (io_fn_t
)file
->f_op
->write
;
1251 fnv
= file
->f_op
->aio_write
;
1255 ret
= do_sync_readv_writev(file
, iov
, nr_segs
, tot_len
,
1258 ret
= do_loop_readv_writev(file
, iov
, nr_segs
, pos
, fn
);
1261 if (iov
!= iovstack
)
1263 if ((ret
+ (type
== READ
)) > 0) {
1264 struct dentry
*dentry
= file
->f_path
.dentry
;
1266 fsnotify_access(dentry
);
1268 fsnotify_modify(dentry
);
1274 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1277 ssize_t ret
= -EBADF
;
1283 if (!(file
->f_mode
& FMODE_READ
))
1287 if (!file
->f_op
|| (!file
->f_op
->aio_read
&& !file
->f_op
->read
))
1290 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1298 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1301 ssize_t ret
= -EBADF
;
1306 if (!(file
->f_mode
& FMODE_WRITE
))
1310 if (!file
->f_op
|| (!file
->f_op
->aio_write
&& !file
->f_op
->write
))
1313 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1321 compat_sys_vmsplice(int fd
, const struct compat_iovec __user
*iov32
,
1322 unsigned int nr_segs
, unsigned int flags
)
1325 struct iovec __user
*iov
;
1326 if (nr_segs
> UIO_MAXIOV
)
1328 iov
= compat_alloc_user_space(nr_segs
* sizeof(struct iovec
));
1329 for (i
= 0; i
< nr_segs
; i
++) {
1330 struct compat_iovec v
;
1331 if (get_user(v
.iov_base
, &iov32
[i
].iov_base
) ||
1332 get_user(v
.iov_len
, &iov32
[i
].iov_len
) ||
1333 put_user(compat_ptr(v
.iov_base
), &iov
[i
].iov_base
) ||
1334 put_user(v
.iov_len
, &iov
[i
].iov_len
))
1337 return sys_vmsplice(fd
, iov
, nr_segs
, flags
);
1341 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1345 compat_sys_open(const char __user
*filename
, int flags
, int mode
)
1347 return do_sys_open(AT_FDCWD
, filename
, flags
, mode
);
1351 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1355 compat_sys_openat(unsigned int dfd
, const char __user
*filename
, int flags
, int mode
)
1357 return do_sys_open(dfd
, filename
, flags
, mode
);
1361 * compat_count() counts the number of arguments/envelopes. It is basically
1362 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1363 * and envp pointers.
1365 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1373 if (get_user(p
, argv
))
1386 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1387 * except that it works with 32 bit argv and envp pointers.
1389 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1390 struct linux_binprm
*bprm
)
1392 struct page
*kmapped_page
= NULL
;
1396 while (argc
-- > 0) {
1401 if (get_user(str
, argv
+argc
) ||
1402 !(len
= strnlen_user(compat_ptr(str
), bprm
->p
))) {
1407 if (bprm
->p
< len
) {
1413 /* XXX: add architecture specific overflow check here. */
1418 int offset
, bytes_to_copy
;
1421 offset
= pos
% PAGE_SIZE
;
1423 page
= bprm
->page
[i
];
1426 page
= alloc_page(GFP_HIGHUSER
);
1427 bprm
->page
[i
] = page
;
1435 if (page
!= kmapped_page
) {
1437 kunmap(kmapped_page
);
1438 kmapped_page
= page
;
1439 kaddr
= kmap(kmapped_page
);
1442 memset(kaddr
, 0, offset
);
1443 bytes_to_copy
= PAGE_SIZE
- offset
;
1444 if (bytes_to_copy
> len
) {
1445 bytes_to_copy
= len
;
1447 memset(kaddr
+offset
+len
, 0,
1448 PAGE_SIZE
-offset
-len
);
1450 err
= copy_from_user(kaddr
+offset
, compat_ptr(str
),
1457 pos
+= bytes_to_copy
;
1458 str
+= bytes_to_copy
;
1459 len
-= bytes_to_copy
;
1465 kunmap(kmapped_page
);
1471 #define free_arg_pages(bprm) do { } while (0)
1475 static inline void free_arg_pages(struct linux_binprm
*bprm
)
1479 for (i
= 0; i
< MAX_ARG_PAGES
; i
++) {
1481 __free_page(bprm
->page
[i
]);
1482 bprm
->page
[i
] = NULL
;
1486 #endif /* CONFIG_MMU */
1489 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1490 * that it processes 32 bit argv and envp pointers.
1492 int compat_do_execve(char * filename
,
1493 compat_uptr_t __user
*argv
,
1494 compat_uptr_t __user
*envp
,
1495 struct pt_regs
* regs
)
1497 struct linux_binprm
*bprm
;
1503 bprm
= kzalloc(sizeof(*bprm
), GFP_KERNEL
);
1507 file
= open_exec(filename
);
1508 retval
= PTR_ERR(file
);
1514 bprm
->p
= PAGE_SIZE
*MAX_ARG_PAGES
-sizeof(void *);
1516 bprm
->filename
= filename
;
1517 bprm
->interp
= filename
;
1518 bprm
->mm
= mm_alloc();
1523 retval
= init_new_context(current
, bprm
->mm
);
1527 bprm
->argc
= compat_count(argv
, bprm
->p
/ sizeof(compat_uptr_t
));
1528 if ((retval
= bprm
->argc
) < 0)
1531 bprm
->envc
= compat_count(envp
, bprm
->p
/ sizeof(compat_uptr_t
));
1532 if ((retval
= bprm
->envc
) < 0)
1535 retval
= security_bprm_alloc(bprm
);
1539 retval
= prepare_binprm(bprm
);
1543 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1547 bprm
->exec
= bprm
->p
;
1548 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1552 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1556 retval
= search_binary_handler(bprm
, regs
);
1558 free_arg_pages(bprm
);
1560 /* execve success */
1561 security_bprm_free(bprm
);
1562 acct_update_integrals(current
);
1568 /* Something went wrong, return the inode and free the argument pages*/
1569 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
1570 struct page
* page
= bprm
->page
[i
];
1576 security_bprm_free(bprm
);
1584 allow_write_access(bprm
->file
);
1595 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1597 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1600 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1601 * 64-bit unsigned longs.
1604 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1605 unsigned long *fdset
)
1607 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1611 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1618 if (__get_user(l
, ufdset
) || __get_user(h
, ufdset
+1))
1621 *fdset
++ = h
<< 32 | l
;
1624 if (odd
&& __get_user(*fdset
, ufdset
))
1627 /* Tricky, must clear full unsigned long in the
1628 * kernel fdset at the end, this makes sure that
1631 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1637 int compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1638 unsigned long *fdset
)
1641 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1652 if (__put_user(l
, ufdset
) || __put_user(h
, ufdset
+1))
1657 if (odd
&& __put_user(*fdset
, ufdset
))
1664 * This is a virtual copy of sys_select from fs/select.c and probably
1665 * should be compared to it from time to time
1669 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1670 * like to be certain this leads to no problems. So I return
1671 * EINTR just for safety.
1673 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1674 * I'm trying ERESTARTNOHAND which restart only when you want to.
1676 #define MAX_SELECT_SECONDS \
1677 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1679 int compat_core_sys_select(int n
, compat_ulong_t __user
*inp
,
1680 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
, s64
*timeout
)
1684 int size
, max_fds
, ret
= -EINVAL
;
1685 struct fdtable
*fdt
;
1690 /* max_fds can increase, so grab it once to avoid race */
1692 fdt
= files_fdtable(current
->files
);
1693 max_fds
= fdt
->max_fds
;
1699 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1700 * since we used fdset we need to allocate memory in units of
1704 size
= FDS_BYTES(n
);
1705 bits
= kmalloc(6 * size
, GFP_KERNEL
);
1708 fds
.in
= (unsigned long *) bits
;
1709 fds
.out
= (unsigned long *) (bits
+ size
);
1710 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1711 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1712 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1713 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1715 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1716 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1717 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1719 zero_fd_set(n
, fds
.res_in
);
1720 zero_fd_set(n
, fds
.res_out
);
1721 zero_fd_set(n
, fds
.res_ex
);
1723 ret
= do_select(n
, &fds
, timeout
);
1728 ret
= -ERESTARTNOHAND
;
1729 if (signal_pending(current
))
1734 if (compat_set_fd_set(n
, inp
, fds
.res_in
) ||
1735 compat_set_fd_set(n
, outp
, fds
.res_out
) ||
1736 compat_set_fd_set(n
, exp
, fds
.res_ex
))
1744 asmlinkage
long compat_sys_select(int n
, compat_ulong_t __user
*inp
,
1745 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1746 struct compat_timeval __user
*tvp
)
1749 struct compat_timeval tv
;
1753 if (copy_from_user(&tv
, tvp
, sizeof(tv
)))
1756 if (tv
.tv_sec
< 0 || tv
.tv_usec
< 0)
1759 /* Cast to u64 to make GCC stop complaining */
1760 if ((u64
)tv
.tv_sec
>= (u64
)MAX_INT64_SECONDS
)
1761 timeout
= -1; /* infinite */
1763 timeout
= ROUND_UP(tv
.tv_usec
, 1000000/HZ
);
1764 timeout
+= tv
.tv_sec
* HZ
;
1768 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1771 struct compat_timeval rtv
;
1773 if (current
->personality
& STICKY_TIMEOUTS
)
1775 rtv
.tv_usec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
));
1776 rtv
.tv_sec
= timeout
;
1777 if (compat_timeval_compare(&rtv
, &tv
) >= 0)
1779 if (copy_to_user(tvp
, &rtv
, sizeof(rtv
))) {
1782 * If an application puts its timeval in read-only
1783 * memory, we don't want the Linux-specific update to
1784 * the timeval to cause a fault after the select has
1785 * completed successfully. However, because we're not
1786 * updating the timeval, we can't restart the system
1789 if (ret
== -ERESTARTNOHAND
)
1797 #ifdef TIF_RESTORE_SIGMASK
1798 asmlinkage
long compat_sys_pselect7(int n
, compat_ulong_t __user
*inp
,
1799 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1800 struct compat_timespec __user
*tsp
, compat_sigset_t __user
*sigmask
,
1801 compat_size_t sigsetsize
)
1803 compat_sigset_t ss32
;
1804 sigset_t ksigmask
, sigsaved
;
1805 s64 timeout
= MAX_SCHEDULE_TIMEOUT
;
1806 struct compat_timespec ts
;
1810 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1813 if (ts
.tv_sec
< 0 || ts
.tv_nsec
< 0)
1818 if (sigsetsize
!= sizeof(compat_sigset_t
))
1820 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1822 sigset_from_compat(&ksigmask
, &ss32
);
1824 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1825 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1830 if ((unsigned long)ts
.tv_sec
< MAX_SELECT_SECONDS
) {
1831 timeout
= ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1832 timeout
+= ts
.tv_sec
* (unsigned long)HZ
;
1836 ts
.tv_sec
-= MAX_SELECT_SECONDS
;
1837 timeout
= MAX_SELECT_SECONDS
* HZ
;
1841 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1843 } while (!ret
&& !timeout
&& tsp
&& (ts
.tv_sec
|| ts
.tv_nsec
));
1846 struct compat_timespec rts
;
1848 if (current
->personality
& STICKY_TIMEOUTS
)
1851 rts
.tv_sec
= timeout
/ HZ
;
1852 rts
.tv_nsec
= (timeout
% HZ
) * (NSEC_PER_SEC
/HZ
);
1853 if (rts
.tv_nsec
>= NSEC_PER_SEC
) {
1855 rts
.tv_nsec
-= NSEC_PER_SEC
;
1857 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1859 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1862 * If an application puts its timeval in read-only
1863 * memory, we don't want the Linux-specific update to
1864 * the timeval to cause a fault after the select has
1865 * completed successfully. However, because we're not
1866 * updating the timeval, we can't restart the system
1869 if (ret
== -ERESTARTNOHAND
)
1874 if (ret
== -ERESTARTNOHAND
) {
1876 * Don't restore the signal mask yet. Let do_signal() deliver
1877 * the signal on the way back to userspace, before the signal
1881 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1883 set_thread_flag(TIF_RESTORE_SIGMASK
);
1886 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1891 asmlinkage
long compat_sys_pselect6(int n
, compat_ulong_t __user
*inp
,
1892 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1893 struct compat_timespec __user
*tsp
, void __user
*sig
)
1895 compat_size_t sigsetsize
= 0;
1896 compat_uptr_t up
= 0;
1899 if (!access_ok(VERIFY_READ
, sig
,
1900 sizeof(compat_uptr_t
)+sizeof(compat_size_t
)) ||
1901 __get_user(up
, (compat_uptr_t __user
*)sig
) ||
1902 __get_user(sigsetsize
,
1903 (compat_size_t __user
*)(sig
+sizeof(up
))))
1906 return compat_sys_pselect7(n
, inp
, outp
, exp
, tsp
, compat_ptr(up
),
1910 asmlinkage
long compat_sys_ppoll(struct pollfd __user
*ufds
,
1911 unsigned int nfds
, struct compat_timespec __user
*tsp
,
1912 const compat_sigset_t __user
*sigmask
, compat_size_t sigsetsize
)
1914 compat_sigset_t ss32
;
1915 sigset_t ksigmask
, sigsaved
;
1916 struct compat_timespec ts
;
1921 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1924 /* We assume that ts.tv_sec is always lower than
1925 the number of seconds that can be expressed in
1926 an s64. Otherwise the compiler bitches at us */
1927 timeout
= ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1928 timeout
+= ts
.tv_sec
* HZ
;
1932 if (sigsetsize
!= sizeof(compat_sigset_t
))
1934 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1936 sigset_from_compat(&ksigmask
, &ss32
);
1938 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1939 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1942 ret
= do_sys_poll(ufds
, nfds
, &timeout
);
1944 /* We can restart this syscall, usually */
1945 if (ret
== -EINTR
) {
1947 * Don't restore the signal mask yet. Let do_signal() deliver
1948 * the signal on the way back to userspace, before the signal
1952 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1954 set_thread_flag(TIF_RESTORE_SIGMASK
);
1956 ret
= -ERESTARTNOHAND
;
1958 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1960 if (tsp
&& timeout
>= 0) {
1961 struct compat_timespec rts
;
1963 if (current
->personality
& STICKY_TIMEOUTS
)
1965 /* Yes, we know it's actually an s64, but it's also positive. */
1966 rts
.tv_nsec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
)) *
1968 rts
.tv_sec
= timeout
;
1969 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1971 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1974 * If an application puts its timeval in read-only
1975 * memory, we don't want the Linux-specific update to
1976 * the timeval to cause a fault after the select has
1977 * completed successfully. However, because we're not
1978 * updating the timeval, we can't restart the system
1981 if (ret
== -ERESTARTNOHAND
&& timeout
>= 0)
1988 #endif /* TIF_RESTORE_SIGMASK */
1990 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1991 /* Stuff for NFS server syscalls... */
1992 struct compat_nfsctl_svc
{
1997 struct compat_nfsctl_client
{
1998 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
2000 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
2003 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
2006 struct compat_nfsctl_export
{
2007 char ex32_client
[NFSCLNT_IDMAX
+1];
2008 char ex32_path
[NFS_MAXPATHLEN
+1];
2009 compat_dev_t ex32_dev
;
2010 compat_ino_t ex32_ino
;
2011 compat_int_t ex32_flags
;
2012 __compat_uid_t ex32_anon_uid
;
2013 __compat_gid_t ex32_anon_gid
;
2016 struct compat_nfsctl_fdparm
{
2017 struct sockaddr gd32_addr
;
2018 s8 gd32_path
[NFS_MAXPATHLEN
+1];
2019 compat_int_t gd32_version
;
2022 struct compat_nfsctl_fsparm
{
2023 struct sockaddr gd32_addr
;
2024 s8 gd32_path
[NFS_MAXPATHLEN
+1];
2025 compat_int_t gd32_maxlen
;
2028 struct compat_nfsctl_arg
{
2029 compat_int_t ca32_version
; /* safeguard */
2031 struct compat_nfsctl_svc u32_svc
;
2032 struct compat_nfsctl_client u32_client
;
2033 struct compat_nfsctl_export u32_export
;
2034 struct compat_nfsctl_fdparm u32_getfd
;
2035 struct compat_nfsctl_fsparm u32_getfs
;
2037 #define ca32_svc u.u32_svc
2038 #define ca32_client u.u32_client
2039 #define ca32_export u.u32_export
2040 #define ca32_getfd u.u32_getfd
2041 #define ca32_getfs u.u32_getfs
2044 union compat_nfsctl_res
{
2045 __u8 cr32_getfh
[NFS_FHSIZE
];
2046 struct knfsd_fh cr32_getfs
;
2049 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
,
2050 struct compat_nfsctl_arg __user
*arg
)
2052 if (!access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
)) ||
2053 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2054 __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
) ||
2055 __get_user(karg
->ca_svc
.svc_nthreads
,
2056 &arg
->ca32_svc
.svc32_nthreads
))
2061 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
,
2062 struct compat_nfsctl_arg __user
*arg
)
2064 if (!access_ok(VERIFY_READ
, &arg
->ca32_client
,
2065 sizeof(arg
->ca32_client
)) ||
2066 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2067 __copy_from_user(&karg
->ca_client
.cl_ident
[0],
2068 &arg
->ca32_client
.cl32_ident
[0],
2070 __get_user(karg
->ca_client
.cl_naddr
,
2071 &arg
->ca32_client
.cl32_naddr
) ||
2072 __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
2073 &arg
->ca32_client
.cl32_addrlist
[0],
2074 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
)) ||
2075 __get_user(karg
->ca_client
.cl_fhkeytype
,
2076 &arg
->ca32_client
.cl32_fhkeytype
) ||
2077 __get_user(karg
->ca_client
.cl_fhkeylen
,
2078 &arg
->ca32_client
.cl32_fhkeylen
) ||
2079 __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
2080 &arg
->ca32_client
.cl32_fhkey
[0],
2087 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
,
2088 struct compat_nfsctl_arg __user
*arg
)
2090 if (!access_ok(VERIFY_READ
, &arg
->ca32_export
,
2091 sizeof(arg
->ca32_export
)) ||
2092 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2093 __copy_from_user(&karg
->ca_export
.ex_client
[0],
2094 &arg
->ca32_export
.ex32_client
[0],
2096 __copy_from_user(&karg
->ca_export
.ex_path
[0],
2097 &arg
->ca32_export
.ex32_path
[0],
2099 __get_user(karg
->ca_export
.ex_dev
,
2100 &arg
->ca32_export
.ex32_dev
) ||
2101 __get_user(karg
->ca_export
.ex_ino
,
2102 &arg
->ca32_export
.ex32_ino
) ||
2103 __get_user(karg
->ca_export
.ex_flags
,
2104 &arg
->ca32_export
.ex32_flags
) ||
2105 __get_user(karg
->ca_export
.ex_anon_uid
,
2106 &arg
->ca32_export
.ex32_anon_uid
) ||
2107 __get_user(karg
->ca_export
.ex_anon_gid
,
2108 &arg
->ca32_export
.ex32_anon_gid
))
2110 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
2111 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
2116 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
,
2117 struct compat_nfsctl_arg __user
*arg
)
2119 if (!access_ok(VERIFY_READ
, &arg
->ca32_getfd
,
2120 sizeof(arg
->ca32_getfd
)) ||
2121 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2122 __copy_from_user(&karg
->ca_getfd
.gd_addr
,
2123 &arg
->ca32_getfd
.gd32_addr
,
2124 (sizeof(struct sockaddr
))) ||
2125 __copy_from_user(&karg
->ca_getfd
.gd_path
,
2126 &arg
->ca32_getfd
.gd32_path
,
2127 (NFS_MAXPATHLEN
+1)) ||
2128 __get_user(karg
->ca_getfd
.gd_version
,
2129 &arg
->ca32_getfd
.gd32_version
))
2135 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
,
2136 struct compat_nfsctl_arg __user
*arg
)
2138 if (!access_ok(VERIFY_READ
,&arg
->ca32_getfs
,sizeof(arg
->ca32_getfs
)) ||
2139 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2140 __copy_from_user(&karg
->ca_getfs
.gd_addr
,
2141 &arg
->ca32_getfs
.gd32_addr
,
2142 (sizeof(struct sockaddr
))) ||
2143 __copy_from_user(&karg
->ca_getfs
.gd_path
,
2144 &arg
->ca32_getfs
.gd32_path
,
2145 (NFS_MAXPATHLEN
+1)) ||
2146 __get_user(karg
->ca_getfs
.gd_maxlen
,
2147 &arg
->ca32_getfs
.gd32_maxlen
))
2153 /* This really doesn't need translations, we are only passing
2154 * back a union which contains opaque nfs file handle data.
2156 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
,
2157 union compat_nfsctl_res __user
*res
)
2161 err
= copy_to_user(res
, kres
, sizeof(*res
));
2163 return (err
) ? -EFAULT
: 0;
2166 asmlinkage
long compat_sys_nfsservctl(int cmd
,
2167 struct compat_nfsctl_arg __user
*arg
,
2168 union compat_nfsctl_res __user
*res
)
2170 struct nfsctl_arg
*karg
;
2171 union nfsctl_res
*kres
;
2175 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
2176 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
2177 if(!karg
|| !kres
) {
2184 err
= compat_nfs_svc_trans(karg
, arg
);
2187 case NFSCTL_ADDCLIENT
:
2188 err
= compat_nfs_clnt_trans(karg
, arg
);
2191 case NFSCTL_DELCLIENT
:
2192 err
= compat_nfs_clnt_trans(karg
, arg
);
2196 case NFSCTL_UNEXPORT
:
2197 err
= compat_nfs_exp_trans(karg
, arg
);
2201 err
= compat_nfs_getfd_trans(karg
, arg
);
2205 err
= compat_nfs_getfs_trans(karg
, arg
);
2218 /* The __user pointer casts are valid because of the set_fs() */
2219 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
2225 if((cmd
== NFSCTL_GETFD
) ||
2226 (cmd
== NFSCTL_GETFS
))
2227 err
= compat_nfs_getfh_res_trans(kres
, res
);
2235 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
2237 return sys_ni_syscall();
2243 #ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
2244 asmlinkage
long compat_sys_epoll_ctl(int epfd
, int op
, int fd
,
2245 struct compat_epoll_event __user
*event
)
2248 struct compat_epoll_event user
;
2249 struct epoll_event __user
*kernel
= NULL
;
2252 if (copy_from_user(&user
, event
, sizeof(user
)))
2254 kernel
= compat_alloc_user_space(sizeof(struct epoll_event
));
2255 err
|= __put_user(user
.events
, &kernel
->events
);
2256 err
|= __put_user(user
.data
, &kernel
->data
);
2259 return err
? err
: sys_epoll_ctl(epfd
, op
, fd
, kernel
);
2263 asmlinkage
long compat_sys_epoll_wait(int epfd
,
2264 struct compat_epoll_event __user
*events
,
2265 int maxevents
, int timeout
)
2267 long i
, ret
, err
= 0;
2268 struct epoll_event __user
*kbuf
;
2269 struct epoll_event ev
;
2271 if ((maxevents
<= 0) ||
2272 (maxevents
> (INT_MAX
/ sizeof(struct epoll_event
))))
2274 kbuf
= compat_alloc_user_space(sizeof(struct epoll_event
) * maxevents
);
2275 ret
= sys_epoll_wait(epfd
, kbuf
, maxevents
, timeout
);
2276 for (i
= 0; i
< ret
; i
++) {
2277 err
|= __get_user(ev
.events
, &kbuf
[i
].events
);
2278 err
|= __get_user(ev
.data
, &kbuf
[i
].data
);
2279 err
|= __put_user(ev
.events
, &events
->events
);
2280 err
|= __put_user_unaligned(ev
.data
, &events
->data
);
2284 return err
? -EFAULT
: ret
;
2286 #endif /* CONFIG_HAS_COMPAT_EPOLL_EVENT */
2288 #ifdef TIF_RESTORE_SIGMASK
2289 asmlinkage
long compat_sys_epoll_pwait(int epfd
,
2290 struct compat_epoll_event __user
*events
,
2291 int maxevents
, int timeout
,
2292 const compat_sigset_t __user
*sigmask
,
2293 compat_size_t sigsetsize
)
2296 compat_sigset_t csigmask
;
2297 sigset_t ksigmask
, sigsaved
;
2300 * If the caller wants a certain signal mask to be set during the wait,
2304 if (sigsetsize
!= sizeof(compat_sigset_t
))
2306 if (copy_from_user(&csigmask
, sigmask
, sizeof(csigmask
)))
2308 sigset_from_compat(&ksigmask
, &csigmask
);
2309 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
) | sigmask(SIGSTOP
));
2310 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
2313 #ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
2314 err
= compat_sys_epoll_wait(epfd
, events
, maxevents
, timeout
);
2316 err
= sys_epoll_wait(epfd
, events
, maxevents
, timeout
);
2320 * If we changed the signal mask, we need to restore the original one.
2321 * In case we've got a signal while waiting, we do not restore the
2322 * signal mask yet, and we allow do_signal() to deliver the signal on
2323 * the way back to userspace, before the signal mask is restored.
2326 if (err
== -EINTR
) {
2327 memcpy(¤t
->saved_sigmask
, &sigsaved
,
2329 set_thread_flag(TIF_RESTORE_SIGMASK
);
2331 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
2336 #endif /* TIF_RESTORE_SIGMASK */
2338 #endif /* CONFIG_EPOLL */