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>
50 #include <net/sock.h> /* siocdevprivate_ioctl */
52 #include <asm/uaccess.h>
53 #include <asm/mmu_context.h>
54 #include <asm/ioctls.h>
59 int compat_printk(const char *fmt
, ...)
66 ret
= vprintk(fmt
, ap
);
71 #include "read_write.h"
74 * Not all architectures have sys_utime, so implement this in terms
77 asmlinkage
long compat_sys_utime(char __user
*filename
, struct compat_utimbuf __user
*t
)
82 if (get_user(tv
[0].tv_sec
, &t
->actime
) ||
83 get_user(tv
[1].tv_sec
, &t
->modtime
))
88 return do_utimes(AT_FDCWD
, filename
, t
? tv
: NULL
);
91 asmlinkage
long compat_sys_futimesat(unsigned int dfd
, char __user
*filename
, struct compat_timeval __user
*t
)
96 if (get_user(tv
[0].tv_sec
, &t
[0].tv_sec
) ||
97 get_user(tv
[0].tv_usec
, &t
[0].tv_usec
) ||
98 get_user(tv
[1].tv_sec
, &t
[1].tv_sec
) ||
99 get_user(tv
[1].tv_usec
, &t
[1].tv_usec
))
102 return do_utimes(dfd
, filename
, t
? tv
: NULL
);
105 asmlinkage
long compat_sys_utimes(char __user
*filename
, struct compat_timeval __user
*t
)
107 return compat_sys_futimesat(AT_FDCWD
, filename
, t
);
110 asmlinkage
long compat_sys_newstat(char __user
* filename
,
111 struct compat_stat __user
*statbuf
)
114 int error
= vfs_stat_fd(AT_FDCWD
, filename
, &stat
);
117 error
= cp_compat_stat(&stat
, statbuf
);
121 asmlinkage
long compat_sys_newlstat(char __user
* filename
,
122 struct compat_stat __user
*statbuf
)
125 int error
= vfs_lstat_fd(AT_FDCWD
, filename
, &stat
);
128 error
= cp_compat_stat(&stat
, statbuf
);
132 #ifndef __ARCH_WANT_STAT64
133 asmlinkage
long compat_sys_newfstatat(unsigned int dfd
, char __user
*filename
,
134 struct compat_stat __user
*statbuf
, int flag
)
139 if ((flag
& ~AT_SYMLINK_NOFOLLOW
) != 0)
142 if (flag
& AT_SYMLINK_NOFOLLOW
)
143 error
= vfs_lstat_fd(dfd
, filename
, &stat
);
145 error
= vfs_stat_fd(dfd
, filename
, &stat
);
148 error
= cp_compat_stat(&stat
, statbuf
);
155 asmlinkage
long compat_sys_newfstat(unsigned int fd
,
156 struct compat_stat __user
* statbuf
)
159 int error
= vfs_fstat(fd
, &stat
);
162 error
= cp_compat_stat(&stat
, statbuf
);
166 static int put_compat_statfs(struct compat_statfs __user
*ubuf
, struct kstatfs
*kbuf
)
169 if (sizeof ubuf
->f_blocks
== 4) {
170 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
171 0xffffffff00000000ULL
)
173 /* f_files and f_ffree may be -1; it's okay
174 * to stuff that into 32 bits */
175 if (kbuf
->f_files
!= 0xffffffffffffffffULL
176 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
178 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
179 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
182 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
183 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
184 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
185 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
186 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
187 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
188 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
189 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
190 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
191 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
192 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
193 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
) ||
194 __put_user(0, &ubuf
->f_spare
[0]) ||
195 __put_user(0, &ubuf
->f_spare
[1]) ||
196 __put_user(0, &ubuf
->f_spare
[2]) ||
197 __put_user(0, &ubuf
->f_spare
[3]) ||
198 __put_user(0, &ubuf
->f_spare
[4]))
204 * The following statfs calls are copies of code from fs/open.c and
205 * should be checked against those from time to time
207 asmlinkage
long compat_sys_statfs(const char __user
*path
, struct compat_statfs __user
*buf
)
212 error
= user_path_walk(path
, &nd
);
215 error
= vfs_statfs(nd
.dentry
, &tmp
);
217 error
= put_compat_statfs(buf
, &tmp
);
223 asmlinkage
long compat_sys_fstatfs(unsigned int fd
, struct compat_statfs __user
*buf
)
233 error
= vfs_statfs(file
->f_dentry
, &tmp
);
235 error
= put_compat_statfs(buf
, &tmp
);
241 static int put_compat_statfs64(struct compat_statfs64 __user
*ubuf
, struct kstatfs
*kbuf
)
243 if (sizeof ubuf
->f_blocks
== 4) {
244 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
245 0xffffffff00000000ULL
)
247 /* f_files and f_ffree may be -1; it's okay
248 * to stuff that into 32 bits */
249 if (kbuf
->f_files
!= 0xffffffffffffffffULL
250 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
252 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
253 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
256 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
257 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
258 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
259 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
260 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
261 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
262 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
263 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
264 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
265 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
266 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
267 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
))
272 asmlinkage
long compat_sys_statfs64(const char __user
*path
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
277 if (sz
!= sizeof(*buf
))
280 error
= user_path_walk(path
, &nd
);
283 error
= vfs_statfs(nd
.dentry
, &tmp
);
285 error
= put_compat_statfs64(buf
, &tmp
);
291 asmlinkage
long compat_sys_fstatfs64(unsigned int fd
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
297 if (sz
!= sizeof(*buf
))
304 error
= vfs_statfs(file
->f_dentry
, &tmp
);
306 error
= put_compat_statfs64(buf
, &tmp
);
312 /* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */
314 #define IOCTL_HASHSIZE 256
315 static struct ioctl_trans
*ioctl32_hash_table
[IOCTL_HASHSIZE
];
317 static inline unsigned long ioctl32_hash(unsigned long cmd
)
319 return (((cmd
>> 6) ^ (cmd
>> 4) ^ cmd
)) % IOCTL_HASHSIZE
;
322 static void ioctl32_insert_translation(struct ioctl_trans
*trans
)
325 struct ioctl_trans
*t
;
327 hash
= ioctl32_hash (trans
->cmd
);
328 if (!ioctl32_hash_table
[hash
])
329 ioctl32_hash_table
[hash
] = trans
;
331 t
= ioctl32_hash_table
[hash
];
339 static int __init
init_sys32_ioctl(void)
343 for (i
= 0; i
< ioctl_table_size
; i
++) {
344 if (ioctl_start
[i
].next
!= 0) {
345 printk("ioctl translation %d bad\n",i
);
349 ioctl32_insert_translation(&ioctl_start
[i
]);
354 __initcall(init_sys32_ioctl
);
356 static void compat_ioctl_error(struct file
*filp
, unsigned int fd
,
357 unsigned int cmd
, unsigned long arg
)
363 /* find the name of the device. */
364 path
= (char *)__get_free_page(GFP_KERNEL
);
366 fn
= d_path(filp
->f_dentry
, filp
->f_vfsmnt
, path
, PAGE_SIZE
);
371 sprintf(buf
,"'%c'", (cmd
>>24) & 0x3f);
372 if (!isprint(buf
[1]))
373 sprintf(buf
, "%02x", buf
[1]);
374 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
375 "cmd(%08x){%s} arg(%08x) on %s\n",
376 current
->comm
, current
->pid
,
377 (int)fd
, (unsigned int)cmd
, buf
,
378 (unsigned int)arg
, fn
);
381 free_page((unsigned long)path
);
384 asmlinkage
long compat_sys_ioctl(unsigned int fd
, unsigned int cmd
,
389 struct ioctl_trans
*t
;
392 filp
= fget_light(fd
, &fput_needed
);
396 /* RED-PEN how should LSM module know it's handling 32bit? */
397 error
= security_file_ioctl(filp
, cmd
, arg
);
402 * To allow the compat_ioctl handlers to be self contained
403 * we need to check the common ioctls here first.
404 * Just handle them with the standard handlers below.
417 if (S_ISREG(filp
->f_dentry
->d_inode
->i_mode
))
422 if (filp
->f_op
&& filp
->f_op
->compat_ioctl
) {
423 error
= filp
->f_op
->compat_ioctl(filp
, cmd
, arg
);
424 if (error
!= -ENOIOCTLCMD
)
429 (!filp
->f_op
->ioctl
&& !filp
->f_op
->unlocked_ioctl
))
434 for (t
= ioctl32_hash_table
[ioctl32_hash(cmd
)]; t
; t
= t
->next
) {
439 if (S_ISSOCK(filp
->f_dentry
->d_inode
->i_mode
) &&
440 cmd
>= SIOCDEVPRIVATE
&& cmd
<= (SIOCDEVPRIVATE
+ 15)) {
441 error
= siocdevprivate_ioctl(fd
, cmd
, arg
);
446 compat_ioctl_error(filp
, fd
, cmd
, arg
);
455 error
= t
->handler(fd
, cmd
, arg
, filp
);
461 error
= vfs_ioctl(filp
, fd
, cmd
, arg
);
463 fput_light(filp
, fput_needed
);
468 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
470 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
471 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
472 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
473 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
474 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
475 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
480 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
482 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
483 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
484 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
485 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
486 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
487 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
492 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
493 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
495 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
496 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
497 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
498 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
499 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
500 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
506 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
507 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
509 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
510 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
511 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
512 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
513 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
514 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
520 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
531 ret
= get_compat_flock(&f
, compat_ptr(arg
));
536 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
538 if (cmd
== F_GETLK
&& ret
== 0) {
539 /* GETLK was successfule and we need to return the data...
540 * but it needs to fit in the compat structure.
541 * l_start shouldn't be too big, unless the original
542 * start + end is greater than COMPAT_OFF_T_MAX, in which
543 * case the app was asking for trouble, so we return
544 * -EOVERFLOW in that case.
545 * l_len could be too big, in which case we just truncate it,
546 * and only allow the app to see that part of the conflicting
547 * lock that might make sense to it anyway
550 if (f
.l_start
> COMPAT_OFF_T_MAX
)
552 if (f
.l_len
> COMPAT_OFF_T_MAX
)
553 f
.l_len
= COMPAT_OFF_T_MAX
;
555 ret
= put_compat_flock(&f
, compat_ptr(arg
));
562 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
567 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
568 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
571 if (cmd
== F_GETLK64
&& ret
== 0) {
572 /* need to return lock information - see above for commentary */
573 if (f
.l_start
> COMPAT_LOFF_T_MAX
)
575 if (f
.l_len
> COMPAT_LOFF_T_MAX
)
576 f
.l_len
= COMPAT_LOFF_T_MAX
;
578 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
583 ret
= sys_fcntl(fd
, cmd
, arg
);
589 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
592 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
594 return compat_sys_fcntl64(fd
, cmd
, arg
);
598 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
603 mm_segment_t oldfs
= get_fs();
604 if (unlikely(get_user(ctx64
, ctx32p
)))
608 /* The __user pointer cast is valid because of the set_fs() */
609 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
611 /* truncating is ok because it's a user address */
613 ret
= put_user((u32
) ctx64
, ctx32p
);
618 compat_sys_io_getevents(aio_context_t ctx_id
,
619 unsigned long min_nr
,
621 struct io_event __user
*events
,
622 struct compat_timespec __user
*timeout
)
626 struct timespec __user
*ut
= NULL
;
629 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
630 nr
* sizeof(struct io_event
))))
633 if (get_compat_timespec(&t
, timeout
))
636 ut
= compat_alloc_user_space(sizeof(*ut
));
637 if (copy_to_user(ut
, &t
, sizeof(t
)) )
640 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
646 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
651 for (i
= 0; i
< nr
; ++i
) {
652 if (get_user(uptr
, ptr32
+ i
))
654 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
660 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
663 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
665 struct iocb __user
* __user
*iocb64
;
668 if (unlikely(nr
< 0))
671 if (nr
> MAX_AIO_SUBMITS
)
672 nr
= MAX_AIO_SUBMITS
;
674 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
675 ret
= copy_iocb(nr
, iocb
, iocb64
);
677 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
681 struct compat_ncp_mount_data
{
682 compat_int_t version
;
683 compat_uint_t ncp_fd
;
684 __compat_uid_t mounted_uid
;
685 compat_pid_t wdog_pid
;
686 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
687 compat_uint_t time_out
;
688 compat_uint_t retry_count
;
692 compat_mode_t file_mode
;
693 compat_mode_t dir_mode
;
696 struct compat_ncp_mount_data_v4
{
697 compat_int_t version
;
698 compat_ulong_t flags
;
699 compat_ulong_t mounted_uid
;
700 compat_long_t wdog_pid
;
701 compat_uint_t ncp_fd
;
702 compat_uint_t time_out
;
703 compat_uint_t retry_count
;
706 compat_ulong_t file_mode
;
707 compat_ulong_t dir_mode
;
710 static void *do_ncp_super_data_conv(void *raw_data
)
712 int version
= *(unsigned int *)raw_data
;
715 struct compat_ncp_mount_data
*c_n
= raw_data
;
716 struct ncp_mount_data
*n
= raw_data
;
718 n
->dir_mode
= c_n
->dir_mode
;
719 n
->file_mode
= c_n
->file_mode
;
722 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
723 n
->wdog_pid
= c_n
->wdog_pid
;
724 n
->mounted_uid
= c_n
->mounted_uid
;
725 } else if (version
== 4) {
726 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
727 struct ncp_mount_data_v4
*n
= raw_data
;
729 n
->dir_mode
= c_n
->dir_mode
;
730 n
->file_mode
= c_n
->file_mode
;
733 n
->retry_count
= c_n
->retry_count
;
734 n
->time_out
= c_n
->time_out
;
735 n
->ncp_fd
= c_n
->ncp_fd
;
736 n
->wdog_pid
= c_n
->wdog_pid
;
737 n
->mounted_uid
= c_n
->mounted_uid
;
738 n
->flags
= c_n
->flags
;
739 } else if (version
!= 5) {
746 struct compat_smb_mount_data
{
747 compat_int_t version
;
748 __compat_uid_t mounted_uid
;
751 compat_mode_t file_mode
;
752 compat_mode_t dir_mode
;
755 static void *do_smb_super_data_conv(void *raw_data
)
757 struct smb_mount_data
*s
= raw_data
;
758 struct compat_smb_mount_data
*c_s
= raw_data
;
760 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
762 s
->dir_mode
= c_s
->dir_mode
;
763 s
->file_mode
= c_s
->file_mode
;
766 s
->mounted_uid
= c_s
->mounted_uid
;
771 struct compat_nfs_string
{
776 static inline void compat_nfs_string(struct nfs_string
*dst
,
777 struct compat_nfs_string
*src
)
779 dst
->data
= compat_ptr(src
->data
);
783 struct compat_nfs4_mount_data_v1
{
784 compat_int_t version
;
789 compat_int_t retrans
;
790 compat_int_t acregmin
;
791 compat_int_t acregmax
;
792 compat_int_t acdirmin
;
793 compat_int_t acdirmax
;
794 struct compat_nfs_string client_addr
;
795 struct compat_nfs_string mnt_path
;
796 struct compat_nfs_string hostname
;
797 compat_uint_t host_addrlen
;
798 compat_uptr_t host_addr
;
800 compat_int_t auth_flavourlen
;
801 compat_uptr_t auth_flavours
;
804 static int do_nfs4_super_data_conv(void *raw_data
)
806 int version
= *(compat_uint_t
*) raw_data
;
809 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
810 struct nfs4_mount_data
*real
= raw_data
;
812 /* copy the fields backwards */
813 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
814 real
->auth_flavourlen
= raw
->auth_flavourlen
;
815 real
->proto
= raw
->proto
;
816 real
->host_addr
= compat_ptr(raw
->host_addr
);
817 real
->host_addrlen
= raw
->host_addrlen
;
818 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
819 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
820 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
821 real
->acdirmax
= raw
->acdirmax
;
822 real
->acdirmin
= raw
->acdirmin
;
823 real
->acregmax
= raw
->acregmax
;
824 real
->acregmin
= raw
->acregmin
;
825 real
->retrans
= raw
->retrans
;
826 real
->timeo
= raw
->timeo
;
827 real
->wsize
= raw
->wsize
;
828 real
->rsize
= raw
->rsize
;
829 real
->flags
= raw
->flags
;
830 real
->version
= raw
->version
;
839 #define SMBFS_NAME "smbfs"
840 #define NCPFS_NAME "ncpfs"
841 #define NFS4_NAME "nfs4"
843 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
844 char __user
* type
, unsigned long flags
,
847 unsigned long type_page
;
848 unsigned long data_page
;
849 unsigned long dev_page
;
853 retval
= copy_mount_options (type
, &type_page
);
857 dir_page
= getname(dir_name
);
858 retval
= PTR_ERR(dir_page
);
859 if (IS_ERR(dir_page
))
862 retval
= copy_mount_options (dev_name
, &dev_page
);
866 retval
= copy_mount_options (data
, &data_page
);
873 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
874 do_smb_super_data_conv((void *)data_page
);
875 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
876 do_ncp_super_data_conv((void *)data_page
);
877 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
878 if (do_nfs4_super_data_conv((void *) data_page
))
884 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
885 flags
, (void*)data_page
);
889 free_page(data_page
);
895 free_page(type_page
);
900 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
901 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
902 ~(sizeof(compat_long_t)-1))
904 struct compat_old_linux_dirent
{
905 compat_ulong_t d_ino
;
906 compat_ulong_t d_offset
;
907 unsigned short d_namlen
;
911 struct compat_readdir_callback
{
912 struct compat_old_linux_dirent __user
*dirent
;
916 static int compat_fillonedir(void *__buf
, const char *name
, int namlen
,
917 loff_t offset
, ino_t ino
, unsigned int d_type
)
919 struct compat_readdir_callback
*buf
= __buf
;
920 struct compat_old_linux_dirent __user
*dirent
;
925 dirent
= buf
->dirent
;
926 if (!access_ok(VERIFY_WRITE
, dirent
,
927 (unsigned long)(dirent
->d_name
+ namlen
+ 1) -
928 (unsigned long)dirent
))
930 if ( __put_user(ino
, &dirent
->d_ino
) ||
931 __put_user(offset
, &dirent
->d_offset
) ||
932 __put_user(namlen
, &dirent
->d_namlen
) ||
933 __copy_to_user(dirent
->d_name
, name
, namlen
) ||
934 __put_user(0, dirent
->d_name
+ namlen
))
938 buf
->result
= -EFAULT
;
942 asmlinkage
long compat_sys_old_readdir(unsigned int fd
,
943 struct compat_old_linux_dirent __user
*dirent
, unsigned int count
)
947 struct compat_readdir_callback buf
;
957 error
= vfs_readdir(file
, compat_fillonedir
, &buf
);
966 struct compat_linux_dirent
{
967 compat_ulong_t d_ino
;
968 compat_ulong_t d_off
;
969 unsigned short d_reclen
;
973 struct compat_getdents_callback
{
974 struct compat_linux_dirent __user
*current_dir
;
975 struct compat_linux_dirent __user
*previous
;
980 static int compat_filldir(void *__buf
, const char *name
, int namlen
,
981 loff_t offset
, ino_t ino
, unsigned int d_type
)
983 struct compat_linux_dirent __user
* dirent
;
984 struct compat_getdents_callback
*buf
= __buf
;
985 int reclen
= COMPAT_ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 2);
987 buf
->error
= -EINVAL
; /* only used if we fail.. */
988 if (reclen
> buf
->count
)
990 dirent
= buf
->previous
;
992 if (__put_user(offset
, &dirent
->d_off
))
995 dirent
= buf
->current_dir
;
996 if (__put_user(ino
, &dirent
->d_ino
))
998 if (__put_user(reclen
, &dirent
->d_reclen
))
1000 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1002 if (__put_user(0, dirent
->d_name
+ namlen
))
1004 if (__put_user(d_type
, (char __user
*) dirent
+ reclen
- 1))
1006 buf
->previous
= dirent
;
1007 dirent
= (void __user
*)dirent
+ reclen
;
1008 buf
->current_dir
= dirent
;
1009 buf
->count
-= reclen
;
1012 buf
->error
= -EFAULT
;
1016 asmlinkage
long compat_sys_getdents(unsigned int fd
,
1017 struct compat_linux_dirent __user
*dirent
, unsigned int count
)
1020 struct compat_linux_dirent __user
* lastdirent
;
1021 struct compat_getdents_callback buf
;
1025 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1033 buf
.current_dir
= dirent
;
1034 buf
.previous
= NULL
;
1038 error
= vfs_readdir(file
, compat_filldir
, &buf
);
1042 lastdirent
= buf
.previous
;
1044 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
1047 error
= count
- buf
.count
;
1056 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1057 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1059 struct compat_getdents_callback64
{
1060 struct linux_dirent64 __user
*current_dir
;
1061 struct linux_dirent64 __user
*previous
;
1066 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
1067 ino_t ino
, unsigned int d_type
)
1069 struct linux_dirent64 __user
*dirent
;
1070 struct compat_getdents_callback64
*buf
= __buf
;
1071 int jj
= NAME_OFFSET(dirent
);
1072 int reclen
= COMPAT_ROUND_UP64(jj
+ namlen
+ 1);
1075 buf
->error
= -EINVAL
; /* only used if we fail.. */
1076 if (reclen
> buf
->count
)
1078 dirent
= buf
->previous
;
1081 if (__put_user_unaligned(offset
, &dirent
->d_off
))
1084 dirent
= buf
->current_dir
;
1085 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
1088 if (__put_user_unaligned(off
, &dirent
->d_off
))
1090 if (__put_user(reclen
, &dirent
->d_reclen
))
1092 if (__put_user(d_type
, &dirent
->d_type
))
1094 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1096 if (__put_user(0, dirent
->d_name
+ namlen
))
1098 buf
->previous
= dirent
;
1099 dirent
= (void __user
*)dirent
+ reclen
;
1100 buf
->current_dir
= dirent
;
1101 buf
->count
-= reclen
;
1104 buf
->error
= -EFAULT
;
1108 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
1109 struct linux_dirent64 __user
* dirent
, unsigned int count
)
1112 struct linux_dirent64 __user
* lastdirent
;
1113 struct compat_getdents_callback64 buf
;
1117 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1125 buf
.current_dir
= dirent
;
1126 buf
.previous
= NULL
;
1130 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1134 lastdirent
= buf
.previous
;
1136 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1137 __put_user_unaligned(d_off
, &lastdirent
->d_off
);
1138 error
= count
- buf
.count
;
1146 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1148 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1149 const struct compat_iovec __user
*uvector
,
1150 unsigned long nr_segs
, loff_t
*pos
)
1152 compat_ssize_t tot_len
;
1153 struct iovec iovstack
[UIO_FASTIOV
];
1154 struct iovec
*iov
=iovstack
, *vector
;
1161 * SuS says "The readv() function *may* fail if the iovcnt argument
1162 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1163 * traditionally returned zero for zero segments, so...
1170 * First get the "struct iovec" from user memory and
1171 * verify all the pointers
1174 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1178 if (nr_segs
> UIO_FASTIOV
) {
1180 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1185 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1189 * Single unix specification:
1190 * We should -EINVAL if an element length is not >= 0 and fitting an
1191 * ssize_t. The total length is fitting an ssize_t
1193 * Be careful here because iov_len is a size_t not an ssize_t
1198 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1199 compat_ssize_t tmp
= tot_len
;
1203 if (__get_user(len
, &uvector
->iov_len
) ||
1204 __get_user(buf
, &uvector
->iov_base
)) {
1208 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1211 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1213 vector
->iov_base
= compat_ptr(buf
);
1214 vector
->iov_len
= (compat_size_t
) len
;
1223 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1227 ret
= security_file_permission(file
, type
== READ
? MAY_READ
:MAY_WRITE
);
1233 fn
= file
->f_op
->read
;
1234 fnv
= file
->f_op
->aio_read
;
1236 fn
= (io_fn_t
)file
->f_op
->write
;
1237 fnv
= file
->f_op
->aio_write
;
1241 ret
= do_sync_readv_writev(file
, iov
, nr_segs
, tot_len
,
1244 ret
= do_loop_readv_writev(file
, iov
, nr_segs
, pos
, fn
);
1247 if (iov
!= iovstack
)
1249 if ((ret
+ (type
== READ
)) > 0) {
1250 struct dentry
*dentry
= file
->f_dentry
;
1252 fsnotify_access(dentry
);
1254 fsnotify_modify(dentry
);
1260 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1263 ssize_t ret
= -EBADF
;
1269 if (!(file
->f_mode
& FMODE_READ
))
1273 if (!file
->f_op
|| (!file
->f_op
->aio_read
&& !file
->f_op
->read
))
1276 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1284 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1287 ssize_t ret
= -EBADF
;
1292 if (!(file
->f_mode
& FMODE_WRITE
))
1296 if (!file
->f_op
|| (!file
->f_op
->aio_write
&& !file
->f_op
->write
))
1299 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1307 compat_sys_vmsplice(int fd
, const struct compat_iovec __user
*iov32
,
1308 unsigned int nr_segs
, unsigned int flags
)
1312 if (nr_segs
> UIO_MAXIOV
)
1314 iov
= compat_alloc_user_space(nr_segs
* sizeof(struct iovec
));
1315 for (i
= 0; i
< nr_segs
; i
++) {
1316 struct compat_iovec v
;
1317 if (get_user(v
.iov_base
, &iov32
[i
].iov_base
) ||
1318 get_user(v
.iov_len
, &iov32
[i
].iov_len
) ||
1319 put_user(compat_ptr(v
.iov_base
), &iov
[i
].iov_base
) ||
1320 put_user(v
.iov_len
, &iov
[i
].iov_len
))
1323 return sys_vmsplice(fd
, iov
, nr_segs
, flags
);
1327 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1331 compat_sys_open(const char __user
*filename
, int flags
, int mode
)
1333 return do_sys_open(AT_FDCWD
, filename
, flags
, mode
);
1337 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1341 compat_sys_openat(unsigned int dfd
, const char __user
*filename
, int flags
, int mode
)
1343 return do_sys_open(dfd
, filename
, flags
, mode
);
1347 * compat_count() counts the number of arguments/envelopes. It is basically
1348 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1349 * and envp pointers.
1351 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1359 if (get_user(p
, argv
))
1372 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1373 * except that it works with 32 bit argv and envp pointers.
1375 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1376 struct linux_binprm
*bprm
)
1378 struct page
*kmapped_page
= NULL
;
1382 while (argc
-- > 0) {
1387 if (get_user(str
, argv
+argc
) ||
1388 !(len
= strnlen_user(compat_ptr(str
), bprm
->p
))) {
1393 if (bprm
->p
< len
) {
1399 /* XXX: add architecture specific overflow check here. */
1404 int offset
, bytes_to_copy
;
1407 offset
= pos
% PAGE_SIZE
;
1409 page
= bprm
->page
[i
];
1412 page
= alloc_page(GFP_HIGHUSER
);
1413 bprm
->page
[i
] = page
;
1421 if (page
!= kmapped_page
) {
1423 kunmap(kmapped_page
);
1424 kmapped_page
= page
;
1425 kaddr
= kmap(kmapped_page
);
1428 memset(kaddr
, 0, offset
);
1429 bytes_to_copy
= PAGE_SIZE
- offset
;
1430 if (bytes_to_copy
> len
) {
1431 bytes_to_copy
= len
;
1433 memset(kaddr
+offset
+len
, 0,
1434 PAGE_SIZE
-offset
-len
);
1436 err
= copy_from_user(kaddr
+offset
, compat_ptr(str
),
1443 pos
+= bytes_to_copy
;
1444 str
+= bytes_to_copy
;
1445 len
-= bytes_to_copy
;
1451 kunmap(kmapped_page
);
1457 #define free_arg_pages(bprm) do { } while (0)
1461 static inline void free_arg_pages(struct linux_binprm
*bprm
)
1465 for (i
= 0; i
< MAX_ARG_PAGES
; i
++) {
1467 __free_page(bprm
->page
[i
]);
1468 bprm
->page
[i
] = NULL
;
1472 #endif /* CONFIG_MMU */
1475 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1476 * that it processes 32 bit argv and envp pointers.
1478 int compat_do_execve(char * filename
,
1479 compat_uptr_t __user
*argv
,
1480 compat_uptr_t __user
*envp
,
1481 struct pt_regs
* regs
)
1483 struct linux_binprm
*bprm
;
1489 bprm
= kzalloc(sizeof(*bprm
), GFP_KERNEL
);
1493 file
= open_exec(filename
);
1494 retval
= PTR_ERR(file
);
1500 bprm
->p
= PAGE_SIZE
*MAX_ARG_PAGES
-sizeof(void *);
1502 bprm
->filename
= filename
;
1503 bprm
->interp
= filename
;
1504 bprm
->mm
= mm_alloc();
1509 retval
= init_new_context(current
, bprm
->mm
);
1513 bprm
->argc
= compat_count(argv
, bprm
->p
/ sizeof(compat_uptr_t
));
1514 if ((retval
= bprm
->argc
) < 0)
1517 bprm
->envc
= compat_count(envp
, bprm
->p
/ sizeof(compat_uptr_t
));
1518 if ((retval
= bprm
->envc
) < 0)
1521 retval
= security_bprm_alloc(bprm
);
1525 retval
= prepare_binprm(bprm
);
1529 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1533 bprm
->exec
= bprm
->p
;
1534 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1538 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1542 retval
= search_binary_handler(bprm
, regs
);
1544 free_arg_pages(bprm
);
1546 /* execve success */
1547 security_bprm_free(bprm
);
1548 acct_update_integrals(current
);
1554 /* Something went wrong, return the inode and free the argument pages*/
1555 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
1556 struct page
* page
= bprm
->page
[i
];
1562 security_bprm_free(bprm
);
1570 allow_write_access(bprm
->file
);
1581 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1583 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1586 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1587 * 64-bit unsigned longs.
1590 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1591 unsigned long *fdset
)
1593 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1597 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1604 __get_user(l
, ufdset
);
1605 __get_user(h
, ufdset
+1);
1607 *fdset
++ = h
<< 32 | l
;
1611 __get_user(*fdset
, ufdset
);
1613 /* Tricky, must clear full unsigned long in the
1614 * kernel fdset at the end, this makes sure that
1617 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1623 void compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1624 unsigned long *fdset
)
1627 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1638 __put_user(l
, ufdset
);
1639 __put_user(h
, ufdset
+1);
1644 __put_user(*fdset
, ufdset
);
1649 * This is a virtual copy of sys_select from fs/select.c and probably
1650 * should be compared to it from time to time
1654 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1655 * like to be certain this leads to no problems. So I return
1656 * EINTR just for safety.
1658 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1659 * I'm trying ERESTARTNOHAND which restart only when you want to.
1661 #define MAX_SELECT_SECONDS \
1662 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1664 int compat_core_sys_select(int n
, compat_ulong_t __user
*inp
,
1665 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
, s64
*timeout
)
1669 int size
, max_fdset
, ret
= -EINVAL
;
1670 struct fdtable
*fdt
;
1675 /* max_fdset can increase, so grab it once to avoid race */
1677 fdt
= files_fdtable(current
->files
);
1678 max_fdset
= fdt
->max_fdset
;
1684 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1685 * since we used fdset we need to allocate memory in units of
1689 size
= FDS_BYTES(n
);
1690 bits
= kmalloc(6 * size
, GFP_KERNEL
);
1693 fds
.in
= (unsigned long *) bits
;
1694 fds
.out
= (unsigned long *) (bits
+ size
);
1695 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1696 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1697 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1698 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1700 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1701 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1702 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1704 zero_fd_set(n
, fds
.res_in
);
1705 zero_fd_set(n
, fds
.res_out
);
1706 zero_fd_set(n
, fds
.res_ex
);
1708 ret
= do_select(n
, &fds
, timeout
);
1713 ret
= -ERESTARTNOHAND
;
1714 if (signal_pending(current
))
1719 compat_set_fd_set(n
, inp
, fds
.res_in
);
1720 compat_set_fd_set(n
, outp
, fds
.res_out
);
1721 compat_set_fd_set(n
, exp
, fds
.res_ex
);
1729 asmlinkage
long compat_sys_select(int n
, compat_ulong_t __user
*inp
,
1730 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1731 struct compat_timeval __user
*tvp
)
1734 struct compat_timeval tv
;
1738 if (copy_from_user(&tv
, tvp
, sizeof(tv
)))
1741 if (tv
.tv_sec
< 0 || tv
.tv_usec
< 0)
1744 /* Cast to u64 to make GCC stop complaining */
1745 if ((u64
)tv
.tv_sec
>= (u64
)MAX_INT64_SECONDS
)
1746 timeout
= -1; /* infinite */
1748 timeout
= ROUND_UP(tv
.tv_usec
, 1000000/HZ
);
1749 timeout
+= tv
.tv_sec
* HZ
;
1753 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1756 struct compat_timeval rtv
;
1758 if (current
->personality
& STICKY_TIMEOUTS
)
1760 rtv
.tv_usec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
));
1761 rtv
.tv_sec
= timeout
;
1762 if (compat_timeval_compare(&rtv
, &tv
) >= 0)
1764 if (copy_to_user(tvp
, &rtv
, sizeof(rtv
))) {
1767 * If an application puts its timeval in read-only
1768 * memory, we don't want the Linux-specific update to
1769 * the timeval to cause a fault after the select has
1770 * completed successfully. However, because we're not
1771 * updating the timeval, we can't restart the system
1774 if (ret
== -ERESTARTNOHAND
)
1782 #ifdef TIF_RESTORE_SIGMASK
1783 asmlinkage
long compat_sys_pselect7(int n
, compat_ulong_t __user
*inp
,
1784 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1785 struct compat_timespec __user
*tsp
, compat_sigset_t __user
*sigmask
,
1786 compat_size_t sigsetsize
)
1788 compat_sigset_t ss32
;
1789 sigset_t ksigmask
, sigsaved
;
1790 s64 timeout
= MAX_SCHEDULE_TIMEOUT
;
1791 struct compat_timespec ts
;
1795 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1798 if (ts
.tv_sec
< 0 || ts
.tv_nsec
< 0)
1803 if (sigsetsize
!= sizeof(compat_sigset_t
))
1805 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1807 sigset_from_compat(&ksigmask
, &ss32
);
1809 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1810 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1815 if ((unsigned long)ts
.tv_sec
< MAX_SELECT_SECONDS
) {
1816 timeout
= ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1817 timeout
+= ts
.tv_sec
* (unsigned long)HZ
;
1821 ts
.tv_sec
-= MAX_SELECT_SECONDS
;
1822 timeout
= MAX_SELECT_SECONDS
* HZ
;
1826 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1828 } while (!ret
&& !timeout
&& tsp
&& (ts
.tv_sec
|| ts
.tv_nsec
));
1830 if (ret
== 0 && tsp
&& !(current
->personality
& STICKY_TIMEOUTS
)) {
1831 struct compat_timespec rts
;
1833 rts
.tv_sec
= timeout
/ HZ
;
1834 rts
.tv_nsec
= (timeout
% HZ
) * (NSEC_PER_SEC
/HZ
);
1835 if (rts
.tv_nsec
>= NSEC_PER_SEC
) {
1837 rts
.tv_nsec
-= NSEC_PER_SEC
;
1839 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1841 if (copy_to_user(tsp
, &rts
, sizeof(rts
)))
1845 if (ret
== -ERESTARTNOHAND
) {
1847 * Don't restore the signal mask yet. Let do_signal() deliver
1848 * the signal on the way back to userspace, before the signal
1852 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1854 set_thread_flag(TIF_RESTORE_SIGMASK
);
1857 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1862 asmlinkage
long compat_sys_pselect6(int n
, compat_ulong_t __user
*inp
,
1863 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1864 struct compat_timespec __user
*tsp
, void __user
*sig
)
1866 compat_size_t sigsetsize
= 0;
1867 compat_uptr_t up
= 0;
1870 if (!access_ok(VERIFY_READ
, sig
,
1871 sizeof(compat_uptr_t
)+sizeof(compat_size_t
)) ||
1872 __get_user(up
, (compat_uptr_t __user
*)sig
) ||
1873 __get_user(sigsetsize
,
1874 (compat_size_t __user
*)(sig
+sizeof(up
))))
1877 return compat_sys_pselect7(n
, inp
, outp
, exp
, tsp
, compat_ptr(up
),
1881 asmlinkage
long compat_sys_ppoll(struct pollfd __user
*ufds
,
1882 unsigned int nfds
, struct compat_timespec __user
*tsp
,
1883 const compat_sigset_t __user
*sigmask
, compat_size_t sigsetsize
)
1885 compat_sigset_t ss32
;
1886 sigset_t ksigmask
, sigsaved
;
1887 struct compat_timespec ts
;
1892 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1895 /* We assume that ts.tv_sec is always lower than
1896 the number of seconds that can be expressed in
1897 an s64. Otherwise the compiler bitches at us */
1898 timeout
= ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1899 timeout
+= ts
.tv_sec
* HZ
;
1903 if (sigsetsize
!= sizeof(compat_sigset_t
))
1905 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1907 sigset_from_compat(&ksigmask
, &ss32
);
1909 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1910 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1913 ret
= do_sys_poll(ufds
, nfds
, &timeout
);
1915 /* We can restart this syscall, usually */
1916 if (ret
== -EINTR
) {
1918 * Don't restore the signal mask yet. Let do_signal() deliver
1919 * the signal on the way back to userspace, before the signal
1923 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1925 set_thread_flag(TIF_RESTORE_SIGMASK
);
1927 ret
= -ERESTARTNOHAND
;
1929 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1931 if (tsp
&& timeout
>= 0) {
1932 struct compat_timespec rts
;
1934 if (current
->personality
& STICKY_TIMEOUTS
)
1936 /* Yes, we know it's actually an s64, but it's also positive. */
1937 rts
.tv_nsec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
)) *
1939 rts
.tv_sec
= timeout
;
1940 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1942 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1945 * If an application puts its timeval in read-only
1946 * memory, we don't want the Linux-specific update to
1947 * the timeval to cause a fault after the select has
1948 * completed successfully. However, because we're not
1949 * updating the timeval, we can't restart the system
1952 if (ret
== -ERESTARTNOHAND
&& timeout
>= 0)
1959 #endif /* TIF_RESTORE_SIGMASK */
1961 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1962 /* Stuff for NFS server syscalls... */
1963 struct compat_nfsctl_svc
{
1968 struct compat_nfsctl_client
{
1969 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
1971 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
1974 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
1977 struct compat_nfsctl_export
{
1978 char ex32_client
[NFSCLNT_IDMAX
+1];
1979 char ex32_path
[NFS_MAXPATHLEN
+1];
1980 compat_dev_t ex32_dev
;
1981 compat_ino_t ex32_ino
;
1982 compat_int_t ex32_flags
;
1983 __compat_uid_t ex32_anon_uid
;
1984 __compat_gid_t ex32_anon_gid
;
1987 struct compat_nfsctl_fdparm
{
1988 struct sockaddr gd32_addr
;
1989 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1990 compat_int_t gd32_version
;
1993 struct compat_nfsctl_fsparm
{
1994 struct sockaddr gd32_addr
;
1995 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1996 compat_int_t gd32_maxlen
;
1999 struct compat_nfsctl_arg
{
2000 compat_int_t ca32_version
; /* safeguard */
2002 struct compat_nfsctl_svc u32_svc
;
2003 struct compat_nfsctl_client u32_client
;
2004 struct compat_nfsctl_export u32_export
;
2005 struct compat_nfsctl_fdparm u32_getfd
;
2006 struct compat_nfsctl_fsparm u32_getfs
;
2008 #define ca32_svc u.u32_svc
2009 #define ca32_client u.u32_client
2010 #define ca32_export u.u32_export
2011 #define ca32_getfd u.u32_getfd
2012 #define ca32_getfs u.u32_getfs
2015 union compat_nfsctl_res
{
2016 __u8 cr32_getfh
[NFS_FHSIZE
];
2017 struct knfsd_fh cr32_getfs
;
2020 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
,
2021 struct compat_nfsctl_arg __user
*arg
)
2023 if (!access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
)) ||
2024 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2025 __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
) ||
2026 __get_user(karg
->ca_svc
.svc_nthreads
,
2027 &arg
->ca32_svc
.svc32_nthreads
))
2032 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
,
2033 struct compat_nfsctl_arg __user
*arg
)
2035 if (!access_ok(VERIFY_READ
, &arg
->ca32_client
,
2036 sizeof(arg
->ca32_client
)) ||
2037 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2038 __copy_from_user(&karg
->ca_client
.cl_ident
[0],
2039 &arg
->ca32_client
.cl32_ident
[0],
2041 __get_user(karg
->ca_client
.cl_naddr
,
2042 &arg
->ca32_client
.cl32_naddr
) ||
2043 __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
2044 &arg
->ca32_client
.cl32_addrlist
[0],
2045 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
)) ||
2046 __get_user(karg
->ca_client
.cl_fhkeytype
,
2047 &arg
->ca32_client
.cl32_fhkeytype
) ||
2048 __get_user(karg
->ca_client
.cl_fhkeylen
,
2049 &arg
->ca32_client
.cl32_fhkeylen
) ||
2050 __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
2051 &arg
->ca32_client
.cl32_fhkey
[0],
2058 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
,
2059 struct compat_nfsctl_arg __user
*arg
)
2061 if (!access_ok(VERIFY_READ
, &arg
->ca32_export
,
2062 sizeof(arg
->ca32_export
)) ||
2063 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2064 __copy_from_user(&karg
->ca_export
.ex_client
[0],
2065 &arg
->ca32_export
.ex32_client
[0],
2067 __copy_from_user(&karg
->ca_export
.ex_path
[0],
2068 &arg
->ca32_export
.ex32_path
[0],
2070 __get_user(karg
->ca_export
.ex_dev
,
2071 &arg
->ca32_export
.ex32_dev
) ||
2072 __get_user(karg
->ca_export
.ex_ino
,
2073 &arg
->ca32_export
.ex32_ino
) ||
2074 __get_user(karg
->ca_export
.ex_flags
,
2075 &arg
->ca32_export
.ex32_flags
) ||
2076 __get_user(karg
->ca_export
.ex_anon_uid
,
2077 &arg
->ca32_export
.ex32_anon_uid
) ||
2078 __get_user(karg
->ca_export
.ex_anon_gid
,
2079 &arg
->ca32_export
.ex32_anon_gid
))
2081 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
2082 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
2087 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
,
2088 struct compat_nfsctl_arg __user
*arg
)
2090 if (!access_ok(VERIFY_READ
, &arg
->ca32_getfd
,
2091 sizeof(arg
->ca32_getfd
)) ||
2092 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2093 __copy_from_user(&karg
->ca_getfd
.gd_addr
,
2094 &arg
->ca32_getfd
.gd32_addr
,
2095 (sizeof(struct sockaddr
))) ||
2096 __copy_from_user(&karg
->ca_getfd
.gd_path
,
2097 &arg
->ca32_getfd
.gd32_path
,
2098 (NFS_MAXPATHLEN
+1)) ||
2099 __get_user(karg
->ca_getfd
.gd_version
,
2100 &arg
->ca32_getfd
.gd32_version
))
2106 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
,
2107 struct compat_nfsctl_arg __user
*arg
)
2109 if (!access_ok(VERIFY_READ
,&arg
->ca32_getfs
,sizeof(arg
->ca32_getfs
)) ||
2110 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
2111 __copy_from_user(&karg
->ca_getfs
.gd_addr
,
2112 &arg
->ca32_getfs
.gd32_addr
,
2113 (sizeof(struct sockaddr
))) ||
2114 __copy_from_user(&karg
->ca_getfs
.gd_path
,
2115 &arg
->ca32_getfs
.gd32_path
,
2116 (NFS_MAXPATHLEN
+1)) ||
2117 __get_user(karg
->ca_getfs
.gd_maxlen
,
2118 &arg
->ca32_getfs
.gd32_maxlen
))
2124 /* This really doesn't need translations, we are only passing
2125 * back a union which contains opaque nfs file handle data.
2127 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
,
2128 union compat_nfsctl_res __user
*res
)
2132 err
= copy_to_user(res
, kres
, sizeof(*res
));
2134 return (err
) ? -EFAULT
: 0;
2137 asmlinkage
long compat_sys_nfsservctl(int cmd
,
2138 struct compat_nfsctl_arg __user
*arg
,
2139 union compat_nfsctl_res __user
*res
)
2141 struct nfsctl_arg
*karg
;
2142 union nfsctl_res
*kres
;
2146 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
2147 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
2148 if(!karg
|| !kres
) {
2155 err
= compat_nfs_svc_trans(karg
, arg
);
2158 case NFSCTL_ADDCLIENT
:
2159 err
= compat_nfs_clnt_trans(karg
, arg
);
2162 case NFSCTL_DELCLIENT
:
2163 err
= compat_nfs_clnt_trans(karg
, arg
);
2167 case NFSCTL_UNEXPORT
:
2168 err
= compat_nfs_exp_trans(karg
, arg
);
2172 err
= compat_nfs_getfd_trans(karg
, arg
);
2176 err
= compat_nfs_getfs_trans(karg
, arg
);
2189 /* The __user pointer casts are valid because of the set_fs() */
2190 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
2196 if((cmd
== NFSCTL_GETFD
) ||
2197 (cmd
== NFSCTL_GETFS
))
2198 err
= compat_nfs_getfh_res_trans(kres
, res
);
2206 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
2208 return sys_ni_syscall();