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>
51 #include <net/sock.h> /* siocdevprivate_ioctl */
53 #include <asm/uaccess.h>
54 #include <asm/mmu_context.h>
55 #include <asm/ioctls.h>
60 int compat_printk(const char *fmt
, ...)
67 ret
= vprintk(fmt
, ap
);
72 #include "read_write.h"
75 * Not all architectures have sys_utime, so implement this in terms
78 asmlinkage
long compat_sys_utime(char __user
*filename
, struct compat_utimbuf __user
*t
)
83 if (get_user(tv
[0].tv_sec
, &t
->actime
) ||
84 get_user(tv
[1].tv_sec
, &t
->modtime
))
89 return do_utimes(AT_FDCWD
, filename
, t
? tv
: NULL
);
92 asmlinkage
long compat_sys_futimesat(unsigned int dfd
, char __user
*filename
, struct compat_timeval __user
*t
)
97 if (get_user(tv
[0].tv_sec
, &t
[0].tv_sec
) ||
98 get_user(tv
[0].tv_usec
, &t
[0].tv_usec
) ||
99 get_user(tv
[1].tv_sec
, &t
[1].tv_sec
) ||
100 get_user(tv
[1].tv_usec
, &t
[1].tv_usec
))
103 return do_utimes(dfd
, filename
, t
? tv
: NULL
);
106 asmlinkage
long compat_sys_utimes(char __user
*filename
, struct compat_timeval __user
*t
)
108 return compat_sys_futimesat(AT_FDCWD
, filename
, t
);
111 asmlinkage
long compat_sys_newstat(char __user
* filename
,
112 struct compat_stat __user
*statbuf
)
115 int error
= vfs_stat_fd(AT_FDCWD
, filename
, &stat
);
118 error
= cp_compat_stat(&stat
, statbuf
);
122 asmlinkage
long compat_sys_newlstat(char __user
* filename
,
123 struct compat_stat __user
*statbuf
)
126 int error
= vfs_lstat_fd(AT_FDCWD
, filename
, &stat
);
129 error
= cp_compat_stat(&stat
, statbuf
);
133 #ifndef __ARCH_WANT_STAT64
134 asmlinkage
long compat_sys_newfstatat(unsigned int dfd
, char __user
*filename
,
135 struct compat_stat __user
*statbuf
, int flag
)
140 if ((flag
& ~AT_SYMLINK_NOFOLLOW
) != 0)
143 if (flag
& AT_SYMLINK_NOFOLLOW
)
144 error
= vfs_lstat_fd(dfd
, filename
, &stat
);
146 error
= vfs_stat_fd(dfd
, filename
, &stat
);
149 error
= cp_compat_stat(&stat
, statbuf
);
156 asmlinkage
long compat_sys_newfstat(unsigned int fd
,
157 struct compat_stat __user
* statbuf
)
160 int error
= vfs_fstat(fd
, &stat
);
163 error
= cp_compat_stat(&stat
, statbuf
);
167 static int put_compat_statfs(struct compat_statfs __user
*ubuf
, struct kstatfs
*kbuf
)
170 if (sizeof ubuf
->f_blocks
== 4) {
171 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
172 0xffffffff00000000ULL
)
174 /* f_files and f_ffree may be -1; it's okay
175 * to stuff that into 32 bits */
176 if (kbuf
->f_files
!= 0xffffffffffffffffULL
177 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
179 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
180 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
183 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
184 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
185 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
186 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
187 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
188 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
189 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
190 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
191 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
192 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
193 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
194 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
) ||
195 __put_user(0, &ubuf
->f_spare
[0]) ||
196 __put_user(0, &ubuf
->f_spare
[1]) ||
197 __put_user(0, &ubuf
->f_spare
[2]) ||
198 __put_user(0, &ubuf
->f_spare
[3]) ||
199 __put_user(0, &ubuf
->f_spare
[4]))
205 * The following statfs calls are copies of code from fs/open.c and
206 * should be checked against those from time to time
208 asmlinkage
long compat_sys_statfs(const char __user
*path
, struct compat_statfs __user
*buf
)
213 error
= user_path_walk(path
, &nd
);
216 error
= vfs_statfs(nd
.dentry
, &tmp
);
218 error
= put_compat_statfs(buf
, &tmp
);
224 asmlinkage
long compat_sys_fstatfs(unsigned int fd
, struct compat_statfs __user
*buf
)
234 error
= vfs_statfs(file
->f_dentry
, &tmp
);
236 error
= put_compat_statfs(buf
, &tmp
);
242 static int put_compat_statfs64(struct compat_statfs64 __user
*ubuf
, struct kstatfs
*kbuf
)
244 if (sizeof ubuf
->f_blocks
== 4) {
245 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
246 0xffffffff00000000ULL
)
248 /* f_files and f_ffree may be -1; it's okay
249 * to stuff that into 32 bits */
250 if (kbuf
->f_files
!= 0xffffffffffffffffULL
251 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
253 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
254 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
257 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
258 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
259 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
260 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
261 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
262 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
263 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
264 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
265 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
266 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
267 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
268 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
))
273 asmlinkage
long compat_sys_statfs64(const char __user
*path
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
278 if (sz
!= sizeof(*buf
))
281 error
= user_path_walk(path
, &nd
);
284 error
= vfs_statfs(nd
.dentry
, &tmp
);
286 error
= put_compat_statfs64(buf
, &tmp
);
292 asmlinkage
long compat_sys_fstatfs64(unsigned int fd
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
298 if (sz
!= sizeof(*buf
))
305 error
= vfs_statfs(file
->f_dentry
, &tmp
);
307 error
= put_compat_statfs64(buf
, &tmp
);
313 /* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */
315 #define IOCTL_HASHSIZE 256
316 static struct ioctl_trans
*ioctl32_hash_table
[IOCTL_HASHSIZE
];
318 static inline unsigned long ioctl32_hash(unsigned long cmd
)
320 return (((cmd
>> 6) ^ (cmd
>> 4) ^ cmd
)) % IOCTL_HASHSIZE
;
323 static void ioctl32_insert_translation(struct ioctl_trans
*trans
)
326 struct ioctl_trans
*t
;
328 hash
= ioctl32_hash (trans
->cmd
);
329 if (!ioctl32_hash_table
[hash
])
330 ioctl32_hash_table
[hash
] = trans
;
332 t
= ioctl32_hash_table
[hash
];
340 static int __init
init_sys32_ioctl(void)
344 for (i
= 0; i
< ioctl_table_size
; i
++) {
345 if (ioctl_start
[i
].next
!= 0) {
346 printk("ioctl translation %d bad\n",i
);
350 ioctl32_insert_translation(&ioctl_start
[i
]);
355 __initcall(init_sys32_ioctl
);
357 static void compat_ioctl_error(struct file
*filp
, unsigned int fd
,
358 unsigned int cmd
, unsigned long arg
)
364 /* find the name of the device. */
365 path
= (char *)__get_free_page(GFP_KERNEL
);
367 fn
= d_path(filp
->f_dentry
, filp
->f_vfsmnt
, path
, PAGE_SIZE
);
372 sprintf(buf
,"'%c'", (cmd
>>24) & 0x3f);
373 if (!isprint(buf
[1]))
374 sprintf(buf
, "%02x", buf
[1]);
375 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
376 "cmd(%08x){%s} arg(%08x) on %s\n",
377 current
->comm
, current
->pid
,
378 (int)fd
, (unsigned int)cmd
, buf
,
379 (unsigned int)arg
, fn
);
382 free_page((unsigned long)path
);
385 asmlinkage
long compat_sys_ioctl(unsigned int fd
, unsigned int cmd
,
390 struct ioctl_trans
*t
;
393 filp
= fget_light(fd
, &fput_needed
);
397 /* RED-PEN how should LSM module know it's handling 32bit? */
398 error
= security_file_ioctl(filp
, cmd
, arg
);
403 * To allow the compat_ioctl handlers to be self contained
404 * we need to check the common ioctls here first.
405 * Just handle them with the standard handlers below.
418 if (S_ISREG(filp
->f_dentry
->d_inode
->i_mode
))
423 if (filp
->f_op
&& filp
->f_op
->compat_ioctl
) {
424 error
= filp
->f_op
->compat_ioctl(filp
, cmd
, arg
);
425 if (error
!= -ENOIOCTLCMD
)
430 (!filp
->f_op
->ioctl
&& !filp
->f_op
->unlocked_ioctl
))
435 for (t
= ioctl32_hash_table
[ioctl32_hash(cmd
)]; t
; t
= t
->next
) {
440 if (S_ISSOCK(filp
->f_dentry
->d_inode
->i_mode
) &&
441 cmd
>= SIOCDEVPRIVATE
&& cmd
<= (SIOCDEVPRIVATE
+ 15)) {
442 error
= siocdevprivate_ioctl(fd
, cmd
, arg
);
447 compat_ioctl_error(filp
, fd
, cmd
, arg
);
456 error
= t
->handler(fd
, cmd
, arg
, filp
);
462 error
= vfs_ioctl(filp
, fd
, cmd
, arg
);
464 fput_light(filp
, fput_needed
);
469 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
471 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
472 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
473 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
474 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
475 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
476 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
481 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
483 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
484 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
485 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
486 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
487 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
488 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
493 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
494 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
496 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
497 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
498 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
499 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
500 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
501 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
507 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
508 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
510 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
511 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
512 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
513 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
514 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
515 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
521 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
532 ret
= get_compat_flock(&f
, compat_ptr(arg
));
537 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
539 if (cmd
== F_GETLK
&& ret
== 0) {
540 /* GETLK was successfule and we need to return the data...
541 * but it needs to fit in the compat structure.
542 * l_start shouldn't be too big, unless the original
543 * start + end is greater than COMPAT_OFF_T_MAX, in which
544 * case the app was asking for trouble, so we return
545 * -EOVERFLOW in that case.
546 * l_len could be too big, in which case we just truncate it,
547 * and only allow the app to see that part of the conflicting
548 * lock that might make sense to it anyway
551 if (f
.l_start
> COMPAT_OFF_T_MAX
)
553 if (f
.l_len
> COMPAT_OFF_T_MAX
)
554 f
.l_len
= COMPAT_OFF_T_MAX
;
556 ret
= put_compat_flock(&f
, compat_ptr(arg
));
563 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
568 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
569 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
572 if (cmd
== F_GETLK64
&& ret
== 0) {
573 /* need to return lock information - see above for commentary */
574 if (f
.l_start
> COMPAT_LOFF_T_MAX
)
576 if (f
.l_len
> COMPAT_LOFF_T_MAX
)
577 f
.l_len
= COMPAT_LOFF_T_MAX
;
579 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
584 ret
= sys_fcntl(fd
, cmd
, arg
);
590 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
593 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
595 return compat_sys_fcntl64(fd
, cmd
, arg
);
599 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
604 mm_segment_t oldfs
= get_fs();
605 if (unlikely(get_user(ctx64
, ctx32p
)))
609 /* The __user pointer cast is valid because of the set_fs() */
610 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
612 /* truncating is ok because it's a user address */
614 ret
= put_user((u32
) ctx64
, ctx32p
);
619 compat_sys_io_getevents(aio_context_t ctx_id
,
620 unsigned long min_nr
,
622 struct io_event __user
*events
,
623 struct compat_timespec __user
*timeout
)
627 struct timespec __user
*ut
= NULL
;
630 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
631 nr
* sizeof(struct io_event
))))
634 if (get_compat_timespec(&t
, timeout
))
637 ut
= compat_alloc_user_space(sizeof(*ut
));
638 if (copy_to_user(ut
, &t
, sizeof(t
)) )
641 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
647 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
652 for (i
= 0; i
< nr
; ++i
) {
653 if (get_user(uptr
, ptr32
+ i
))
655 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
661 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
664 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
666 struct iocb __user
* __user
*iocb64
;
669 if (unlikely(nr
< 0))
672 if (nr
> MAX_AIO_SUBMITS
)
673 nr
= MAX_AIO_SUBMITS
;
675 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
676 ret
= copy_iocb(nr
, iocb
, iocb64
);
678 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
682 struct compat_ncp_mount_data
{
683 compat_int_t version
;
684 compat_uint_t ncp_fd
;
685 __compat_uid_t mounted_uid
;
686 compat_pid_t wdog_pid
;
687 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
688 compat_uint_t time_out
;
689 compat_uint_t retry_count
;
693 compat_mode_t file_mode
;
694 compat_mode_t dir_mode
;
697 struct compat_ncp_mount_data_v4
{
698 compat_int_t version
;
699 compat_ulong_t flags
;
700 compat_ulong_t mounted_uid
;
701 compat_long_t wdog_pid
;
702 compat_uint_t ncp_fd
;
703 compat_uint_t time_out
;
704 compat_uint_t retry_count
;
707 compat_ulong_t file_mode
;
708 compat_ulong_t dir_mode
;
711 static void *do_ncp_super_data_conv(void *raw_data
)
713 int version
= *(unsigned int *)raw_data
;
716 struct compat_ncp_mount_data
*c_n
= raw_data
;
717 struct ncp_mount_data
*n
= raw_data
;
719 n
->dir_mode
= c_n
->dir_mode
;
720 n
->file_mode
= c_n
->file_mode
;
723 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
724 n
->wdog_pid
= c_n
->wdog_pid
;
725 n
->mounted_uid
= c_n
->mounted_uid
;
726 } else if (version
== 4) {
727 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
728 struct ncp_mount_data_v4
*n
= raw_data
;
730 n
->dir_mode
= c_n
->dir_mode
;
731 n
->file_mode
= c_n
->file_mode
;
734 n
->retry_count
= c_n
->retry_count
;
735 n
->time_out
= c_n
->time_out
;
736 n
->ncp_fd
= c_n
->ncp_fd
;
737 n
->wdog_pid
= c_n
->wdog_pid
;
738 n
->mounted_uid
= c_n
->mounted_uid
;
739 n
->flags
= c_n
->flags
;
740 } else if (version
!= 5) {
747 struct compat_smb_mount_data
{
748 compat_int_t version
;
749 __compat_uid_t mounted_uid
;
752 compat_mode_t file_mode
;
753 compat_mode_t dir_mode
;
756 static void *do_smb_super_data_conv(void *raw_data
)
758 struct smb_mount_data
*s
= raw_data
;
759 struct compat_smb_mount_data
*c_s
= raw_data
;
761 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
763 s
->dir_mode
= c_s
->dir_mode
;
764 s
->file_mode
= c_s
->file_mode
;
767 s
->mounted_uid
= c_s
->mounted_uid
;
772 struct compat_nfs_string
{
777 static inline void compat_nfs_string(struct nfs_string
*dst
,
778 struct compat_nfs_string
*src
)
780 dst
->data
= compat_ptr(src
->data
);
784 struct compat_nfs4_mount_data_v1
{
785 compat_int_t version
;
790 compat_int_t retrans
;
791 compat_int_t acregmin
;
792 compat_int_t acregmax
;
793 compat_int_t acdirmin
;
794 compat_int_t acdirmax
;
795 struct compat_nfs_string client_addr
;
796 struct compat_nfs_string mnt_path
;
797 struct compat_nfs_string hostname
;
798 compat_uint_t host_addrlen
;
799 compat_uptr_t host_addr
;
801 compat_int_t auth_flavourlen
;
802 compat_uptr_t auth_flavours
;
805 static int do_nfs4_super_data_conv(void *raw_data
)
807 int version
= *(compat_uint_t
*) raw_data
;
810 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
811 struct nfs4_mount_data
*real
= raw_data
;
813 /* copy the fields backwards */
814 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
815 real
->auth_flavourlen
= raw
->auth_flavourlen
;
816 real
->proto
= raw
->proto
;
817 real
->host_addr
= compat_ptr(raw
->host_addr
);
818 real
->host_addrlen
= raw
->host_addrlen
;
819 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
820 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
821 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
822 real
->acdirmax
= raw
->acdirmax
;
823 real
->acdirmin
= raw
->acdirmin
;
824 real
->acregmax
= raw
->acregmax
;
825 real
->acregmin
= raw
->acregmin
;
826 real
->retrans
= raw
->retrans
;
827 real
->timeo
= raw
->timeo
;
828 real
->wsize
= raw
->wsize
;
829 real
->rsize
= raw
->rsize
;
830 real
->flags
= raw
->flags
;
831 real
->version
= raw
->version
;
840 #define SMBFS_NAME "smbfs"
841 #define NCPFS_NAME "ncpfs"
842 #define NFS4_NAME "nfs4"
844 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
845 char __user
* type
, unsigned long flags
,
848 unsigned long type_page
;
849 unsigned long data_page
;
850 unsigned long dev_page
;
854 retval
= copy_mount_options (type
, &type_page
);
858 dir_page
= getname(dir_name
);
859 retval
= PTR_ERR(dir_page
);
860 if (IS_ERR(dir_page
))
863 retval
= copy_mount_options (dev_name
, &dev_page
);
867 retval
= copy_mount_options (data
, &data_page
);
874 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
875 do_smb_super_data_conv((void *)data_page
);
876 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
877 do_ncp_super_data_conv((void *)data_page
);
878 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
879 if (do_nfs4_super_data_conv((void *) data_page
))
885 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
886 flags
, (void*)data_page
);
890 free_page(data_page
);
896 free_page(type_page
);
901 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
902 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
903 ~(sizeof(compat_long_t)-1))
905 struct compat_old_linux_dirent
{
906 compat_ulong_t d_ino
;
907 compat_ulong_t d_offset
;
908 unsigned short d_namlen
;
912 struct compat_readdir_callback
{
913 struct compat_old_linux_dirent __user
*dirent
;
917 static int compat_fillonedir(void *__buf
, const char *name
, int namlen
,
918 loff_t offset
, u64 ino
, unsigned int d_type
)
920 struct compat_readdir_callback
*buf
= __buf
;
921 struct compat_old_linux_dirent __user
*dirent
;
922 compat_ulong_t d_ino
;
927 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
930 dirent
= buf
->dirent
;
931 if (!access_ok(VERIFY_WRITE
, dirent
,
932 (unsigned long)(dirent
->d_name
+ namlen
+ 1) -
933 (unsigned long)dirent
))
935 if ( __put_user(d_ino
, &dirent
->d_ino
) ||
936 __put_user(offset
, &dirent
->d_offset
) ||
937 __put_user(namlen
, &dirent
->d_namlen
) ||
938 __copy_to_user(dirent
->d_name
, name
, namlen
) ||
939 __put_user(0, dirent
->d_name
+ namlen
))
943 buf
->result
= -EFAULT
;
947 asmlinkage
long compat_sys_old_readdir(unsigned int fd
,
948 struct compat_old_linux_dirent __user
*dirent
, unsigned int count
)
952 struct compat_readdir_callback buf
;
962 error
= vfs_readdir(file
, compat_fillonedir
, &buf
);
971 struct compat_linux_dirent
{
972 compat_ulong_t d_ino
;
973 compat_ulong_t d_off
;
974 unsigned short d_reclen
;
978 struct compat_getdents_callback
{
979 struct compat_linux_dirent __user
*current_dir
;
980 struct compat_linux_dirent __user
*previous
;
985 static int compat_filldir(void *__buf
, const char *name
, int namlen
,
986 loff_t offset
, u64 ino
, unsigned int d_type
)
988 struct compat_linux_dirent __user
* dirent
;
989 struct compat_getdents_callback
*buf
= __buf
;
990 compat_ulong_t d_ino
;
991 int reclen
= COMPAT_ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 2);
993 buf
->error
= -EINVAL
; /* only used if we fail.. */
994 if (reclen
> buf
->count
)
997 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
999 dirent
= buf
->previous
;
1001 if (__put_user(offset
, &dirent
->d_off
))
1004 dirent
= buf
->current_dir
;
1005 if (__put_user(d_ino
, &dirent
->d_ino
))
1007 if (__put_user(reclen
, &dirent
->d_reclen
))
1009 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1011 if (__put_user(0, dirent
->d_name
+ namlen
))
1013 if (__put_user(d_type
, (char __user
*) dirent
+ reclen
- 1))
1015 buf
->previous
= dirent
;
1016 dirent
= (void __user
*)dirent
+ reclen
;
1017 buf
->current_dir
= dirent
;
1018 buf
->count
-= reclen
;
1021 buf
->error
= -EFAULT
;
1025 asmlinkage
long compat_sys_getdents(unsigned int fd
,
1026 struct compat_linux_dirent __user
*dirent
, unsigned int count
)
1029 struct compat_linux_dirent __user
* lastdirent
;
1030 struct compat_getdents_callback buf
;
1034 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1042 buf
.current_dir
= dirent
;
1043 buf
.previous
= NULL
;
1047 error
= vfs_readdir(file
, compat_filldir
, &buf
);
1051 lastdirent
= buf
.previous
;
1053 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
1056 error
= count
- buf
.count
;
1065 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1066 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1068 struct compat_getdents_callback64
{
1069 struct linux_dirent64 __user
*current_dir
;
1070 struct linux_dirent64 __user
*previous
;
1075 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
1076 u64 ino
, unsigned int d_type
)
1078 struct linux_dirent64 __user
*dirent
;
1079 struct compat_getdents_callback64
*buf
= __buf
;
1080 int jj
= NAME_OFFSET(dirent
);
1081 int reclen
= COMPAT_ROUND_UP64(jj
+ namlen
+ 1);
1084 buf
->error
= -EINVAL
; /* only used if we fail.. */
1085 if (reclen
> buf
->count
)
1087 dirent
= buf
->previous
;
1090 if (__put_user_unaligned(offset
, &dirent
->d_off
))
1093 dirent
= buf
->current_dir
;
1094 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
1097 if (__put_user_unaligned(off
, &dirent
->d_off
))
1099 if (__put_user(reclen
, &dirent
->d_reclen
))
1101 if (__put_user(d_type
, &dirent
->d_type
))
1103 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1105 if (__put_user(0, dirent
->d_name
+ namlen
))
1107 buf
->previous
= dirent
;
1108 dirent
= (void __user
*)dirent
+ reclen
;
1109 buf
->current_dir
= dirent
;
1110 buf
->count
-= reclen
;
1113 buf
->error
= -EFAULT
;
1117 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
1118 struct linux_dirent64 __user
* dirent
, unsigned int count
)
1121 struct linux_dirent64 __user
* lastdirent
;
1122 struct compat_getdents_callback64 buf
;
1126 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1134 buf
.current_dir
= dirent
;
1135 buf
.previous
= NULL
;
1139 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1143 lastdirent
= buf
.previous
;
1145 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1146 __put_user_unaligned(d_off
, &lastdirent
->d_off
);
1147 error
= count
- buf
.count
;
1155 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1157 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1158 const struct compat_iovec __user
*uvector
,
1159 unsigned long nr_segs
, loff_t
*pos
)
1161 compat_ssize_t tot_len
;
1162 struct iovec iovstack
[UIO_FASTIOV
];
1163 struct iovec
*iov
=iovstack
, *vector
;
1170 * SuS says "The readv() function *may* fail if the iovcnt argument
1171 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1172 * traditionally returned zero for zero segments, so...
1179 * First get the "struct iovec" from user memory and
1180 * verify all the pointers
1183 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1187 if (nr_segs
> UIO_FASTIOV
) {
1189 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1194 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1198 * Single unix specification:
1199 * We should -EINVAL if an element length is not >= 0 and fitting an
1200 * ssize_t. The total length is fitting an ssize_t
1202 * Be careful here because iov_len is a size_t not an ssize_t
1207 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1208 compat_ssize_t tmp
= tot_len
;
1212 if (__get_user(len
, &uvector
->iov_len
) ||
1213 __get_user(buf
, &uvector
->iov_base
)) {
1217 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1220 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1222 vector
->iov_base
= compat_ptr(buf
);
1223 vector
->iov_len
= (compat_size_t
) len
;
1232 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1236 ret
= security_file_permission(file
, type
== READ
? MAY_READ
:MAY_WRITE
);
1242 fn
= file
->f_op
->read
;
1243 fnv
= file
->f_op
->aio_read
;
1245 fn
= (io_fn_t
)file
->f_op
->write
;
1246 fnv
= file
->f_op
->aio_write
;
1250 ret
= do_sync_readv_writev(file
, iov
, nr_segs
, tot_len
,
1253 ret
= do_loop_readv_writev(file
, iov
, nr_segs
, pos
, fn
);
1256 if (iov
!= iovstack
)
1258 if ((ret
+ (type
== READ
)) > 0) {
1259 struct dentry
*dentry
= file
->f_dentry
;
1261 fsnotify_access(dentry
);
1263 fsnotify_modify(dentry
);
1269 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1272 ssize_t ret
= -EBADF
;
1278 if (!(file
->f_mode
& FMODE_READ
))
1282 if (!file
->f_op
|| (!file
->f_op
->aio_read
&& !file
->f_op
->read
))
1285 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1293 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1296 ssize_t ret
= -EBADF
;
1301 if (!(file
->f_mode
& FMODE_WRITE
))
1305 if (!file
->f_op
|| (!file
->f_op
->aio_write
&& !file
->f_op
->write
))
1308 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1316 compat_sys_vmsplice(int fd
, const struct compat_iovec __user
*iov32
,
1317 unsigned int nr_segs
, unsigned int flags
)
1320 struct iovec __user
*iov
;
1321 if (nr_segs
> UIO_MAXIOV
)
1323 iov
= compat_alloc_user_space(nr_segs
* sizeof(struct iovec
));
1324 for (i
= 0; i
< nr_segs
; i
++) {
1325 struct compat_iovec v
;
1326 if (get_user(v
.iov_base
, &iov32
[i
].iov_base
) ||
1327 get_user(v
.iov_len
, &iov32
[i
].iov_len
) ||
1328 put_user(compat_ptr(v
.iov_base
), &iov
[i
].iov_base
) ||
1329 put_user(v
.iov_len
, &iov
[i
].iov_len
))
1332 return sys_vmsplice(fd
, iov
, nr_segs
, flags
);
1336 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1340 compat_sys_open(const char __user
*filename
, int flags
, int mode
)
1342 return do_sys_open(AT_FDCWD
, filename
, flags
, mode
);
1346 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1350 compat_sys_openat(unsigned int dfd
, const char __user
*filename
, int flags
, int mode
)
1352 return do_sys_open(dfd
, filename
, flags
, mode
);
1356 * compat_count() counts the number of arguments/envelopes. It is basically
1357 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1358 * and envp pointers.
1360 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1368 if (get_user(p
, argv
))
1381 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1382 * except that it works with 32 bit argv and envp pointers.
1384 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1385 struct linux_binprm
*bprm
)
1387 struct page
*kmapped_page
= NULL
;
1391 while (argc
-- > 0) {
1396 if (get_user(str
, argv
+argc
) ||
1397 !(len
= strnlen_user(compat_ptr(str
), bprm
->p
))) {
1402 if (bprm
->p
< len
) {
1408 /* XXX: add architecture specific overflow check here. */
1413 int offset
, bytes_to_copy
;
1416 offset
= pos
% PAGE_SIZE
;
1418 page
= bprm
->page
[i
];
1421 page
= alloc_page(GFP_HIGHUSER
);
1422 bprm
->page
[i
] = page
;
1430 if (page
!= kmapped_page
) {
1432 kunmap(kmapped_page
);
1433 kmapped_page
= page
;
1434 kaddr
= kmap(kmapped_page
);
1437 memset(kaddr
, 0, offset
);
1438 bytes_to_copy
= PAGE_SIZE
- offset
;
1439 if (bytes_to_copy
> len
) {
1440 bytes_to_copy
= len
;
1442 memset(kaddr
+offset
+len
, 0,
1443 PAGE_SIZE
-offset
-len
);
1445 err
= copy_from_user(kaddr
+offset
, compat_ptr(str
),
1452 pos
+= bytes_to_copy
;
1453 str
+= bytes_to_copy
;
1454 len
-= bytes_to_copy
;
1460 kunmap(kmapped_page
);
1466 #define free_arg_pages(bprm) do { } while (0)
1470 static inline void free_arg_pages(struct linux_binprm
*bprm
)
1474 for (i
= 0; i
< MAX_ARG_PAGES
; i
++) {
1476 __free_page(bprm
->page
[i
]);
1477 bprm
->page
[i
] = NULL
;
1481 #endif /* CONFIG_MMU */
1484 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1485 * that it processes 32 bit argv and envp pointers.
1487 int compat_do_execve(char * filename
,
1488 compat_uptr_t __user
*argv
,
1489 compat_uptr_t __user
*envp
,
1490 struct pt_regs
* regs
)
1492 struct linux_binprm
*bprm
;
1498 bprm
= kzalloc(sizeof(*bprm
), GFP_KERNEL
);
1502 file
= open_exec(filename
);
1503 retval
= PTR_ERR(file
);
1509 bprm
->p
= PAGE_SIZE
*MAX_ARG_PAGES
-sizeof(void *);
1511 bprm
->filename
= filename
;
1512 bprm
->interp
= filename
;
1513 bprm
->mm
= mm_alloc();
1518 retval
= init_new_context(current
, bprm
->mm
);
1522 bprm
->argc
= compat_count(argv
, bprm
->p
/ sizeof(compat_uptr_t
));
1523 if ((retval
= bprm
->argc
) < 0)
1526 bprm
->envc
= compat_count(envp
, bprm
->p
/ sizeof(compat_uptr_t
));
1527 if ((retval
= bprm
->envc
) < 0)
1530 retval
= security_bprm_alloc(bprm
);
1534 retval
= prepare_binprm(bprm
);
1538 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1542 bprm
->exec
= bprm
->p
;
1543 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1547 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1551 retval
= search_binary_handler(bprm
, regs
);
1553 free_arg_pages(bprm
);
1555 /* execve success */
1556 security_bprm_free(bprm
);
1557 acct_update_integrals(current
);
1563 /* Something went wrong, return the inode and free the argument pages*/
1564 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
1565 struct page
* page
= bprm
->page
[i
];
1571 security_bprm_free(bprm
);
1579 allow_write_access(bprm
->file
);
1590 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1592 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1595 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1596 * 64-bit unsigned longs.
1599 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1600 unsigned long *fdset
)
1602 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1606 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1613 __get_user(l
, ufdset
);
1614 __get_user(h
, ufdset
+1);
1616 *fdset
++ = h
<< 32 | l
;
1620 __get_user(*fdset
, ufdset
);
1622 /* Tricky, must clear full unsigned long in the
1623 * kernel fdset at the end, this makes sure that
1626 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1632 void compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1633 unsigned long *fdset
)
1636 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1647 __put_user(l
, ufdset
);
1648 __put_user(h
, ufdset
+1);
1653 __put_user(*fdset
, ufdset
);
1658 * This is a virtual copy of sys_select from fs/select.c and probably
1659 * should be compared to it from time to time
1663 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1664 * like to be certain this leads to no problems. So I return
1665 * EINTR just for safety.
1667 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1668 * I'm trying ERESTARTNOHAND which restart only when you want to.
1670 #define MAX_SELECT_SECONDS \
1671 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1673 int compat_core_sys_select(int n
, compat_ulong_t __user
*inp
,
1674 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
, s64
*timeout
)
1678 int size
, max_fdset
, ret
= -EINVAL
;
1679 struct fdtable
*fdt
;
1684 /* max_fdset can increase, so grab it once to avoid race */
1686 fdt
= files_fdtable(current
->files
);
1687 max_fdset
= fdt
->max_fdset
;
1693 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1694 * since we used fdset we need to allocate memory in units of
1698 size
= FDS_BYTES(n
);
1699 bits
= kmalloc(6 * size
, GFP_KERNEL
);
1702 fds
.in
= (unsigned long *) bits
;
1703 fds
.out
= (unsigned long *) (bits
+ size
);
1704 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1705 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1706 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1707 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1709 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1710 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1711 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1713 zero_fd_set(n
, fds
.res_in
);
1714 zero_fd_set(n
, fds
.res_out
);
1715 zero_fd_set(n
, fds
.res_ex
);
1717 ret
= do_select(n
, &fds
, timeout
);
1722 ret
= -ERESTARTNOHAND
;
1723 if (signal_pending(current
))
1728 compat_set_fd_set(n
, inp
, fds
.res_in
);
1729 compat_set_fd_set(n
, outp
, fds
.res_out
);
1730 compat_set_fd_set(n
, exp
, fds
.res_ex
);
1738 asmlinkage
long compat_sys_select(int n
, compat_ulong_t __user
*inp
,
1739 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1740 struct compat_timeval __user
*tvp
)
1743 struct compat_timeval tv
;
1747 if (copy_from_user(&tv
, tvp
, sizeof(tv
)))
1750 if (tv
.tv_sec
< 0 || tv
.tv_usec
< 0)
1753 /* Cast to u64 to make GCC stop complaining */
1754 if ((u64
)tv
.tv_sec
>= (u64
)MAX_INT64_SECONDS
)
1755 timeout
= -1; /* infinite */
1757 timeout
= ROUND_UP(tv
.tv_usec
, 1000000/HZ
);
1758 timeout
+= tv
.tv_sec
* HZ
;
1762 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1765 struct compat_timeval rtv
;
1767 if (current
->personality
& STICKY_TIMEOUTS
)
1769 rtv
.tv_usec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
));
1770 rtv
.tv_sec
= timeout
;
1771 if (compat_timeval_compare(&rtv
, &tv
) >= 0)
1773 if (copy_to_user(tvp
, &rtv
, sizeof(rtv
))) {
1776 * If an application puts its timeval in read-only
1777 * memory, we don't want the Linux-specific update to
1778 * the timeval to cause a fault after the select has
1779 * completed successfully. However, because we're not
1780 * updating the timeval, we can't restart the system
1783 if (ret
== -ERESTARTNOHAND
)
1791 #ifdef TIF_RESTORE_SIGMASK
1792 asmlinkage
long compat_sys_pselect7(int n
, compat_ulong_t __user
*inp
,
1793 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1794 struct compat_timespec __user
*tsp
, compat_sigset_t __user
*sigmask
,
1795 compat_size_t sigsetsize
)
1797 compat_sigset_t ss32
;
1798 sigset_t ksigmask
, sigsaved
;
1799 s64 timeout
= MAX_SCHEDULE_TIMEOUT
;
1800 struct compat_timespec ts
;
1804 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1807 if (ts
.tv_sec
< 0 || ts
.tv_nsec
< 0)
1812 if (sigsetsize
!= sizeof(compat_sigset_t
))
1814 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1816 sigset_from_compat(&ksigmask
, &ss32
);
1818 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1819 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1824 if ((unsigned long)ts
.tv_sec
< MAX_SELECT_SECONDS
) {
1825 timeout
= ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1826 timeout
+= ts
.tv_sec
* (unsigned long)HZ
;
1830 ts
.tv_sec
-= MAX_SELECT_SECONDS
;
1831 timeout
= MAX_SELECT_SECONDS
* HZ
;
1835 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1837 } while (!ret
&& !timeout
&& tsp
&& (ts
.tv_sec
|| ts
.tv_nsec
));
1840 struct compat_timespec rts
;
1842 if (current
->personality
& STICKY_TIMEOUTS
)
1845 rts
.tv_sec
= timeout
/ HZ
;
1846 rts
.tv_nsec
= (timeout
% HZ
) * (NSEC_PER_SEC
/HZ
);
1847 if (rts
.tv_nsec
>= NSEC_PER_SEC
) {
1849 rts
.tv_nsec
-= NSEC_PER_SEC
;
1851 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1853 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1856 * If an application puts its timeval in read-only
1857 * memory, we don't want the Linux-specific update to
1858 * the timeval to cause a fault after the select has
1859 * completed successfully. However, because we're not
1860 * updating the timeval, we can't restart the system
1863 if (ret
== -ERESTARTNOHAND
)
1868 if (ret
== -ERESTARTNOHAND
) {
1870 * Don't restore the signal mask yet. Let do_signal() deliver
1871 * the signal on the way back to userspace, before the signal
1875 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1877 set_thread_flag(TIF_RESTORE_SIGMASK
);
1880 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1885 asmlinkage
long compat_sys_pselect6(int n
, compat_ulong_t __user
*inp
,
1886 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1887 struct compat_timespec __user
*tsp
, void __user
*sig
)
1889 compat_size_t sigsetsize
= 0;
1890 compat_uptr_t up
= 0;
1893 if (!access_ok(VERIFY_READ
, sig
,
1894 sizeof(compat_uptr_t
)+sizeof(compat_size_t
)) ||
1895 __get_user(up
, (compat_uptr_t __user
*)sig
) ||
1896 __get_user(sigsetsize
,
1897 (compat_size_t __user
*)(sig
+sizeof(up
))))
1900 return compat_sys_pselect7(n
, inp
, outp
, exp
, tsp
, compat_ptr(up
),
1904 asmlinkage
long compat_sys_ppoll(struct pollfd __user
*ufds
,
1905 unsigned int nfds
, struct compat_timespec __user
*tsp
,
1906 const compat_sigset_t __user
*sigmask
, compat_size_t sigsetsize
)
1908 compat_sigset_t ss32
;
1909 sigset_t ksigmask
, sigsaved
;
1910 struct compat_timespec ts
;
1915 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1918 /* We assume that ts.tv_sec is always lower than
1919 the number of seconds that can be expressed in
1920 an s64. Otherwise the compiler bitches at us */
1921 timeout
= ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1922 timeout
+= ts
.tv_sec
* HZ
;
1926 if (sigsetsize
!= sizeof(compat_sigset_t
))
1928 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1930 sigset_from_compat(&ksigmask
, &ss32
);
1932 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1933 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1936 ret
= do_sys_poll(ufds
, nfds
, &timeout
);
1938 /* We can restart this syscall, usually */
1939 if (ret
== -EINTR
) {
1941 * Don't restore the signal mask yet. Let do_signal() deliver
1942 * the signal on the way back to userspace, before the signal
1946 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1948 set_thread_flag(TIF_RESTORE_SIGMASK
);
1950 ret
= -ERESTARTNOHAND
;
1952 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1954 if (tsp
&& timeout
>= 0) {
1955 struct compat_timespec rts
;
1957 if (current
->personality
& STICKY_TIMEOUTS
)
1959 /* Yes, we know it's actually an s64, but it's also positive. */
1960 rts
.tv_nsec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
)) *
1962 rts
.tv_sec
= timeout
;
1963 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1965 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1968 * If an application puts its timeval in read-only
1969 * memory, we don't want the Linux-specific update to
1970 * the timeval to cause a fault after the select has
1971 * completed successfully. However, because we're not
1972 * updating the timeval, we can't restart the system
1975 if (ret
== -ERESTARTNOHAND
&& timeout
>= 0)
1982 #endif /* TIF_RESTORE_SIGMASK */
1984 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1985 /* Stuff for NFS server syscalls... */
1986 struct compat_nfsctl_svc
{
1991 struct compat_nfsctl_client
{
1992 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
1994 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
1997 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
2000 struct compat_nfsctl_export
{
2001 char ex32_client
[NFSCLNT_IDMAX
+1];
2002 char ex32_path
[NFS_MAXPATHLEN
+1];
2003 compat_dev_t ex32_dev
;
2004 compat_ino_t ex32_ino
;
2005 compat_int_t ex32_flags
;
2006 __compat_uid_t ex32_anon_uid
;
2007 __compat_gid_t ex32_anon_gid
;
2010 struct compat_nfsctl_fdparm
{
2011 struct sockaddr gd32_addr
;
2012 s8 gd32_path
[NFS_MAXPATHLEN
+1];
2013 compat_int_t gd32_version
;
2016 struct compat_nfsctl_fsparm
{
2017 struct sockaddr gd32_addr
;
2018 s8 gd32_path
[NFS_MAXPATHLEN
+1];
2019 compat_int_t gd32_maxlen
;
2022 struct compat_nfsctl_arg
{
2023 compat_int_t ca32_version
; /* safeguard */
2025 struct compat_nfsctl_svc u32_svc
;
2026 struct compat_nfsctl_client u32_client
;
2027 struct compat_nfsctl_export u32_export
;
2028 struct compat_nfsctl_fdparm u32_getfd
;
2029 struct compat_nfsctl_fsparm u32_getfs
;
2031 #define ca32_svc u.u32_svc
2032 #define ca32_client u.u32_client
2033 #define ca32_export u.u32_export
2034 #define ca32_getfd u.u32_getfd
2035 #define ca32_getfs u.u32_getfs
2038 union compat_nfsctl_res
{
2039 __u8 cr32_getfh
[NFS_FHSIZE
];
2040 struct knfsd_fh cr32_getfs
;
2043 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
,
2044 struct compat_nfsctl_arg __user
*arg
)
2046 if (!access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
)) ||
2047 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2048 __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
) ||
2049 __get_user(karg
->ca_svc
.svc_nthreads
,
2050 &arg
->ca32_svc
.svc32_nthreads
))
2055 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
,
2056 struct compat_nfsctl_arg __user
*arg
)
2058 if (!access_ok(VERIFY_READ
, &arg
->ca32_client
,
2059 sizeof(arg
->ca32_client
)) ||
2060 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2061 __copy_from_user(&karg
->ca_client
.cl_ident
[0],
2062 &arg
->ca32_client
.cl32_ident
[0],
2064 __get_user(karg
->ca_client
.cl_naddr
,
2065 &arg
->ca32_client
.cl32_naddr
) ||
2066 __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
2067 &arg
->ca32_client
.cl32_addrlist
[0],
2068 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
)) ||
2069 __get_user(karg
->ca_client
.cl_fhkeytype
,
2070 &arg
->ca32_client
.cl32_fhkeytype
) ||
2071 __get_user(karg
->ca_client
.cl_fhkeylen
,
2072 &arg
->ca32_client
.cl32_fhkeylen
) ||
2073 __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
2074 &arg
->ca32_client
.cl32_fhkey
[0],
2081 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
,
2082 struct compat_nfsctl_arg __user
*arg
)
2084 if (!access_ok(VERIFY_READ
, &arg
->ca32_export
,
2085 sizeof(arg
->ca32_export
)) ||
2086 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2087 __copy_from_user(&karg
->ca_export
.ex_client
[0],
2088 &arg
->ca32_export
.ex32_client
[0],
2090 __copy_from_user(&karg
->ca_export
.ex_path
[0],
2091 &arg
->ca32_export
.ex32_path
[0],
2093 __get_user(karg
->ca_export
.ex_dev
,
2094 &arg
->ca32_export
.ex32_dev
) ||
2095 __get_user(karg
->ca_export
.ex_ino
,
2096 &arg
->ca32_export
.ex32_ino
) ||
2097 __get_user(karg
->ca_export
.ex_flags
,
2098 &arg
->ca32_export
.ex32_flags
) ||
2099 __get_user(karg
->ca_export
.ex_anon_uid
,
2100 &arg
->ca32_export
.ex32_anon_uid
) ||
2101 __get_user(karg
->ca_export
.ex_anon_gid
,
2102 &arg
->ca32_export
.ex32_anon_gid
))
2104 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
2105 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
2110 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
,
2111 struct compat_nfsctl_arg __user
*arg
)
2113 if (!access_ok(VERIFY_READ
, &arg
->ca32_getfd
,
2114 sizeof(arg
->ca32_getfd
)) ||
2115 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2116 __copy_from_user(&karg
->ca_getfd
.gd_addr
,
2117 &arg
->ca32_getfd
.gd32_addr
,
2118 (sizeof(struct sockaddr
))) ||
2119 __copy_from_user(&karg
->ca_getfd
.gd_path
,
2120 &arg
->ca32_getfd
.gd32_path
,
2121 (NFS_MAXPATHLEN
+1)) ||
2122 __get_user(karg
->ca_getfd
.gd_version
,
2123 &arg
->ca32_getfd
.gd32_version
))
2129 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
,
2130 struct compat_nfsctl_arg __user
*arg
)
2132 if (!access_ok(VERIFY_READ
,&arg
->ca32_getfs
,sizeof(arg
->ca32_getfs
)) ||
2133 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2134 __copy_from_user(&karg
->ca_getfs
.gd_addr
,
2135 &arg
->ca32_getfs
.gd32_addr
,
2136 (sizeof(struct sockaddr
))) ||
2137 __copy_from_user(&karg
->ca_getfs
.gd_path
,
2138 &arg
->ca32_getfs
.gd32_path
,
2139 (NFS_MAXPATHLEN
+1)) ||
2140 __get_user(karg
->ca_getfs
.gd_maxlen
,
2141 &arg
->ca32_getfs
.gd32_maxlen
))
2147 /* This really doesn't need translations, we are only passing
2148 * back a union which contains opaque nfs file handle data.
2150 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
,
2151 union compat_nfsctl_res __user
*res
)
2155 err
= copy_to_user(res
, kres
, sizeof(*res
));
2157 return (err
) ? -EFAULT
: 0;
2160 asmlinkage
long compat_sys_nfsservctl(int cmd
,
2161 struct compat_nfsctl_arg __user
*arg
,
2162 union compat_nfsctl_res __user
*res
)
2164 struct nfsctl_arg
*karg
;
2165 union nfsctl_res
*kres
;
2169 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
2170 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
2171 if(!karg
|| !kres
) {
2178 err
= compat_nfs_svc_trans(karg
, arg
);
2181 case NFSCTL_ADDCLIENT
:
2182 err
= compat_nfs_clnt_trans(karg
, arg
);
2185 case NFSCTL_DELCLIENT
:
2186 err
= compat_nfs_clnt_trans(karg
, arg
);
2190 case NFSCTL_UNEXPORT
:
2191 err
= compat_nfs_exp_trans(karg
, arg
);
2195 err
= compat_nfs_getfd_trans(karg
, arg
);
2199 err
= compat_nfs_getfs_trans(karg
, arg
);
2212 /* The __user pointer casts are valid because of the set_fs() */
2213 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
2219 if((cmd
== NFSCTL_GETFD
) ||
2220 (cmd
== NFSCTL_GETFS
))
2221 err
= compat_nfs_getfh_res_trans(kres
, res
);
2229 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
2231 return sys_ni_syscall();