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/kernel.h>
19 #include <linux/linkage.h>
20 #include <linux/compat.h>
21 #include <linux/errno.h>
22 #include <linux/time.h>
24 #include <linux/fcntl.h>
25 #include <linux/namei.h>
26 #include <linux/file.h>
27 #include <linux/vfs.h>
28 #include <linux/ioctl32.h>
29 #include <linux/ioctl.h>
30 #include <linux/init.h>
31 #include <linux/sockios.h> /* for SIOCDEVPRIVATE */
32 #include <linux/smb.h>
33 #include <linux/smb_mount.h>
34 #include <linux/ncp_mount.h>
35 #include <linux/nfs4_mount.h>
36 #include <linux/smp_lock.h>
37 #include <linux/syscalls.h>
38 #include <linux/ctype.h>
39 #include <linux/module.h>
40 #include <linux/dirent.h>
41 #include <linux/fsnotify.h>
42 #include <linux/highuid.h>
43 #include <linux/sunrpc/svc.h>
44 #include <linux/nfsd/nfsd.h>
45 #include <linux/nfsd/syscall.h>
46 #include <linux/personality.h>
47 #include <linux/rwsem.h>
48 #include <linux/tsacct_kern.h>
49 #include <linux/highmem.h>
50 #include <linux/poll.h>
52 #include <linux/eventpoll.h>
54 #include <net/sock.h> /* siocdevprivate_ioctl */
56 #include <asm/uaccess.h>
57 #include <asm/mmu_context.h>
58 #include <asm/ioctls.h>
63 int compat_printk(const char *fmt
, ...)
70 ret
= vprintk(fmt
, ap
);
75 #include "read_write.h"
78 * Not all architectures have sys_utime, so implement this in terms
81 asmlinkage
long compat_sys_utime(char __user
*filename
, struct compat_utimbuf __user
*t
)
86 if (get_user(tv
[0].tv_sec
, &t
->actime
) ||
87 get_user(tv
[1].tv_sec
, &t
->modtime
))
92 return do_utimes(AT_FDCWD
, filename
, t
? tv
: NULL
);
95 asmlinkage
long compat_sys_futimesat(unsigned int dfd
, char __user
*filename
, struct compat_timeval __user
*t
)
100 if (get_user(tv
[0].tv_sec
, &t
[0].tv_sec
) ||
101 get_user(tv
[0].tv_usec
, &t
[0].tv_usec
) ||
102 get_user(tv
[1].tv_sec
, &t
[1].tv_sec
) ||
103 get_user(tv
[1].tv_usec
, &t
[1].tv_usec
))
106 return do_utimes(dfd
, filename
, t
? tv
: NULL
);
109 asmlinkage
long compat_sys_utimes(char __user
*filename
, struct compat_timeval __user
*t
)
111 return compat_sys_futimesat(AT_FDCWD
, filename
, t
);
114 asmlinkage
long compat_sys_newstat(char __user
* filename
,
115 struct compat_stat __user
*statbuf
)
118 int error
= vfs_stat_fd(AT_FDCWD
, filename
, &stat
);
121 error
= cp_compat_stat(&stat
, statbuf
);
125 asmlinkage
long compat_sys_newlstat(char __user
* filename
,
126 struct compat_stat __user
*statbuf
)
129 int error
= vfs_lstat_fd(AT_FDCWD
, filename
, &stat
);
132 error
= cp_compat_stat(&stat
, statbuf
);
136 #ifndef __ARCH_WANT_STAT64
137 asmlinkage
long compat_sys_newfstatat(unsigned int dfd
, char __user
*filename
,
138 struct compat_stat __user
*statbuf
, int flag
)
143 if ((flag
& ~AT_SYMLINK_NOFOLLOW
) != 0)
146 if (flag
& AT_SYMLINK_NOFOLLOW
)
147 error
= vfs_lstat_fd(dfd
, filename
, &stat
);
149 error
= vfs_stat_fd(dfd
, filename
, &stat
);
152 error
= cp_compat_stat(&stat
, statbuf
);
159 asmlinkage
long compat_sys_newfstat(unsigned int fd
,
160 struct compat_stat __user
* statbuf
)
163 int error
= vfs_fstat(fd
, &stat
);
166 error
= cp_compat_stat(&stat
, statbuf
);
170 static int put_compat_statfs(struct compat_statfs __user
*ubuf
, struct kstatfs
*kbuf
)
173 if (sizeof ubuf
->f_blocks
== 4) {
174 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
175 0xffffffff00000000ULL
)
177 /* f_files and f_ffree may be -1; it's okay
178 * to stuff that into 32 bits */
179 if (kbuf
->f_files
!= 0xffffffffffffffffULL
180 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
182 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
183 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
186 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
187 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
188 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
189 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
190 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
191 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
192 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
193 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
194 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
195 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
196 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
197 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
) ||
198 __put_user(0, &ubuf
->f_spare
[0]) ||
199 __put_user(0, &ubuf
->f_spare
[1]) ||
200 __put_user(0, &ubuf
->f_spare
[2]) ||
201 __put_user(0, &ubuf
->f_spare
[3]) ||
202 __put_user(0, &ubuf
->f_spare
[4]))
208 * The following statfs calls are copies of code from fs/open.c and
209 * should be checked against those from time to time
211 asmlinkage
long compat_sys_statfs(const char __user
*path
, struct compat_statfs __user
*buf
)
216 error
= user_path_walk(path
, &nd
);
219 error
= vfs_statfs(nd
.dentry
, &tmp
);
221 error
= put_compat_statfs(buf
, &tmp
);
227 asmlinkage
long compat_sys_fstatfs(unsigned int fd
, struct compat_statfs __user
*buf
)
237 error
= vfs_statfs(file
->f_path
.dentry
, &tmp
);
239 error
= put_compat_statfs(buf
, &tmp
);
245 static int put_compat_statfs64(struct compat_statfs64 __user
*ubuf
, struct kstatfs
*kbuf
)
247 if (sizeof ubuf
->f_blocks
== 4) {
248 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
249 0xffffffff00000000ULL
)
251 /* f_files and f_ffree may be -1; it's okay
252 * to stuff that into 32 bits */
253 if (kbuf
->f_files
!= 0xffffffffffffffffULL
254 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
256 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
257 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
260 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
261 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
262 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
263 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
264 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
265 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
266 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
267 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
268 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
269 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
270 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
271 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
))
276 asmlinkage
long compat_sys_statfs64(const char __user
*path
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
281 if (sz
!= sizeof(*buf
))
284 error
= user_path_walk(path
, &nd
);
287 error
= vfs_statfs(nd
.dentry
, &tmp
);
289 error
= put_compat_statfs64(buf
, &tmp
);
295 asmlinkage
long compat_sys_fstatfs64(unsigned int fd
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
301 if (sz
!= sizeof(*buf
))
308 error
= vfs_statfs(file
->f_path
.dentry
, &tmp
);
310 error
= put_compat_statfs64(buf
, &tmp
);
316 /* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */
318 #define IOCTL_HASHSIZE 256
319 static struct ioctl_trans
*ioctl32_hash_table
[IOCTL_HASHSIZE
];
321 static inline unsigned long ioctl32_hash(unsigned long cmd
)
323 return (((cmd
>> 6) ^ (cmd
>> 4) ^ cmd
)) % IOCTL_HASHSIZE
;
326 static void ioctl32_insert_translation(struct ioctl_trans
*trans
)
329 struct ioctl_trans
*t
;
331 hash
= ioctl32_hash (trans
->cmd
);
332 if (!ioctl32_hash_table
[hash
])
333 ioctl32_hash_table
[hash
] = trans
;
335 t
= ioctl32_hash_table
[hash
];
343 static int __init
init_sys32_ioctl(void)
347 for (i
= 0; i
< ioctl_table_size
; i
++) {
348 if (ioctl_start
[i
].next
!= 0) {
349 printk("ioctl translation %d bad\n",i
);
353 ioctl32_insert_translation(&ioctl_start
[i
]);
358 __initcall(init_sys32_ioctl
);
360 static void compat_ioctl_error(struct file
*filp
, unsigned int fd
,
361 unsigned int cmd
, unsigned long arg
)
367 /* find the name of the device. */
368 path
= (char *)__get_free_page(GFP_KERNEL
);
370 fn
= d_path(filp
->f_path
.dentry
, filp
->f_path
.mnt
, path
, PAGE_SIZE
);
375 sprintf(buf
,"'%c'", (cmd
>>_IOC_TYPESHIFT
) & _IOC_TYPEMASK
);
376 if (!isprint(buf
[1]))
377 sprintf(buf
, "%02x", buf
[1]);
378 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
379 "cmd(%08x){t:%s;sz:%u} arg(%08x) on %s\n",
380 current
->comm
, current
->pid
,
381 (int)fd
, (unsigned int)cmd
, buf
,
382 (cmd
>> _IOC_SIZESHIFT
) & _IOC_SIZEMASK
,
383 (unsigned int)arg
, fn
);
386 free_page((unsigned long)path
);
389 asmlinkage
long compat_sys_ioctl(unsigned int fd
, unsigned int cmd
,
394 struct ioctl_trans
*t
;
397 filp
= fget_light(fd
, &fput_needed
);
401 /* RED-PEN how should LSM module know it's handling 32bit? */
402 error
= security_file_ioctl(filp
, cmd
, arg
);
407 * To allow the compat_ioctl handlers to be self contained
408 * we need to check the common ioctls here first.
409 * Just handle them with the standard handlers below.
422 if (S_ISREG(filp
->f_path
.dentry
->d_inode
->i_mode
))
427 if (filp
->f_op
&& filp
->f_op
->compat_ioctl
) {
428 error
= filp
->f_op
->compat_ioctl(filp
, cmd
, arg
);
429 if (error
!= -ENOIOCTLCMD
)
434 (!filp
->f_op
->ioctl
&& !filp
->f_op
->unlocked_ioctl
))
439 for (t
= ioctl32_hash_table
[ioctl32_hash(cmd
)]; t
; t
= t
->next
) {
444 if (S_ISSOCK(filp
->f_path
.dentry
->d_inode
->i_mode
) &&
445 cmd
>= SIOCDEVPRIVATE
&& cmd
<= (SIOCDEVPRIVATE
+ 15)) {
446 error
= siocdevprivate_ioctl(fd
, cmd
, arg
);
451 compat_ioctl_error(filp
, fd
, cmd
, arg
);
460 error
= t
->handler(fd
, cmd
, arg
, filp
);
466 error
= vfs_ioctl(filp
, fd
, cmd
, arg
);
468 fput_light(filp
, fput_needed
);
473 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
475 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
476 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
477 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
478 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
479 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
480 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
485 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
487 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
488 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
489 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
490 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
491 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
492 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
497 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
498 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
500 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
501 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
502 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
503 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
504 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
505 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
511 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
512 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
514 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
515 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
516 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
517 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
518 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
519 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
525 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
536 ret
= get_compat_flock(&f
, compat_ptr(arg
));
541 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
543 if (cmd
== F_GETLK
&& ret
== 0) {
544 /* GETLK was successfule and we need to return the data...
545 * but it needs to fit in the compat structure.
546 * l_start shouldn't be too big, unless the original
547 * start + end is greater than COMPAT_OFF_T_MAX, in which
548 * case the app was asking for trouble, so we return
549 * -EOVERFLOW in that case.
550 * l_len could be too big, in which case we just truncate it,
551 * and only allow the app to see that part of the conflicting
552 * lock that might make sense to it anyway
555 if (f
.l_start
> COMPAT_OFF_T_MAX
)
557 if (f
.l_len
> COMPAT_OFF_T_MAX
)
558 f
.l_len
= COMPAT_OFF_T_MAX
;
560 ret
= put_compat_flock(&f
, compat_ptr(arg
));
567 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
572 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
573 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
576 if (cmd
== F_GETLK64
&& ret
== 0) {
577 /* need to return lock information - see above for commentary */
578 if (f
.l_start
> COMPAT_LOFF_T_MAX
)
580 if (f
.l_len
> COMPAT_LOFF_T_MAX
)
581 f
.l_len
= COMPAT_LOFF_T_MAX
;
583 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
588 ret
= sys_fcntl(fd
, cmd
, arg
);
594 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
597 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
599 return compat_sys_fcntl64(fd
, cmd
, arg
);
603 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
608 mm_segment_t oldfs
= get_fs();
609 if (unlikely(get_user(ctx64
, ctx32p
)))
613 /* The __user pointer cast is valid because of the set_fs() */
614 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
616 /* truncating is ok because it's a user address */
618 ret
= put_user((u32
) ctx64
, ctx32p
);
623 compat_sys_io_getevents(aio_context_t ctx_id
,
624 unsigned long min_nr
,
626 struct io_event __user
*events
,
627 struct compat_timespec __user
*timeout
)
631 struct timespec __user
*ut
= NULL
;
634 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
635 nr
* sizeof(struct io_event
))))
638 if (get_compat_timespec(&t
, timeout
))
641 ut
= compat_alloc_user_space(sizeof(*ut
));
642 if (copy_to_user(ut
, &t
, sizeof(t
)) )
645 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
651 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
656 for (i
= 0; i
< nr
; ++i
) {
657 if (get_user(uptr
, ptr32
+ i
))
659 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
665 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
668 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
670 struct iocb __user
* __user
*iocb64
;
673 if (unlikely(nr
< 0))
676 if (nr
> MAX_AIO_SUBMITS
)
677 nr
= MAX_AIO_SUBMITS
;
679 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
680 ret
= copy_iocb(nr
, iocb
, iocb64
);
682 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
686 struct compat_ncp_mount_data
{
687 compat_int_t version
;
688 compat_uint_t ncp_fd
;
689 __compat_uid_t mounted_uid
;
690 compat_pid_t wdog_pid
;
691 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
692 compat_uint_t time_out
;
693 compat_uint_t retry_count
;
697 compat_mode_t file_mode
;
698 compat_mode_t dir_mode
;
701 struct compat_ncp_mount_data_v4
{
702 compat_int_t version
;
703 compat_ulong_t flags
;
704 compat_ulong_t mounted_uid
;
705 compat_long_t wdog_pid
;
706 compat_uint_t ncp_fd
;
707 compat_uint_t time_out
;
708 compat_uint_t retry_count
;
711 compat_ulong_t file_mode
;
712 compat_ulong_t dir_mode
;
715 static void *do_ncp_super_data_conv(void *raw_data
)
717 int version
= *(unsigned int *)raw_data
;
720 struct compat_ncp_mount_data
*c_n
= raw_data
;
721 struct ncp_mount_data
*n
= raw_data
;
723 n
->dir_mode
= c_n
->dir_mode
;
724 n
->file_mode
= c_n
->file_mode
;
727 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
728 n
->wdog_pid
= c_n
->wdog_pid
;
729 n
->mounted_uid
= c_n
->mounted_uid
;
730 } else if (version
== 4) {
731 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
732 struct ncp_mount_data_v4
*n
= raw_data
;
734 n
->dir_mode
= c_n
->dir_mode
;
735 n
->file_mode
= c_n
->file_mode
;
738 n
->retry_count
= c_n
->retry_count
;
739 n
->time_out
= c_n
->time_out
;
740 n
->ncp_fd
= c_n
->ncp_fd
;
741 n
->wdog_pid
= c_n
->wdog_pid
;
742 n
->mounted_uid
= c_n
->mounted_uid
;
743 n
->flags
= c_n
->flags
;
744 } else if (version
!= 5) {
751 struct compat_smb_mount_data
{
752 compat_int_t version
;
753 __compat_uid_t mounted_uid
;
756 compat_mode_t file_mode
;
757 compat_mode_t dir_mode
;
760 static void *do_smb_super_data_conv(void *raw_data
)
762 struct smb_mount_data
*s
= raw_data
;
763 struct compat_smb_mount_data
*c_s
= raw_data
;
765 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
767 s
->dir_mode
= c_s
->dir_mode
;
768 s
->file_mode
= c_s
->file_mode
;
771 s
->mounted_uid
= c_s
->mounted_uid
;
776 struct compat_nfs_string
{
781 static inline void compat_nfs_string(struct nfs_string
*dst
,
782 struct compat_nfs_string
*src
)
784 dst
->data
= compat_ptr(src
->data
);
788 struct compat_nfs4_mount_data_v1
{
789 compat_int_t version
;
794 compat_int_t retrans
;
795 compat_int_t acregmin
;
796 compat_int_t acregmax
;
797 compat_int_t acdirmin
;
798 compat_int_t acdirmax
;
799 struct compat_nfs_string client_addr
;
800 struct compat_nfs_string mnt_path
;
801 struct compat_nfs_string hostname
;
802 compat_uint_t host_addrlen
;
803 compat_uptr_t host_addr
;
805 compat_int_t auth_flavourlen
;
806 compat_uptr_t auth_flavours
;
809 static int do_nfs4_super_data_conv(void *raw_data
)
811 int version
= *(compat_uint_t
*) raw_data
;
814 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
815 struct nfs4_mount_data
*real
= raw_data
;
817 /* copy the fields backwards */
818 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
819 real
->auth_flavourlen
= raw
->auth_flavourlen
;
820 real
->proto
= raw
->proto
;
821 real
->host_addr
= compat_ptr(raw
->host_addr
);
822 real
->host_addrlen
= raw
->host_addrlen
;
823 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
824 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
825 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
826 real
->acdirmax
= raw
->acdirmax
;
827 real
->acdirmin
= raw
->acdirmin
;
828 real
->acregmax
= raw
->acregmax
;
829 real
->acregmin
= raw
->acregmin
;
830 real
->retrans
= raw
->retrans
;
831 real
->timeo
= raw
->timeo
;
832 real
->wsize
= raw
->wsize
;
833 real
->rsize
= raw
->rsize
;
834 real
->flags
= raw
->flags
;
835 real
->version
= raw
->version
;
844 #define SMBFS_NAME "smbfs"
845 #define NCPFS_NAME "ncpfs"
846 #define NFS4_NAME "nfs4"
848 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
849 char __user
* type
, unsigned long flags
,
852 unsigned long type_page
;
853 unsigned long data_page
;
854 unsigned long dev_page
;
858 retval
= copy_mount_options (type
, &type_page
);
862 dir_page
= getname(dir_name
);
863 retval
= PTR_ERR(dir_page
);
864 if (IS_ERR(dir_page
))
867 retval
= copy_mount_options (dev_name
, &dev_page
);
871 retval
= copy_mount_options (data
, &data_page
);
877 if (type_page
&& data_page
) {
878 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
879 do_smb_super_data_conv((void *)data_page
);
880 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
881 do_ncp_super_data_conv((void *)data_page
);
882 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
883 if (do_nfs4_super_data_conv((void *) data_page
))
889 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
890 flags
, (void*)data_page
);
894 free_page(data_page
);
900 free_page(type_page
);
905 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
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
= ALIGN(NAME_OFFSET(dirent
) + namlen
+ 2, sizeof(compat_long_t
));
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
1069 struct compat_getdents_callback64
{
1070 struct linux_dirent64 __user
*current_dir
;
1071 struct linux_dirent64 __user
*previous
;
1076 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
1077 u64 ino
, unsigned int d_type
)
1079 struct linux_dirent64 __user
*dirent
;
1080 struct compat_getdents_callback64
*buf
= __buf
;
1081 int jj
= NAME_OFFSET(dirent
);
1082 int reclen
= ALIGN(jj
+ namlen
+ 1, sizeof(u64
));
1085 buf
->error
= -EINVAL
; /* only used if we fail.. */
1086 if (reclen
> buf
->count
)
1088 dirent
= buf
->previous
;
1091 if (__put_user_unaligned(offset
, &dirent
->d_off
))
1094 dirent
= buf
->current_dir
;
1095 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
1098 if (__put_user_unaligned(off
, &dirent
->d_off
))
1100 if (__put_user(reclen
, &dirent
->d_reclen
))
1102 if (__put_user(d_type
, &dirent
->d_type
))
1104 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1106 if (__put_user(0, dirent
->d_name
+ namlen
))
1108 buf
->previous
= dirent
;
1109 dirent
= (void __user
*)dirent
+ reclen
;
1110 buf
->current_dir
= dirent
;
1111 buf
->count
-= reclen
;
1114 buf
->error
= -EFAULT
;
1118 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
1119 struct linux_dirent64 __user
* dirent
, unsigned int count
)
1122 struct linux_dirent64 __user
* lastdirent
;
1123 struct compat_getdents_callback64 buf
;
1127 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1135 buf
.current_dir
= dirent
;
1136 buf
.previous
= NULL
;
1140 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1144 lastdirent
= buf
.previous
;
1146 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1148 if (__put_user_unaligned(d_off
, &lastdirent
->d_off
))
1150 error
= count
- buf
.count
;
1158 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1160 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1161 const struct compat_iovec __user
*uvector
,
1162 unsigned long nr_segs
, loff_t
*pos
)
1164 compat_ssize_t tot_len
;
1165 struct iovec iovstack
[UIO_FASTIOV
];
1166 struct iovec
*iov
=iovstack
, *vector
;
1173 * SuS says "The readv() function *may* fail if the iovcnt argument
1174 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1175 * traditionally returned zero for zero segments, so...
1182 * First get the "struct iovec" from user memory and
1183 * verify all the pointers
1186 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1190 if (nr_segs
> UIO_FASTIOV
) {
1192 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1197 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1201 * Single unix specification:
1202 * We should -EINVAL if an element length is not >= 0 and fitting an
1203 * ssize_t. The total length is fitting an ssize_t
1205 * Be careful here because iov_len is a size_t not an ssize_t
1210 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1211 compat_ssize_t tmp
= tot_len
;
1215 if (__get_user(len
, &uvector
->iov_len
) ||
1216 __get_user(buf
, &uvector
->iov_base
)) {
1220 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1223 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1225 vector
->iov_base
= compat_ptr(buf
);
1226 vector
->iov_len
= (compat_size_t
) len
;
1235 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1239 ret
= security_file_permission(file
, type
== READ
? MAY_READ
:MAY_WRITE
);
1245 fn
= file
->f_op
->read
;
1246 fnv
= file
->f_op
->aio_read
;
1248 fn
= (io_fn_t
)file
->f_op
->write
;
1249 fnv
= file
->f_op
->aio_write
;
1253 ret
= do_sync_readv_writev(file
, iov
, nr_segs
, tot_len
,
1256 ret
= do_loop_readv_writev(file
, iov
, nr_segs
, pos
, fn
);
1259 if (iov
!= iovstack
)
1261 if ((ret
+ (type
== READ
)) > 0) {
1262 struct dentry
*dentry
= file
->f_path
.dentry
;
1264 fsnotify_access(dentry
);
1266 fsnotify_modify(dentry
);
1272 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1275 ssize_t ret
= -EBADF
;
1281 if (!(file
->f_mode
& FMODE_READ
))
1285 if (!file
->f_op
|| (!file
->f_op
->aio_read
&& !file
->f_op
->read
))
1288 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1296 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1299 ssize_t ret
= -EBADF
;
1304 if (!(file
->f_mode
& FMODE_WRITE
))
1308 if (!file
->f_op
|| (!file
->f_op
->aio_write
&& !file
->f_op
->write
))
1311 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1319 compat_sys_vmsplice(int fd
, const struct compat_iovec __user
*iov32
,
1320 unsigned int nr_segs
, unsigned int flags
)
1323 struct iovec __user
*iov
;
1324 if (nr_segs
> UIO_MAXIOV
)
1326 iov
= compat_alloc_user_space(nr_segs
* sizeof(struct iovec
));
1327 for (i
= 0; i
< nr_segs
; i
++) {
1328 struct compat_iovec v
;
1329 if (get_user(v
.iov_base
, &iov32
[i
].iov_base
) ||
1330 get_user(v
.iov_len
, &iov32
[i
].iov_len
) ||
1331 put_user(compat_ptr(v
.iov_base
), &iov
[i
].iov_base
) ||
1332 put_user(v
.iov_len
, &iov
[i
].iov_len
))
1335 return sys_vmsplice(fd
, iov
, nr_segs
, flags
);
1339 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1343 compat_sys_open(const char __user
*filename
, int flags
, int mode
)
1345 return do_sys_open(AT_FDCWD
, filename
, flags
, mode
);
1349 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1353 compat_sys_openat(unsigned int dfd
, const char __user
*filename
, int flags
, int mode
)
1355 return do_sys_open(dfd
, filename
, flags
, mode
);
1359 * compat_count() counts the number of arguments/envelopes. It is basically
1360 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1361 * and envp pointers.
1363 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1371 if (get_user(p
, argv
))
1384 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1385 * except that it works with 32 bit argv and envp pointers.
1387 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1388 struct linux_binprm
*bprm
)
1390 struct page
*kmapped_page
= NULL
;
1394 while (argc
-- > 0) {
1399 if (get_user(str
, argv
+argc
) ||
1400 !(len
= strnlen_user(compat_ptr(str
), bprm
->p
))) {
1405 if (bprm
->p
< len
) {
1411 /* XXX: add architecture specific overflow check here. */
1416 int offset
, bytes_to_copy
;
1419 offset
= pos
% PAGE_SIZE
;
1421 page
= bprm
->page
[i
];
1424 page
= alloc_page(GFP_HIGHUSER
);
1425 bprm
->page
[i
] = page
;
1433 if (page
!= kmapped_page
) {
1435 kunmap(kmapped_page
);
1436 kmapped_page
= page
;
1437 kaddr
= kmap(kmapped_page
);
1440 memset(kaddr
, 0, offset
);
1441 bytes_to_copy
= PAGE_SIZE
- offset
;
1442 if (bytes_to_copy
> len
) {
1443 bytes_to_copy
= len
;
1445 memset(kaddr
+offset
+len
, 0,
1446 PAGE_SIZE
-offset
-len
);
1448 err
= copy_from_user(kaddr
+offset
, compat_ptr(str
),
1455 pos
+= bytes_to_copy
;
1456 str
+= bytes_to_copy
;
1457 len
-= bytes_to_copy
;
1463 kunmap(kmapped_page
);
1469 #define free_arg_pages(bprm) do { } while (0)
1473 static inline void free_arg_pages(struct linux_binprm
*bprm
)
1477 for (i
= 0; i
< MAX_ARG_PAGES
; i
++) {
1479 __free_page(bprm
->page
[i
]);
1480 bprm
->page
[i
] = NULL
;
1484 #endif /* CONFIG_MMU */
1487 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1488 * that it processes 32 bit argv and envp pointers.
1490 int compat_do_execve(char * filename
,
1491 compat_uptr_t __user
*argv
,
1492 compat_uptr_t __user
*envp
,
1493 struct pt_regs
* regs
)
1495 struct linux_binprm
*bprm
;
1501 bprm
= kzalloc(sizeof(*bprm
), GFP_KERNEL
);
1505 file
= open_exec(filename
);
1506 retval
= PTR_ERR(file
);
1512 bprm
->p
= PAGE_SIZE
*MAX_ARG_PAGES
-sizeof(void *);
1514 bprm
->filename
= filename
;
1515 bprm
->interp
= filename
;
1516 bprm
->mm
= mm_alloc();
1521 retval
= init_new_context(current
, bprm
->mm
);
1525 bprm
->argc
= compat_count(argv
, bprm
->p
/ sizeof(compat_uptr_t
));
1526 if ((retval
= bprm
->argc
) < 0)
1529 bprm
->envc
= compat_count(envp
, bprm
->p
/ sizeof(compat_uptr_t
));
1530 if ((retval
= bprm
->envc
) < 0)
1533 retval
= security_bprm_alloc(bprm
);
1537 retval
= prepare_binprm(bprm
);
1541 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1545 bprm
->exec
= bprm
->p
;
1546 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1550 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1554 retval
= search_binary_handler(bprm
, regs
);
1556 free_arg_pages(bprm
);
1558 /* execve success */
1559 security_bprm_free(bprm
);
1560 acct_update_integrals(current
);
1566 /* Something went wrong, return the inode and free the argument pages*/
1567 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
1568 struct page
* page
= bprm
->page
[i
];
1574 security_bprm_free(bprm
);
1582 allow_write_access(bprm
->file
);
1593 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1596 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1597 * 64-bit unsigned longs.
1600 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1601 unsigned long *fdset
)
1603 nr
= DIV_ROUND_UP(nr
, __COMPAT_NFDBITS
);
1607 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1614 if (__get_user(l
, ufdset
) || __get_user(h
, ufdset
+1))
1617 *fdset
++ = h
<< 32 | l
;
1620 if (odd
&& __get_user(*fdset
, ufdset
))
1623 /* Tricky, must clear full unsigned long in the
1624 * kernel fdset at the end, this makes sure that
1627 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1633 int compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1634 unsigned long *fdset
)
1637 nr
= DIV_ROUND_UP(nr
, __COMPAT_NFDBITS
);
1648 if (__put_user(l
, ufdset
) || __put_user(h
, ufdset
+1))
1653 if (odd
&& __put_user(*fdset
, ufdset
))
1660 * This is a virtual copy of sys_select from fs/select.c and probably
1661 * should be compared to it from time to time
1665 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1666 * like to be certain this leads to no problems. So I return
1667 * EINTR just for safety.
1669 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1670 * I'm trying ERESTARTNOHAND which restart only when you want to.
1672 #define MAX_SELECT_SECONDS \
1673 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1675 int compat_core_sys_select(int n
, compat_ulong_t __user
*inp
,
1676 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
, s64
*timeout
)
1680 int size
, max_fds
, ret
= -EINVAL
;
1681 struct fdtable
*fdt
;
1686 /* max_fds can increase, so grab it once to avoid race */
1688 fdt
= files_fdtable(current
->files
);
1689 max_fds
= fdt
->max_fds
;
1695 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1696 * since we used fdset we need to allocate memory in units of
1700 size
= FDS_BYTES(n
);
1701 bits
= kmalloc(6 * size
, GFP_KERNEL
);
1704 fds
.in
= (unsigned long *) bits
;
1705 fds
.out
= (unsigned long *) (bits
+ size
);
1706 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1707 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1708 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1709 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1711 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1712 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1713 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1715 zero_fd_set(n
, fds
.res_in
);
1716 zero_fd_set(n
, fds
.res_out
);
1717 zero_fd_set(n
, fds
.res_ex
);
1719 ret
= do_select(n
, &fds
, timeout
);
1724 ret
= -ERESTARTNOHAND
;
1725 if (signal_pending(current
))
1730 if (compat_set_fd_set(n
, inp
, fds
.res_in
) ||
1731 compat_set_fd_set(n
, outp
, fds
.res_out
) ||
1732 compat_set_fd_set(n
, exp
, fds
.res_ex
))
1740 asmlinkage
long compat_sys_select(int n
, compat_ulong_t __user
*inp
,
1741 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1742 struct compat_timeval __user
*tvp
)
1745 struct compat_timeval tv
;
1749 if (copy_from_user(&tv
, tvp
, sizeof(tv
)))
1752 if (tv
.tv_sec
< 0 || tv
.tv_usec
< 0)
1755 /* Cast to u64 to make GCC stop complaining */
1756 if ((u64
)tv
.tv_sec
>= (u64
)MAX_INT64_SECONDS
)
1757 timeout
= -1; /* infinite */
1759 timeout
= DIV_ROUND_UP(tv
.tv_usec
, 1000000/HZ
);
1760 timeout
+= tv
.tv_sec
* HZ
;
1764 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1767 struct compat_timeval rtv
;
1769 if (current
->personality
& STICKY_TIMEOUTS
)
1771 rtv
.tv_usec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
));
1772 rtv
.tv_sec
= timeout
;
1773 if (compat_timeval_compare(&rtv
, &tv
) >= 0)
1775 if (copy_to_user(tvp
, &rtv
, sizeof(rtv
))) {
1778 * If an application puts its timeval in read-only
1779 * memory, we don't want the Linux-specific update to
1780 * the timeval to cause a fault after the select has
1781 * completed successfully. However, because we're not
1782 * updating the timeval, we can't restart the system
1785 if (ret
== -ERESTARTNOHAND
)
1793 #ifdef TIF_RESTORE_SIGMASK
1794 asmlinkage
long compat_sys_pselect7(int n
, compat_ulong_t __user
*inp
,
1795 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1796 struct compat_timespec __user
*tsp
, compat_sigset_t __user
*sigmask
,
1797 compat_size_t sigsetsize
)
1799 compat_sigset_t ss32
;
1800 sigset_t ksigmask
, sigsaved
;
1801 s64 timeout
= MAX_SCHEDULE_TIMEOUT
;
1802 struct compat_timespec ts
;
1806 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1809 if (ts
.tv_sec
< 0 || ts
.tv_nsec
< 0)
1814 if (sigsetsize
!= sizeof(compat_sigset_t
))
1816 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1818 sigset_from_compat(&ksigmask
, &ss32
);
1820 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1821 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1826 if ((unsigned long)ts
.tv_sec
< MAX_SELECT_SECONDS
) {
1827 timeout
= DIV_ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1828 timeout
+= ts
.tv_sec
* (unsigned long)HZ
;
1832 ts
.tv_sec
-= MAX_SELECT_SECONDS
;
1833 timeout
= MAX_SELECT_SECONDS
* HZ
;
1837 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1839 } while (!ret
&& !timeout
&& tsp
&& (ts
.tv_sec
|| ts
.tv_nsec
));
1842 struct compat_timespec rts
;
1844 if (current
->personality
& STICKY_TIMEOUTS
)
1847 rts
.tv_sec
= timeout
/ HZ
;
1848 rts
.tv_nsec
= (timeout
% HZ
) * (NSEC_PER_SEC
/HZ
);
1849 if (rts
.tv_nsec
>= NSEC_PER_SEC
) {
1851 rts
.tv_nsec
-= NSEC_PER_SEC
;
1853 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1855 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1858 * If an application puts its timeval in read-only
1859 * memory, we don't want the Linux-specific update to
1860 * the timeval to cause a fault after the select has
1861 * completed successfully. However, because we're not
1862 * updating the timeval, we can't restart the system
1865 if (ret
== -ERESTARTNOHAND
)
1870 if (ret
== -ERESTARTNOHAND
) {
1872 * Don't restore the signal mask yet. Let do_signal() deliver
1873 * the signal on the way back to userspace, before the signal
1877 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1879 set_thread_flag(TIF_RESTORE_SIGMASK
);
1882 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1887 asmlinkage
long compat_sys_pselect6(int n
, compat_ulong_t __user
*inp
,
1888 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1889 struct compat_timespec __user
*tsp
, void __user
*sig
)
1891 compat_size_t sigsetsize
= 0;
1892 compat_uptr_t up
= 0;
1895 if (!access_ok(VERIFY_READ
, sig
,
1896 sizeof(compat_uptr_t
)+sizeof(compat_size_t
)) ||
1897 __get_user(up
, (compat_uptr_t __user
*)sig
) ||
1898 __get_user(sigsetsize
,
1899 (compat_size_t __user
*)(sig
+sizeof(up
))))
1902 return compat_sys_pselect7(n
, inp
, outp
, exp
, tsp
, compat_ptr(up
),
1906 asmlinkage
long compat_sys_ppoll(struct pollfd __user
*ufds
,
1907 unsigned int nfds
, struct compat_timespec __user
*tsp
,
1908 const compat_sigset_t __user
*sigmask
, compat_size_t sigsetsize
)
1910 compat_sigset_t ss32
;
1911 sigset_t ksigmask
, sigsaved
;
1912 struct compat_timespec ts
;
1917 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1920 /* We assume that ts.tv_sec is always lower than
1921 the number of seconds that can be expressed in
1922 an s64. Otherwise the compiler bitches at us */
1923 timeout
= DIV_ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1924 timeout
+= ts
.tv_sec
* HZ
;
1928 if (sigsetsize
!= sizeof(compat_sigset_t
))
1930 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1932 sigset_from_compat(&ksigmask
, &ss32
);
1934 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1935 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1938 ret
= do_sys_poll(ufds
, nfds
, &timeout
);
1940 /* We can restart this syscall, usually */
1941 if (ret
== -EINTR
) {
1943 * Don't restore the signal mask yet. Let do_signal() deliver
1944 * the signal on the way back to userspace, before the signal
1948 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1950 set_thread_flag(TIF_RESTORE_SIGMASK
);
1952 ret
= -ERESTARTNOHAND
;
1954 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1956 if (tsp
&& timeout
>= 0) {
1957 struct compat_timespec rts
;
1959 if (current
->personality
& STICKY_TIMEOUTS
)
1961 /* Yes, we know it's actually an s64, but it's also positive. */
1962 rts
.tv_nsec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
)) *
1964 rts
.tv_sec
= timeout
;
1965 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1967 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1970 * If an application puts its timeval in read-only
1971 * memory, we don't want the Linux-specific update to
1972 * the timeval to cause a fault after the select has
1973 * completed successfully. However, because we're not
1974 * updating the timeval, we can't restart the system
1977 if (ret
== -ERESTARTNOHAND
&& timeout
>= 0)
1984 #endif /* TIF_RESTORE_SIGMASK */
1986 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1987 /* Stuff for NFS server syscalls... */
1988 struct compat_nfsctl_svc
{
1993 struct compat_nfsctl_client
{
1994 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
1996 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
1999 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
2002 struct compat_nfsctl_export
{
2003 char ex32_client
[NFSCLNT_IDMAX
+1];
2004 char ex32_path
[NFS_MAXPATHLEN
+1];
2005 compat_dev_t ex32_dev
;
2006 compat_ino_t ex32_ino
;
2007 compat_int_t ex32_flags
;
2008 __compat_uid_t ex32_anon_uid
;
2009 __compat_gid_t ex32_anon_gid
;
2012 struct compat_nfsctl_fdparm
{
2013 struct sockaddr gd32_addr
;
2014 s8 gd32_path
[NFS_MAXPATHLEN
+1];
2015 compat_int_t gd32_version
;
2018 struct compat_nfsctl_fsparm
{
2019 struct sockaddr gd32_addr
;
2020 s8 gd32_path
[NFS_MAXPATHLEN
+1];
2021 compat_int_t gd32_maxlen
;
2024 struct compat_nfsctl_arg
{
2025 compat_int_t ca32_version
; /* safeguard */
2027 struct compat_nfsctl_svc u32_svc
;
2028 struct compat_nfsctl_client u32_client
;
2029 struct compat_nfsctl_export u32_export
;
2030 struct compat_nfsctl_fdparm u32_getfd
;
2031 struct compat_nfsctl_fsparm u32_getfs
;
2033 #define ca32_svc u.u32_svc
2034 #define ca32_client u.u32_client
2035 #define ca32_export u.u32_export
2036 #define ca32_getfd u.u32_getfd
2037 #define ca32_getfs u.u32_getfs
2040 union compat_nfsctl_res
{
2041 __u8 cr32_getfh
[NFS_FHSIZE
];
2042 struct knfsd_fh cr32_getfs
;
2045 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
,
2046 struct compat_nfsctl_arg __user
*arg
)
2048 if (!access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
)) ||
2049 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2050 __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
) ||
2051 __get_user(karg
->ca_svc
.svc_nthreads
,
2052 &arg
->ca32_svc
.svc32_nthreads
))
2057 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
,
2058 struct compat_nfsctl_arg __user
*arg
)
2060 if (!access_ok(VERIFY_READ
, &arg
->ca32_client
,
2061 sizeof(arg
->ca32_client
)) ||
2062 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2063 __copy_from_user(&karg
->ca_client
.cl_ident
[0],
2064 &arg
->ca32_client
.cl32_ident
[0],
2066 __get_user(karg
->ca_client
.cl_naddr
,
2067 &arg
->ca32_client
.cl32_naddr
) ||
2068 __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
2069 &arg
->ca32_client
.cl32_addrlist
[0],
2070 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
)) ||
2071 __get_user(karg
->ca_client
.cl_fhkeytype
,
2072 &arg
->ca32_client
.cl32_fhkeytype
) ||
2073 __get_user(karg
->ca_client
.cl_fhkeylen
,
2074 &arg
->ca32_client
.cl32_fhkeylen
) ||
2075 __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
2076 &arg
->ca32_client
.cl32_fhkey
[0],
2083 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
,
2084 struct compat_nfsctl_arg __user
*arg
)
2086 if (!access_ok(VERIFY_READ
, &arg
->ca32_export
,
2087 sizeof(arg
->ca32_export
)) ||
2088 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2089 __copy_from_user(&karg
->ca_export
.ex_client
[0],
2090 &arg
->ca32_export
.ex32_client
[0],
2092 __copy_from_user(&karg
->ca_export
.ex_path
[0],
2093 &arg
->ca32_export
.ex32_path
[0],
2095 __get_user(karg
->ca_export
.ex_dev
,
2096 &arg
->ca32_export
.ex32_dev
) ||
2097 __get_user(karg
->ca_export
.ex_ino
,
2098 &arg
->ca32_export
.ex32_ino
) ||
2099 __get_user(karg
->ca_export
.ex_flags
,
2100 &arg
->ca32_export
.ex32_flags
) ||
2101 __get_user(karg
->ca_export
.ex_anon_uid
,
2102 &arg
->ca32_export
.ex32_anon_uid
) ||
2103 __get_user(karg
->ca_export
.ex_anon_gid
,
2104 &arg
->ca32_export
.ex32_anon_gid
))
2106 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
2107 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
2112 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
,
2113 struct compat_nfsctl_arg __user
*arg
)
2115 if (!access_ok(VERIFY_READ
, &arg
->ca32_getfd
,
2116 sizeof(arg
->ca32_getfd
)) ||
2117 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2118 __copy_from_user(&karg
->ca_getfd
.gd_addr
,
2119 &arg
->ca32_getfd
.gd32_addr
,
2120 (sizeof(struct sockaddr
))) ||
2121 __copy_from_user(&karg
->ca_getfd
.gd_path
,
2122 &arg
->ca32_getfd
.gd32_path
,
2123 (NFS_MAXPATHLEN
+1)) ||
2124 __get_user(karg
->ca_getfd
.gd_version
,
2125 &arg
->ca32_getfd
.gd32_version
))
2131 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
,
2132 struct compat_nfsctl_arg __user
*arg
)
2134 if (!access_ok(VERIFY_READ
,&arg
->ca32_getfs
,sizeof(arg
->ca32_getfs
)) ||
2135 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2136 __copy_from_user(&karg
->ca_getfs
.gd_addr
,
2137 &arg
->ca32_getfs
.gd32_addr
,
2138 (sizeof(struct sockaddr
))) ||
2139 __copy_from_user(&karg
->ca_getfs
.gd_path
,
2140 &arg
->ca32_getfs
.gd32_path
,
2141 (NFS_MAXPATHLEN
+1)) ||
2142 __get_user(karg
->ca_getfs
.gd_maxlen
,
2143 &arg
->ca32_getfs
.gd32_maxlen
))
2149 /* This really doesn't need translations, we are only passing
2150 * back a union which contains opaque nfs file handle data.
2152 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
,
2153 union compat_nfsctl_res __user
*res
)
2157 err
= copy_to_user(res
, kres
, sizeof(*res
));
2159 return (err
) ? -EFAULT
: 0;
2162 asmlinkage
long compat_sys_nfsservctl(int cmd
,
2163 struct compat_nfsctl_arg __user
*arg
,
2164 union compat_nfsctl_res __user
*res
)
2166 struct nfsctl_arg
*karg
;
2167 union nfsctl_res
*kres
;
2171 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
2172 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
2173 if(!karg
|| !kres
) {
2180 err
= compat_nfs_svc_trans(karg
, arg
);
2183 case NFSCTL_ADDCLIENT
:
2184 err
= compat_nfs_clnt_trans(karg
, arg
);
2187 case NFSCTL_DELCLIENT
:
2188 err
= compat_nfs_clnt_trans(karg
, arg
);
2192 case NFSCTL_UNEXPORT
:
2193 err
= compat_nfs_exp_trans(karg
, arg
);
2197 err
= compat_nfs_getfd_trans(karg
, arg
);
2201 err
= compat_nfs_getfs_trans(karg
, arg
);
2214 /* The __user pointer casts are valid because of the set_fs() */
2215 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
2221 if((cmd
== NFSCTL_GETFD
) ||
2222 (cmd
== NFSCTL_GETFS
))
2223 err
= compat_nfs_getfh_res_trans(kres
, res
);
2231 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
2233 return sys_ni_syscall();
2239 #ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
2240 asmlinkage
long compat_sys_epoll_ctl(int epfd
, int op
, int fd
,
2241 struct compat_epoll_event __user
*event
)
2244 struct compat_epoll_event user
;
2245 struct epoll_event __user
*kernel
= NULL
;
2248 if (copy_from_user(&user
, event
, sizeof(user
)))
2250 kernel
= compat_alloc_user_space(sizeof(struct epoll_event
));
2251 err
|= __put_user(user
.events
, &kernel
->events
);
2252 err
|= __put_user(user
.data
, &kernel
->data
);
2255 return err
? err
: sys_epoll_ctl(epfd
, op
, fd
, kernel
);
2259 asmlinkage
long compat_sys_epoll_wait(int epfd
,
2260 struct compat_epoll_event __user
*events
,
2261 int maxevents
, int timeout
)
2263 long i
, ret
, err
= 0;
2264 struct epoll_event __user
*kbuf
;
2265 struct epoll_event ev
;
2267 if ((maxevents
<= 0) ||
2268 (maxevents
> (INT_MAX
/ sizeof(struct epoll_event
))))
2270 kbuf
= compat_alloc_user_space(sizeof(struct epoll_event
) * maxevents
);
2271 ret
= sys_epoll_wait(epfd
, kbuf
, maxevents
, timeout
);
2272 for (i
= 0; i
< ret
; i
++) {
2273 err
|= __get_user(ev
.events
, &kbuf
[i
].events
);
2274 err
|= __get_user(ev
.data
, &kbuf
[i
].data
);
2275 err
|= __put_user(ev
.events
, &events
->events
);
2276 err
|= __put_user_unaligned(ev
.data
, &events
->data
);
2280 return err
? -EFAULT
: ret
;
2282 #endif /* CONFIG_HAS_COMPAT_EPOLL_EVENT */
2284 #ifdef TIF_RESTORE_SIGMASK
2285 asmlinkage
long compat_sys_epoll_pwait(int epfd
,
2286 struct compat_epoll_event __user
*events
,
2287 int maxevents
, int timeout
,
2288 const compat_sigset_t __user
*sigmask
,
2289 compat_size_t sigsetsize
)
2292 compat_sigset_t csigmask
;
2293 sigset_t ksigmask
, sigsaved
;
2296 * If the caller wants a certain signal mask to be set during the wait,
2300 if (sigsetsize
!= sizeof(compat_sigset_t
))
2302 if (copy_from_user(&csigmask
, sigmask
, sizeof(csigmask
)))
2304 sigset_from_compat(&ksigmask
, &csigmask
);
2305 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
) | sigmask(SIGSTOP
));
2306 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
2309 #ifdef CONFIG_HAS_COMPAT_EPOLL_EVENT
2310 err
= compat_sys_epoll_wait(epfd
, events
, maxevents
, timeout
);
2312 err
= sys_epoll_wait(epfd
, events
, maxevents
, timeout
);
2316 * If we changed the signal mask, we need to restore the original one.
2317 * In case we've got a signal while waiting, we do not restore the
2318 * signal mask yet, and we allow do_signal() to deliver the signal on
2319 * the way back to userspace, before the signal mask is restored.
2322 if (err
== -EINTR
) {
2323 memcpy(¤t
->saved_sigmask
, &sigsaved
,
2325 set_thread_flag(TIF_RESTORE_SIGMASK
);
2327 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
2332 #endif /* TIF_RESTORE_SIGMASK */
2334 #endif /* CONFIG_EPOLL */