4 * Kernel compatibililty routines for e.g. 32 bit syscall support
7 * Copyright (C) 2002 Stephen Rothwell, IBM Corporation
8 * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
9 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
10 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
11 * Copyright (C) 2003 Pavel Machek (pavel@suse.cz)
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
18 #include <linux/kernel.h>
19 #include <linux/linkage.h>
20 #include <linux/compat.h>
21 #include <linux/errno.h>
22 #include <linux/time.h>
24 #include <linux/fcntl.h>
25 #include <linux/namei.h>
26 #include <linux/file.h>
27 #include <linux/fdtable.h>
28 #include <linux/vfs.h>
29 #include <linux/ioctl.h>
30 #include <linux/init.h>
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/security.h>
49 #include <linux/highmem.h>
50 #include <linux/signal.h>
51 #include <linux/poll.h>
53 #include <linux/eventpoll.h>
55 #include <asm/uaccess.h>
56 #include <asm/mmu_context.h>
57 #include <asm/ioctls.h>
62 int compat_printk(const char *fmt
, ...)
69 ret
= vprintk(fmt
, ap
);
74 #include "read_write.h"
77 * Not all architectures have sys_utime, so implement this in terms
80 asmlinkage
long compat_sys_utime(char __user
*filename
, struct compat_utimbuf __user
*t
)
82 struct timespec tv
[2];
85 if (get_user(tv
[0].tv_sec
, &t
->actime
) ||
86 get_user(tv
[1].tv_sec
, &t
->modtime
))
91 return do_utimes(AT_FDCWD
, filename
, t
? tv
: NULL
, 0);
94 asmlinkage
long compat_sys_utimensat(unsigned int dfd
, char __user
*filename
, struct compat_timespec __user
*t
, int flags
)
96 struct timespec tv
[2];
99 if (get_compat_timespec(&tv
[0], &t
[0]) ||
100 get_compat_timespec(&tv
[1], &t
[1]))
103 if ((tv
[0].tv_nsec
== UTIME_OMIT
|| tv
[0].tv_nsec
== UTIME_NOW
)
104 && tv
[0].tv_sec
!= 0)
106 if ((tv
[1].tv_nsec
== UTIME_OMIT
|| tv
[1].tv_nsec
== UTIME_NOW
)
107 && tv
[1].tv_sec
!= 0)
110 if (tv
[0].tv_nsec
== UTIME_OMIT
&& tv
[1].tv_nsec
== UTIME_OMIT
)
113 return do_utimes(dfd
, filename
, t
? tv
: NULL
, flags
);
116 asmlinkage
long compat_sys_futimesat(unsigned int dfd
, char __user
*filename
, struct compat_timeval __user
*t
)
118 struct timespec tv
[2];
121 if (get_user(tv
[0].tv_sec
, &t
[0].tv_sec
) ||
122 get_user(tv
[0].tv_nsec
, &t
[0].tv_usec
) ||
123 get_user(tv
[1].tv_sec
, &t
[1].tv_sec
) ||
124 get_user(tv
[1].tv_nsec
, &t
[1].tv_usec
))
126 if (tv
[0].tv_nsec
>= 1000000 || tv
[0].tv_nsec
< 0 ||
127 tv
[1].tv_nsec
>= 1000000 || tv
[1].tv_nsec
< 0)
129 tv
[0].tv_nsec
*= 1000;
130 tv
[1].tv_nsec
*= 1000;
132 return do_utimes(dfd
, filename
, t
? tv
: NULL
, 0);
135 asmlinkage
long compat_sys_utimes(char __user
*filename
, struct compat_timeval __user
*t
)
137 return compat_sys_futimesat(AT_FDCWD
, filename
, t
);
140 asmlinkage
long compat_sys_newstat(char __user
* filename
,
141 struct compat_stat __user
*statbuf
)
144 int error
= vfs_stat_fd(AT_FDCWD
, filename
, &stat
);
147 error
= cp_compat_stat(&stat
, statbuf
);
151 asmlinkage
long compat_sys_newlstat(char __user
* filename
,
152 struct compat_stat __user
*statbuf
)
155 int error
= vfs_lstat_fd(AT_FDCWD
, filename
, &stat
);
158 error
= cp_compat_stat(&stat
, statbuf
);
162 #ifndef __ARCH_WANT_STAT64
163 asmlinkage
long compat_sys_newfstatat(unsigned int dfd
, char __user
*filename
,
164 struct compat_stat __user
*statbuf
, int flag
)
169 if ((flag
& ~AT_SYMLINK_NOFOLLOW
) != 0)
172 if (flag
& AT_SYMLINK_NOFOLLOW
)
173 error
= vfs_lstat_fd(dfd
, filename
, &stat
);
175 error
= vfs_stat_fd(dfd
, filename
, &stat
);
178 error
= cp_compat_stat(&stat
, statbuf
);
185 asmlinkage
long compat_sys_newfstat(unsigned int fd
,
186 struct compat_stat __user
* statbuf
)
189 int error
= vfs_fstat(fd
, &stat
);
192 error
= cp_compat_stat(&stat
, statbuf
);
196 static int put_compat_statfs(struct compat_statfs __user
*ubuf
, struct kstatfs
*kbuf
)
199 if (sizeof ubuf
->f_blocks
== 4) {
200 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
|
201 kbuf
->f_bsize
| kbuf
->f_frsize
) & 0xffffffff00000000ULL
)
203 /* f_files and f_ffree may be -1; it's okay
204 * to stuff that into 32 bits */
205 if (kbuf
->f_files
!= 0xffffffffffffffffULL
206 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
208 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
209 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
212 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
213 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
214 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
215 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
216 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
217 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
218 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
219 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
220 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
221 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
222 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
223 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
) ||
224 __put_user(0, &ubuf
->f_spare
[0]) ||
225 __put_user(0, &ubuf
->f_spare
[1]) ||
226 __put_user(0, &ubuf
->f_spare
[2]) ||
227 __put_user(0, &ubuf
->f_spare
[3]) ||
228 __put_user(0, &ubuf
->f_spare
[4]))
234 * The following statfs calls are copies of code from fs/open.c and
235 * should be checked against those from time to time
237 asmlinkage
long compat_sys_statfs(const char __user
*pathname
, struct compat_statfs __user
*buf
)
242 error
= user_path(pathname
, &path
);
245 error
= vfs_statfs(path
.dentry
, &tmp
);
247 error
= put_compat_statfs(buf
, &tmp
);
253 asmlinkage
long compat_sys_fstatfs(unsigned int fd
, struct compat_statfs __user
*buf
)
263 error
= vfs_statfs(file
->f_path
.dentry
, &tmp
);
265 error
= put_compat_statfs(buf
, &tmp
);
271 static int put_compat_statfs64(struct compat_statfs64 __user
*ubuf
, struct kstatfs
*kbuf
)
273 if (sizeof ubuf
->f_blocks
== 4) {
274 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
|
275 kbuf
->f_bsize
| kbuf
->f_frsize
) & 0xffffffff00000000ULL
)
277 /* f_files and f_ffree may be -1; it's okay
278 * to stuff that into 32 bits */
279 if (kbuf
->f_files
!= 0xffffffffffffffffULL
280 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
282 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
283 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
286 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
287 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
288 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
289 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
290 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
291 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
292 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
293 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
294 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
295 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
296 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
297 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
))
302 asmlinkage
long compat_sys_statfs64(const char __user
*pathname
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
307 if (sz
!= sizeof(*buf
))
310 error
= user_path(pathname
, &path
);
313 error
= vfs_statfs(path
.dentry
, &tmp
);
315 error
= put_compat_statfs64(buf
, &tmp
);
321 asmlinkage
long compat_sys_fstatfs64(unsigned int fd
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
327 if (sz
!= sizeof(*buf
))
334 error
= vfs_statfs(file
->f_path
.dentry
, &tmp
);
336 error
= put_compat_statfs64(buf
, &tmp
);
342 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
344 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
345 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
346 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
347 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
348 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
349 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
354 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
356 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
357 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
358 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
359 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
360 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
361 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
366 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
367 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
369 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
370 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
371 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
372 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
373 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
374 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
380 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
381 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
383 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
384 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
385 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
386 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
387 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
388 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
394 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
405 ret
= get_compat_flock(&f
, compat_ptr(arg
));
410 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
412 if (cmd
== F_GETLK
&& ret
== 0) {
413 /* GETLK was successfule and we need to return the data...
414 * but it needs to fit in the compat structure.
415 * l_start shouldn't be too big, unless the original
416 * start + end is greater than COMPAT_OFF_T_MAX, in which
417 * case the app was asking for trouble, so we return
418 * -EOVERFLOW in that case.
419 * l_len could be too big, in which case we just truncate it,
420 * and only allow the app to see that part of the conflicting
421 * lock that might make sense to it anyway
424 if (f
.l_start
> COMPAT_OFF_T_MAX
)
426 if (f
.l_len
> COMPAT_OFF_T_MAX
)
427 f
.l_len
= COMPAT_OFF_T_MAX
;
429 ret
= put_compat_flock(&f
, compat_ptr(arg
));
436 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
441 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
442 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
445 if (cmd
== F_GETLK64
&& ret
== 0) {
446 /* need to return lock information - see above for commentary */
447 if (f
.l_start
> COMPAT_LOFF_T_MAX
)
449 if (f
.l_len
> COMPAT_LOFF_T_MAX
)
450 f
.l_len
= COMPAT_LOFF_T_MAX
;
452 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
457 ret
= sys_fcntl(fd
, cmd
, arg
);
463 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
466 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
468 return compat_sys_fcntl64(fd
, cmd
, arg
);
472 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
477 mm_segment_t oldfs
= get_fs();
478 if (unlikely(get_user(ctx64
, ctx32p
)))
482 /* The __user pointer cast is valid because of the set_fs() */
483 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
485 /* truncating is ok because it's a user address */
487 ret
= put_user((u32
) ctx64
, ctx32p
);
492 compat_sys_io_getevents(aio_context_t ctx_id
,
493 unsigned long min_nr
,
495 struct io_event __user
*events
,
496 struct compat_timespec __user
*timeout
)
500 struct timespec __user
*ut
= NULL
;
503 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
504 nr
* sizeof(struct io_event
))))
507 if (get_compat_timespec(&t
, timeout
))
510 ut
= compat_alloc_user_space(sizeof(*ut
));
511 if (copy_to_user(ut
, &t
, sizeof(t
)) )
514 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
520 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
525 for (i
= 0; i
< nr
; ++i
) {
526 if (get_user(uptr
, ptr32
+ i
))
528 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
534 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
537 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
539 struct iocb __user
* __user
*iocb64
;
542 if (unlikely(nr
< 0))
545 if (nr
> MAX_AIO_SUBMITS
)
546 nr
= MAX_AIO_SUBMITS
;
548 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
549 ret
= copy_iocb(nr
, iocb
, iocb64
);
551 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
555 struct compat_ncp_mount_data
{
556 compat_int_t version
;
557 compat_uint_t ncp_fd
;
558 __compat_uid_t mounted_uid
;
559 compat_pid_t wdog_pid
;
560 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
561 compat_uint_t time_out
;
562 compat_uint_t retry_count
;
566 compat_mode_t file_mode
;
567 compat_mode_t dir_mode
;
570 struct compat_ncp_mount_data_v4
{
571 compat_int_t version
;
572 compat_ulong_t flags
;
573 compat_ulong_t mounted_uid
;
574 compat_long_t wdog_pid
;
575 compat_uint_t ncp_fd
;
576 compat_uint_t time_out
;
577 compat_uint_t retry_count
;
580 compat_ulong_t file_mode
;
581 compat_ulong_t dir_mode
;
584 static void *do_ncp_super_data_conv(void *raw_data
)
586 int version
= *(unsigned int *)raw_data
;
589 struct compat_ncp_mount_data
*c_n
= raw_data
;
590 struct ncp_mount_data
*n
= raw_data
;
592 n
->dir_mode
= c_n
->dir_mode
;
593 n
->file_mode
= c_n
->file_mode
;
596 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
597 n
->wdog_pid
= c_n
->wdog_pid
;
598 n
->mounted_uid
= c_n
->mounted_uid
;
599 } else if (version
== 4) {
600 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
601 struct ncp_mount_data_v4
*n
= raw_data
;
603 n
->dir_mode
= c_n
->dir_mode
;
604 n
->file_mode
= c_n
->file_mode
;
607 n
->retry_count
= c_n
->retry_count
;
608 n
->time_out
= c_n
->time_out
;
609 n
->ncp_fd
= c_n
->ncp_fd
;
610 n
->wdog_pid
= c_n
->wdog_pid
;
611 n
->mounted_uid
= c_n
->mounted_uid
;
612 n
->flags
= c_n
->flags
;
613 } else if (version
!= 5) {
620 struct compat_smb_mount_data
{
621 compat_int_t version
;
622 __compat_uid_t mounted_uid
;
625 compat_mode_t file_mode
;
626 compat_mode_t dir_mode
;
629 static void *do_smb_super_data_conv(void *raw_data
)
631 struct smb_mount_data
*s
= raw_data
;
632 struct compat_smb_mount_data
*c_s
= raw_data
;
634 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
636 s
->dir_mode
= c_s
->dir_mode
;
637 s
->file_mode
= c_s
->file_mode
;
640 s
->mounted_uid
= c_s
->mounted_uid
;
645 struct compat_nfs_string
{
650 static inline void compat_nfs_string(struct nfs_string
*dst
,
651 struct compat_nfs_string
*src
)
653 dst
->data
= compat_ptr(src
->data
);
657 struct compat_nfs4_mount_data_v1
{
658 compat_int_t version
;
663 compat_int_t retrans
;
664 compat_int_t acregmin
;
665 compat_int_t acregmax
;
666 compat_int_t acdirmin
;
667 compat_int_t acdirmax
;
668 struct compat_nfs_string client_addr
;
669 struct compat_nfs_string mnt_path
;
670 struct compat_nfs_string hostname
;
671 compat_uint_t host_addrlen
;
672 compat_uptr_t host_addr
;
674 compat_int_t auth_flavourlen
;
675 compat_uptr_t auth_flavours
;
678 static int do_nfs4_super_data_conv(void *raw_data
)
680 int version
= *(compat_uint_t
*) raw_data
;
683 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
684 struct nfs4_mount_data
*real
= raw_data
;
686 /* copy the fields backwards */
687 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
688 real
->auth_flavourlen
= raw
->auth_flavourlen
;
689 real
->proto
= raw
->proto
;
690 real
->host_addr
= compat_ptr(raw
->host_addr
);
691 real
->host_addrlen
= raw
->host_addrlen
;
692 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
693 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
694 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
695 real
->acdirmax
= raw
->acdirmax
;
696 real
->acdirmin
= raw
->acdirmin
;
697 real
->acregmax
= raw
->acregmax
;
698 real
->acregmin
= raw
->acregmin
;
699 real
->retrans
= raw
->retrans
;
700 real
->timeo
= raw
->timeo
;
701 real
->wsize
= raw
->wsize
;
702 real
->rsize
= raw
->rsize
;
703 real
->flags
= raw
->flags
;
704 real
->version
= raw
->version
;
710 #define SMBFS_NAME "smbfs"
711 #define NCPFS_NAME "ncpfs"
712 #define NFS4_NAME "nfs4"
714 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
715 char __user
* type
, unsigned long flags
,
718 unsigned long type_page
;
719 unsigned long data_page
;
720 unsigned long dev_page
;
724 retval
= copy_mount_options (type
, &type_page
);
728 dir_page
= getname(dir_name
);
729 retval
= PTR_ERR(dir_page
);
730 if (IS_ERR(dir_page
))
733 retval
= copy_mount_options (dev_name
, &dev_page
);
737 retval
= copy_mount_options (data
, &data_page
);
743 if (type_page
&& data_page
) {
744 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
745 do_smb_super_data_conv((void *)data_page
);
746 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
747 do_ncp_super_data_conv((void *)data_page
);
748 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
749 if (do_nfs4_super_data_conv((void *) data_page
))
755 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
756 flags
, (void*)data_page
);
760 free_page(data_page
);
766 free_page(type_page
);
771 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
773 struct compat_old_linux_dirent
{
774 compat_ulong_t d_ino
;
775 compat_ulong_t d_offset
;
776 unsigned short d_namlen
;
780 struct compat_readdir_callback
{
781 struct compat_old_linux_dirent __user
*dirent
;
785 static int compat_fillonedir(void *__buf
, const char *name
, int namlen
,
786 loff_t offset
, u64 ino
, unsigned int d_type
)
788 struct compat_readdir_callback
*buf
= __buf
;
789 struct compat_old_linux_dirent __user
*dirent
;
790 compat_ulong_t d_ino
;
795 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
) {
796 buf
->result
= -EOVERFLOW
;
800 dirent
= buf
->dirent
;
801 if (!access_ok(VERIFY_WRITE
, dirent
,
802 (unsigned long)(dirent
->d_name
+ namlen
+ 1) -
803 (unsigned long)dirent
))
805 if ( __put_user(d_ino
, &dirent
->d_ino
) ||
806 __put_user(offset
, &dirent
->d_offset
) ||
807 __put_user(namlen
, &dirent
->d_namlen
) ||
808 __copy_to_user(dirent
->d_name
, name
, namlen
) ||
809 __put_user(0, dirent
->d_name
+ namlen
))
813 buf
->result
= -EFAULT
;
817 asmlinkage
long compat_sys_old_readdir(unsigned int fd
,
818 struct compat_old_linux_dirent __user
*dirent
, unsigned int count
)
822 struct compat_readdir_callback buf
;
832 error
= vfs_readdir(file
, compat_fillonedir
, &buf
);
841 struct compat_linux_dirent
{
842 compat_ulong_t d_ino
;
843 compat_ulong_t d_off
;
844 unsigned short d_reclen
;
848 struct compat_getdents_callback
{
849 struct compat_linux_dirent __user
*current_dir
;
850 struct compat_linux_dirent __user
*previous
;
855 static int compat_filldir(void *__buf
, const char *name
, int namlen
,
856 loff_t offset
, u64 ino
, unsigned int d_type
)
858 struct compat_linux_dirent __user
* dirent
;
859 struct compat_getdents_callback
*buf
= __buf
;
860 compat_ulong_t d_ino
;
861 int reclen
= ALIGN(NAME_OFFSET(dirent
) + namlen
+ 2, sizeof(compat_long_t
));
863 buf
->error
= -EINVAL
; /* only used if we fail.. */
864 if (reclen
> buf
->count
)
867 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
) {
868 buf
->error
= -EOVERFLOW
;
871 dirent
= buf
->previous
;
873 if (__put_user(offset
, &dirent
->d_off
))
876 dirent
= buf
->current_dir
;
877 if (__put_user(d_ino
, &dirent
->d_ino
))
879 if (__put_user(reclen
, &dirent
->d_reclen
))
881 if (copy_to_user(dirent
->d_name
, name
, namlen
))
883 if (__put_user(0, dirent
->d_name
+ namlen
))
885 if (__put_user(d_type
, (char __user
*) dirent
+ reclen
- 1))
887 buf
->previous
= dirent
;
888 dirent
= (void __user
*)dirent
+ reclen
;
889 buf
->current_dir
= dirent
;
890 buf
->count
-= reclen
;
893 buf
->error
= -EFAULT
;
897 asmlinkage
long compat_sys_getdents(unsigned int fd
,
898 struct compat_linux_dirent __user
*dirent
, unsigned int count
)
901 struct compat_linux_dirent __user
* lastdirent
;
902 struct compat_getdents_callback buf
;
906 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
914 buf
.current_dir
= dirent
;
919 error
= vfs_readdir(file
, compat_filldir
, &buf
);
923 lastdirent
= buf
.previous
;
925 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
928 error
= count
- buf
.count
;
937 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
939 struct compat_getdents_callback64
{
940 struct linux_dirent64 __user
*current_dir
;
941 struct linux_dirent64 __user
*previous
;
946 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
947 u64 ino
, unsigned int d_type
)
949 struct linux_dirent64 __user
*dirent
;
950 struct compat_getdents_callback64
*buf
= __buf
;
951 int jj
= NAME_OFFSET(dirent
);
952 int reclen
= ALIGN(jj
+ namlen
+ 1, sizeof(u64
));
955 buf
->error
= -EINVAL
; /* only used if we fail.. */
956 if (reclen
> buf
->count
)
958 dirent
= buf
->previous
;
961 if (__put_user_unaligned(offset
, &dirent
->d_off
))
964 dirent
= buf
->current_dir
;
965 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
968 if (__put_user_unaligned(off
, &dirent
->d_off
))
970 if (__put_user(reclen
, &dirent
->d_reclen
))
972 if (__put_user(d_type
, &dirent
->d_type
))
974 if (copy_to_user(dirent
->d_name
, name
, namlen
))
976 if (__put_user(0, dirent
->d_name
+ namlen
))
978 buf
->previous
= dirent
;
979 dirent
= (void __user
*)dirent
+ reclen
;
980 buf
->current_dir
= dirent
;
981 buf
->count
-= reclen
;
984 buf
->error
= -EFAULT
;
988 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
989 struct linux_dirent64 __user
* dirent
, unsigned int count
)
992 struct linux_dirent64 __user
* lastdirent
;
993 struct compat_getdents_callback64 buf
;
997 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1005 buf
.current_dir
= dirent
;
1006 buf
.previous
= NULL
;
1010 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1014 lastdirent
= buf
.previous
;
1016 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1018 if (__put_user_unaligned(d_off
, &lastdirent
->d_off
))
1020 error
= count
- buf
.count
;
1028 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1030 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1031 const struct compat_iovec __user
*uvector
,
1032 unsigned long nr_segs
, loff_t
*pos
)
1034 compat_ssize_t tot_len
;
1035 struct iovec iovstack
[UIO_FASTIOV
];
1036 struct iovec
*iov
=iovstack
, *vector
;
1043 * SuS says "The readv() function *may* fail if the iovcnt argument
1044 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1045 * traditionally returned zero for zero segments, so...
1052 * First get the "struct iovec" from user memory and
1053 * verify all the pointers
1056 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1060 if (nr_segs
> UIO_FASTIOV
) {
1062 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1067 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1071 * Single unix specification:
1072 * We should -EINVAL if an element length is not >= 0 and fitting an
1073 * ssize_t. The total length is fitting an ssize_t
1075 * Be careful here because iov_len is a size_t not an ssize_t
1080 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1081 compat_ssize_t tmp
= tot_len
;
1085 if (__get_user(len
, &uvector
->iov_len
) ||
1086 __get_user(buf
, &uvector
->iov_base
)) {
1090 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1093 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1095 vector
->iov_base
= compat_ptr(buf
);
1096 vector
->iov_len
= (compat_size_t
) len
;
1105 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1111 fn
= file
->f_op
->read
;
1112 fnv
= file
->f_op
->aio_read
;
1114 fn
= (io_fn_t
)file
->f_op
->write
;
1115 fnv
= file
->f_op
->aio_write
;
1119 ret
= do_sync_readv_writev(file
, iov
, nr_segs
, tot_len
,
1122 ret
= do_loop_readv_writev(file
, iov
, nr_segs
, pos
, fn
);
1125 if (iov
!= iovstack
)
1127 if ((ret
+ (type
== READ
)) > 0) {
1128 struct dentry
*dentry
= file
->f_path
.dentry
;
1130 fsnotify_access(dentry
);
1132 fsnotify_modify(dentry
);
1138 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1141 ssize_t ret
= -EBADF
;
1147 if (!(file
->f_mode
& FMODE_READ
))
1151 if (!file
->f_op
|| (!file
->f_op
->aio_read
&& !file
->f_op
->read
))
1154 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1162 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1165 ssize_t ret
= -EBADF
;
1170 if (!(file
->f_mode
& FMODE_WRITE
))
1174 if (!file
->f_op
|| (!file
->f_op
->aio_write
&& !file
->f_op
->write
))
1177 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1185 compat_sys_vmsplice(int fd
, const struct compat_iovec __user
*iov32
,
1186 unsigned int nr_segs
, unsigned int flags
)
1189 struct iovec __user
*iov
;
1190 if (nr_segs
> UIO_MAXIOV
)
1192 iov
= compat_alloc_user_space(nr_segs
* sizeof(struct iovec
));
1193 for (i
= 0; i
< nr_segs
; i
++) {
1194 struct compat_iovec v
;
1195 if (get_user(v
.iov_base
, &iov32
[i
].iov_base
) ||
1196 get_user(v
.iov_len
, &iov32
[i
].iov_len
) ||
1197 put_user(compat_ptr(v
.iov_base
), &iov
[i
].iov_base
) ||
1198 put_user(v
.iov_len
, &iov
[i
].iov_len
))
1201 return sys_vmsplice(fd
, iov
, nr_segs
, flags
);
1205 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1209 compat_sys_open(const char __user
*filename
, int flags
, int mode
)
1211 return do_sys_open(AT_FDCWD
, filename
, flags
, mode
);
1215 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1219 compat_sys_openat(unsigned int dfd
, const char __user
*filename
, int flags
, int mode
)
1221 return do_sys_open(dfd
, filename
, flags
, mode
);
1225 * compat_count() counts the number of arguments/envelopes. It is basically
1226 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1227 * and envp pointers.
1229 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1237 if (get_user(p
, argv
))
1250 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1251 * except that it works with 32 bit argv and envp pointers.
1253 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1254 struct linux_binprm
*bprm
)
1256 struct page
*kmapped_page
= NULL
;
1258 unsigned long kpos
= 0;
1261 while (argc
-- > 0) {
1266 if (get_user(str
, argv
+argc
) ||
1267 !(len
= strnlen_user(compat_ptr(str
), MAX_ARG_STRLEN
))) {
1272 if (len
> MAX_ARG_STRLEN
) {
1277 /* We're going to work our way backwords. */
1283 int offset
, bytes_to_copy
;
1285 offset
= pos
% PAGE_SIZE
;
1289 bytes_to_copy
= offset
;
1290 if (bytes_to_copy
> len
)
1291 bytes_to_copy
= len
;
1293 offset
-= bytes_to_copy
;
1294 pos
-= bytes_to_copy
;
1295 str
-= bytes_to_copy
;
1296 len
-= bytes_to_copy
;
1298 if (!kmapped_page
|| kpos
!= (pos
& PAGE_MASK
)) {
1301 #ifdef CONFIG_STACK_GROWSUP
1302 ret
= expand_stack_downwards(bprm
->vma
, pos
);
1304 /* We've exceed the stack rlimit. */
1309 ret
= get_user_pages(current
, bprm
->mm
, pos
,
1310 1, 1, 1, &page
, NULL
);
1312 /* We've exceed the stack rlimit. */
1318 flush_kernel_dcache_page(kmapped_page
);
1319 kunmap(kmapped_page
);
1320 put_page(kmapped_page
);
1322 kmapped_page
= page
;
1323 kaddr
= kmap(kmapped_page
);
1324 kpos
= pos
& PAGE_MASK
;
1325 flush_cache_page(bprm
->vma
, kpos
,
1326 page_to_pfn(kmapped_page
));
1328 if (copy_from_user(kaddr
+offset
, compat_ptr(str
),
1338 flush_kernel_dcache_page(kmapped_page
);
1339 kunmap(kmapped_page
);
1340 put_page(kmapped_page
);
1346 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1347 * that it processes 32 bit argv and envp pointers.
1349 int compat_do_execve(char * filename
,
1350 compat_uptr_t __user
*argv
,
1351 compat_uptr_t __user
*envp
,
1352 struct pt_regs
* regs
)
1354 struct linux_binprm
*bprm
;
1356 struct files_struct
*displaced
;
1359 retval
= unshare_files(&displaced
);
1364 bprm
= kzalloc(sizeof(*bprm
), GFP_KERNEL
);
1368 file
= open_exec(filename
);
1369 retval
= PTR_ERR(file
);
1376 bprm
->filename
= filename
;
1377 bprm
->interp
= filename
;
1379 retval
= bprm_mm_init(bprm
);
1383 bprm
->argc
= compat_count(argv
, MAX_ARG_STRINGS
);
1384 if ((retval
= bprm
->argc
) < 0)
1387 bprm
->envc
= compat_count(envp
, MAX_ARG_STRINGS
);
1388 if ((retval
= bprm
->envc
) < 0)
1391 retval
= security_bprm_alloc(bprm
);
1395 retval
= prepare_binprm(bprm
);
1399 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1403 bprm
->exec
= bprm
->p
;
1404 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1408 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1412 retval
= search_binary_handler(bprm
, regs
);
1414 /* execve success */
1415 security_bprm_free(bprm
);
1416 acct_update_integrals(current
);
1419 put_files_struct(displaced
);
1425 security_bprm_free(bprm
);
1433 allow_write_access(bprm
->file
);
1442 reset_files_struct(displaced
);
1447 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1450 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1451 * 64-bit unsigned longs.
1454 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1455 unsigned long *fdset
)
1457 nr
= DIV_ROUND_UP(nr
, __COMPAT_NFDBITS
);
1461 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1468 if (__get_user(l
, ufdset
) || __get_user(h
, ufdset
+1))
1471 *fdset
++ = h
<< 32 | l
;
1474 if (odd
&& __get_user(*fdset
, ufdset
))
1477 /* Tricky, must clear full unsigned long in the
1478 * kernel fdset at the end, this makes sure that
1481 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1487 int compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1488 unsigned long *fdset
)
1491 nr
= DIV_ROUND_UP(nr
, __COMPAT_NFDBITS
);
1502 if (__put_user(l
, ufdset
) || __put_user(h
, ufdset
+1))
1507 if (odd
&& __put_user(*fdset
, ufdset
))
1514 * This is a virtual copy of sys_select from fs/select.c and probably
1515 * should be compared to it from time to time
1519 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1520 * like to be certain this leads to no problems. So I return
1521 * EINTR just for safety.
1523 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1524 * I'm trying ERESTARTNOHAND which restart only when you want to.
1526 #define MAX_SELECT_SECONDS \
1527 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1529 int compat_core_sys_select(int n
, compat_ulong_t __user
*inp
,
1530 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
, s64
*timeout
)
1534 int size
, max_fds
, ret
= -EINVAL
;
1535 struct fdtable
*fdt
;
1536 long stack_fds
[SELECT_STACK_ALLOC
/sizeof(long)];
1541 /* max_fds can increase, so grab it once to avoid race */
1543 fdt
= files_fdtable(current
->files
);
1544 max_fds
= fdt
->max_fds
;
1550 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1551 * since we used fdset we need to allocate memory in units of
1554 size
= FDS_BYTES(n
);
1556 if (size
> sizeof(stack_fds
) / 6) {
1557 bits
= kmalloc(6 * size
, GFP_KERNEL
);
1562 fds
.in
= (unsigned long *) bits
;
1563 fds
.out
= (unsigned long *) (bits
+ size
);
1564 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1565 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1566 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1567 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1569 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1570 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1571 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1573 zero_fd_set(n
, fds
.res_in
);
1574 zero_fd_set(n
, fds
.res_out
);
1575 zero_fd_set(n
, fds
.res_ex
);
1577 ret
= do_select(n
, &fds
, timeout
);
1582 ret
= -ERESTARTNOHAND
;
1583 if (signal_pending(current
))
1588 if (compat_set_fd_set(n
, inp
, fds
.res_in
) ||
1589 compat_set_fd_set(n
, outp
, fds
.res_out
) ||
1590 compat_set_fd_set(n
, exp
, fds
.res_ex
))
1593 if (bits
!= stack_fds
)
1599 asmlinkage
long compat_sys_select(int n
, compat_ulong_t __user
*inp
,
1600 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1601 struct compat_timeval __user
*tvp
)
1604 struct compat_timeval tv
;
1608 if (copy_from_user(&tv
, tvp
, sizeof(tv
)))
1611 if (tv
.tv_sec
< 0 || tv
.tv_usec
< 0)
1614 /* Cast to u64 to make GCC stop complaining */
1615 if ((u64
)tv
.tv_sec
>= (u64
)MAX_INT64_SECONDS
)
1616 timeout
= -1; /* infinite */
1618 timeout
= DIV_ROUND_UP(tv
.tv_usec
, 1000000/HZ
);
1619 timeout
+= tv
.tv_sec
* HZ
;
1623 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1626 struct compat_timeval rtv
;
1628 if (current
->personality
& STICKY_TIMEOUTS
)
1630 rtv
.tv_usec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
));
1631 rtv
.tv_sec
= timeout
;
1632 if (compat_timeval_compare(&rtv
, &tv
) >= 0)
1634 if (copy_to_user(tvp
, &rtv
, sizeof(rtv
))) {
1637 * If an application puts its timeval in read-only
1638 * memory, we don't want the Linux-specific update to
1639 * the timeval to cause a fault after the select has
1640 * completed successfully. However, because we're not
1641 * updating the timeval, we can't restart the system
1644 if (ret
== -ERESTARTNOHAND
)
1652 #ifdef HAVE_SET_RESTORE_SIGMASK
1653 static long do_compat_pselect(int n
, compat_ulong_t __user
*inp
,
1654 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1655 struct compat_timespec __user
*tsp
, compat_sigset_t __user
*sigmask
,
1656 compat_size_t sigsetsize
)
1658 compat_sigset_t ss32
;
1659 sigset_t ksigmask
, sigsaved
;
1660 s64 timeout
= MAX_SCHEDULE_TIMEOUT
;
1661 struct compat_timespec ts
;
1665 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1668 if (ts
.tv_sec
< 0 || ts
.tv_nsec
< 0)
1673 if (sigsetsize
!= sizeof(compat_sigset_t
))
1675 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1677 sigset_from_compat(&ksigmask
, &ss32
);
1679 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1680 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1685 if ((unsigned long)ts
.tv_sec
< MAX_SELECT_SECONDS
) {
1686 timeout
= DIV_ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1687 timeout
+= ts
.tv_sec
* (unsigned long)HZ
;
1691 ts
.tv_sec
-= MAX_SELECT_SECONDS
;
1692 timeout
= MAX_SELECT_SECONDS
* HZ
;
1696 ret
= compat_core_sys_select(n
, inp
, outp
, exp
, &timeout
);
1698 } while (!ret
&& !timeout
&& tsp
&& (ts
.tv_sec
|| ts
.tv_nsec
));
1701 struct compat_timespec rts
;
1703 if (current
->personality
& STICKY_TIMEOUTS
)
1706 rts
.tv_sec
= timeout
/ HZ
;
1707 rts
.tv_nsec
= (timeout
% HZ
) * (NSEC_PER_SEC
/HZ
);
1708 if (rts
.tv_nsec
>= NSEC_PER_SEC
) {
1710 rts
.tv_nsec
-= NSEC_PER_SEC
;
1712 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1714 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1717 * If an application puts its timeval in read-only
1718 * memory, we don't want the Linux-specific update to
1719 * the timeval to cause a fault after the select has
1720 * completed successfully. However, because we're not
1721 * updating the timeval, we can't restart the system
1724 if (ret
== -ERESTARTNOHAND
)
1729 if (ret
== -ERESTARTNOHAND
) {
1731 * Don't restore the signal mask yet. Let do_signal() deliver
1732 * the signal on the way back to userspace, before the signal
1736 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1738 set_restore_sigmask();
1741 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1746 asmlinkage
long compat_sys_pselect6(int n
, compat_ulong_t __user
*inp
,
1747 compat_ulong_t __user
*outp
, compat_ulong_t __user
*exp
,
1748 struct compat_timespec __user
*tsp
, void __user
*sig
)
1750 compat_size_t sigsetsize
= 0;
1751 compat_uptr_t up
= 0;
1754 if (!access_ok(VERIFY_READ
, sig
,
1755 sizeof(compat_uptr_t
)+sizeof(compat_size_t
)) ||
1756 __get_user(up
, (compat_uptr_t __user
*)sig
) ||
1757 __get_user(sigsetsize
,
1758 (compat_size_t __user
*)(sig
+sizeof(up
))))
1761 return do_compat_pselect(n
, inp
, outp
, exp
, tsp
, compat_ptr(up
),
1765 asmlinkage
long compat_sys_ppoll(struct pollfd __user
*ufds
,
1766 unsigned int nfds
, struct compat_timespec __user
*tsp
,
1767 const compat_sigset_t __user
*sigmask
, compat_size_t sigsetsize
)
1769 compat_sigset_t ss32
;
1770 sigset_t ksigmask
, sigsaved
;
1771 struct compat_timespec ts
;
1776 if (copy_from_user(&ts
, tsp
, sizeof(ts
)))
1779 /* We assume that ts.tv_sec is always lower than
1780 the number of seconds that can be expressed in
1781 an s64. Otherwise the compiler bitches at us */
1782 timeout
= DIV_ROUND_UP(ts
.tv_nsec
, 1000000000/HZ
);
1783 timeout
+= ts
.tv_sec
* HZ
;
1787 if (sigsetsize
!= sizeof(compat_sigset_t
))
1789 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
1791 sigset_from_compat(&ksigmask
, &ss32
);
1793 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
1794 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
1797 ret
= do_sys_poll(ufds
, nfds
, &timeout
);
1799 /* We can restart this syscall, usually */
1800 if (ret
== -EINTR
) {
1802 * Don't restore the signal mask yet. Let do_signal() deliver
1803 * the signal on the way back to userspace, before the signal
1807 memcpy(¤t
->saved_sigmask
, &sigsaved
,
1809 set_restore_sigmask();
1811 ret
= -ERESTARTNOHAND
;
1813 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
1815 if (tsp
&& timeout
>= 0) {
1816 struct compat_timespec rts
;
1818 if (current
->personality
& STICKY_TIMEOUTS
)
1820 /* Yes, we know it's actually an s64, but it's also positive. */
1821 rts
.tv_nsec
= jiffies_to_usecs(do_div((*(u64
*)&timeout
), HZ
)) *
1823 rts
.tv_sec
= timeout
;
1824 if (compat_timespec_compare(&rts
, &ts
) >= 0)
1826 if (copy_to_user(tsp
, &rts
, sizeof(rts
))) {
1829 * If an application puts its timeval in read-only
1830 * memory, we don't want the Linux-specific update to
1831 * the timeval to cause a fault after the select has
1832 * completed successfully. However, because we're not
1833 * updating the timeval, we can't restart the system
1836 if (ret
== -ERESTARTNOHAND
&& timeout
>= 0)
1843 #endif /* HAVE_SET_RESTORE_SIGMASK */
1845 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1846 /* Stuff for NFS server syscalls... */
1847 struct compat_nfsctl_svc
{
1852 struct compat_nfsctl_client
{
1853 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
1855 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
1858 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
1861 struct compat_nfsctl_export
{
1862 char ex32_client
[NFSCLNT_IDMAX
+1];
1863 char ex32_path
[NFS_MAXPATHLEN
+1];
1864 compat_dev_t ex32_dev
;
1865 compat_ino_t ex32_ino
;
1866 compat_int_t ex32_flags
;
1867 __compat_uid_t ex32_anon_uid
;
1868 __compat_gid_t ex32_anon_gid
;
1871 struct compat_nfsctl_fdparm
{
1872 struct sockaddr gd32_addr
;
1873 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1874 compat_int_t gd32_version
;
1877 struct compat_nfsctl_fsparm
{
1878 struct sockaddr gd32_addr
;
1879 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1880 compat_int_t gd32_maxlen
;
1883 struct compat_nfsctl_arg
{
1884 compat_int_t ca32_version
; /* safeguard */
1886 struct compat_nfsctl_svc u32_svc
;
1887 struct compat_nfsctl_client u32_client
;
1888 struct compat_nfsctl_export u32_export
;
1889 struct compat_nfsctl_fdparm u32_getfd
;
1890 struct compat_nfsctl_fsparm u32_getfs
;
1892 #define ca32_svc u.u32_svc
1893 #define ca32_client u.u32_client
1894 #define ca32_export u.u32_export
1895 #define ca32_getfd u.u32_getfd
1896 #define ca32_getfs u.u32_getfs
1899 union compat_nfsctl_res
{
1900 __u8 cr32_getfh
[NFS_FHSIZE
];
1901 struct knfsd_fh cr32_getfs
;
1904 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
,
1905 struct compat_nfsctl_arg __user
*arg
)
1907 if (!access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
)) ||
1908 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
1909 __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
) ||
1910 __get_user(karg
->ca_svc
.svc_nthreads
,
1911 &arg
->ca32_svc
.svc32_nthreads
))
1916 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
,
1917 struct compat_nfsctl_arg __user
*arg
)
1919 if (!access_ok(VERIFY_READ
, &arg
->ca32_client
,
1920 sizeof(arg
->ca32_client
)) ||
1921 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
1922 __copy_from_user(&karg
->ca_client
.cl_ident
[0],
1923 &arg
->ca32_client
.cl32_ident
[0],
1925 __get_user(karg
->ca_client
.cl_naddr
,
1926 &arg
->ca32_client
.cl32_naddr
) ||
1927 __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
1928 &arg
->ca32_client
.cl32_addrlist
[0],
1929 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
)) ||
1930 __get_user(karg
->ca_client
.cl_fhkeytype
,
1931 &arg
->ca32_client
.cl32_fhkeytype
) ||
1932 __get_user(karg
->ca_client
.cl_fhkeylen
,
1933 &arg
->ca32_client
.cl32_fhkeylen
) ||
1934 __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
1935 &arg
->ca32_client
.cl32_fhkey
[0],
1942 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
,
1943 struct compat_nfsctl_arg __user
*arg
)
1945 if (!access_ok(VERIFY_READ
, &arg
->ca32_export
,
1946 sizeof(arg
->ca32_export
)) ||
1947 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
1948 __copy_from_user(&karg
->ca_export
.ex_client
[0],
1949 &arg
->ca32_export
.ex32_client
[0],
1951 __copy_from_user(&karg
->ca_export
.ex_path
[0],
1952 &arg
->ca32_export
.ex32_path
[0],
1954 __get_user(karg
->ca_export
.ex_dev
,
1955 &arg
->ca32_export
.ex32_dev
) ||
1956 __get_user(karg
->ca_export
.ex_ino
,
1957 &arg
->ca32_export
.ex32_ino
) ||
1958 __get_user(karg
->ca_export
.ex_flags
,
1959 &arg
->ca32_export
.ex32_flags
) ||
1960 __get_user(karg
->ca_export
.ex_anon_uid
,
1961 &arg
->ca32_export
.ex32_anon_uid
) ||
1962 __get_user(karg
->ca_export
.ex_anon_gid
,
1963 &arg
->ca32_export
.ex32_anon_gid
))
1965 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
1966 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
1971 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
,
1972 struct compat_nfsctl_arg __user
*arg
)
1974 if (!access_ok(VERIFY_READ
, &arg
->ca32_getfd
,
1975 sizeof(arg
->ca32_getfd
)) ||
1976 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
1977 __copy_from_user(&karg
->ca_getfd
.gd_addr
,
1978 &arg
->ca32_getfd
.gd32_addr
,
1979 (sizeof(struct sockaddr
))) ||
1980 __copy_from_user(&karg
->ca_getfd
.gd_path
,
1981 &arg
->ca32_getfd
.gd32_path
,
1982 (NFS_MAXPATHLEN
+1)) ||
1983 __get_user(karg
->ca_getfd
.gd_version
,
1984 &arg
->ca32_getfd
.gd32_version
))
1990 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
,
1991 struct compat_nfsctl_arg __user
*arg
)
1993 if (!access_ok(VERIFY_READ
,&arg
->ca32_getfs
,sizeof(arg
->ca32_getfs
)) ||
1994 get_user(karg
->ca_version
, &arg
->ca32_version
) ||
1995 __copy_from_user(&karg
->ca_getfs
.gd_addr
,
1996 &arg
->ca32_getfs
.gd32_addr
,
1997 (sizeof(struct sockaddr
))) ||
1998 __copy_from_user(&karg
->ca_getfs
.gd_path
,
1999 &arg
->ca32_getfs
.gd32_path
,
2000 (NFS_MAXPATHLEN
+1)) ||
2001 __get_user(karg
->ca_getfs
.gd_maxlen
,
2002 &arg
->ca32_getfs
.gd32_maxlen
))
2008 /* This really doesn't need translations, we are only passing
2009 * back a union which contains opaque nfs file handle data.
2011 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
,
2012 union compat_nfsctl_res __user
*res
)
2016 err
= copy_to_user(res
, kres
, sizeof(*res
));
2018 return (err
) ? -EFAULT
: 0;
2021 asmlinkage
long compat_sys_nfsservctl(int cmd
,
2022 struct compat_nfsctl_arg __user
*arg
,
2023 union compat_nfsctl_res __user
*res
)
2025 struct nfsctl_arg
*karg
;
2026 union nfsctl_res
*kres
;
2030 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
2031 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
2032 if(!karg
|| !kres
) {
2039 err
= compat_nfs_svc_trans(karg
, arg
);
2042 case NFSCTL_ADDCLIENT
:
2043 err
= compat_nfs_clnt_trans(karg
, arg
);
2046 case NFSCTL_DELCLIENT
:
2047 err
= compat_nfs_clnt_trans(karg
, arg
);
2051 case NFSCTL_UNEXPORT
:
2052 err
= compat_nfs_exp_trans(karg
, arg
);
2056 err
= compat_nfs_getfd_trans(karg
, arg
);
2060 err
= compat_nfs_getfs_trans(karg
, arg
);
2073 /* The __user pointer casts are valid because of the set_fs() */
2074 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
2080 if((cmd
== NFSCTL_GETFD
) ||
2081 (cmd
== NFSCTL_GETFS
))
2082 err
= compat_nfs_getfh_res_trans(kres
, res
);
2090 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
2092 return sys_ni_syscall();
2098 #ifdef HAVE_SET_RESTORE_SIGMASK
2099 asmlinkage
long compat_sys_epoll_pwait(int epfd
,
2100 struct compat_epoll_event __user
*events
,
2101 int maxevents
, int timeout
,
2102 const compat_sigset_t __user
*sigmask
,
2103 compat_size_t sigsetsize
)
2106 compat_sigset_t csigmask
;
2107 sigset_t ksigmask
, sigsaved
;
2110 * If the caller wants a certain signal mask to be set during the wait,
2114 if (sigsetsize
!= sizeof(compat_sigset_t
))
2116 if (copy_from_user(&csigmask
, sigmask
, sizeof(csigmask
)))
2118 sigset_from_compat(&ksigmask
, &csigmask
);
2119 sigdelsetmask(&ksigmask
, sigmask(SIGKILL
) | sigmask(SIGSTOP
));
2120 sigprocmask(SIG_SETMASK
, &ksigmask
, &sigsaved
);
2123 err
= sys_epoll_wait(epfd
, events
, maxevents
, timeout
);
2126 * If we changed the signal mask, we need to restore the original one.
2127 * In case we've got a signal while waiting, we do not restore the
2128 * signal mask yet, and we allow do_signal() to deliver the signal on
2129 * the way back to userspace, before the signal mask is restored.
2132 if (err
== -EINTR
) {
2133 memcpy(¤t
->saved_sigmask
, &sigsaved
,
2135 set_restore_sigmask();
2137 sigprocmask(SIG_SETMASK
, &sigsaved
, NULL
);
2142 #endif /* HAVE_SET_RESTORE_SIGMASK */
2144 #endif /* CONFIG_EPOLL */
2146 #ifdef CONFIG_SIGNALFD
2148 asmlinkage
long compat_sys_signalfd4(int ufd
,
2149 const compat_sigset_t __user
*sigmask
,
2150 compat_size_t sigsetsize
, int flags
)
2152 compat_sigset_t ss32
;
2154 sigset_t __user
*ksigmask
;
2156 if (sigsetsize
!= sizeof(compat_sigset_t
))
2158 if (copy_from_user(&ss32
, sigmask
, sizeof(ss32
)))
2160 sigset_from_compat(&tmp
, &ss32
);
2161 ksigmask
= compat_alloc_user_space(sizeof(sigset_t
));
2162 if (copy_to_user(ksigmask
, &tmp
, sizeof(sigset_t
)))
2165 return sys_signalfd4(ufd
, ksigmask
, sizeof(sigset_t
), flags
);
2168 asmlinkage
long compat_sys_signalfd(int ufd
,
2169 const compat_sigset_t __user
*sigmask
,
2170 compat_size_t sigsetsize
)
2172 return compat_sys_signalfd4(ufd
, sigmask
, sigsetsize
, 0);
2174 #endif /* CONFIG_SIGNALFD */
2176 #ifdef CONFIG_TIMERFD
2178 asmlinkage
long compat_sys_timerfd_settime(int ufd
, int flags
,
2179 const struct compat_itimerspec __user
*utmr
,
2180 struct compat_itimerspec __user
*otmr
)
2183 struct itimerspec t
;
2184 struct itimerspec __user
*ut
;
2186 if (get_compat_itimerspec(&t
, utmr
))
2188 ut
= compat_alloc_user_space(2 * sizeof(struct itimerspec
));
2189 if (copy_to_user(&ut
[0], &t
, sizeof(t
)))
2191 error
= sys_timerfd_settime(ufd
, flags
, &ut
[0], &ut
[1]);
2193 error
= (copy_from_user(&t
, &ut
[1], sizeof(struct itimerspec
)) ||
2194 put_compat_itimerspec(otmr
, &t
)) ? -EFAULT
: 0;
2199 asmlinkage
long compat_sys_timerfd_gettime(int ufd
,
2200 struct compat_itimerspec __user
*otmr
)
2203 struct itimerspec t
;
2204 struct itimerspec __user
*ut
;
2206 ut
= compat_alloc_user_space(sizeof(struct itimerspec
));
2207 error
= sys_timerfd_gettime(ufd
, ut
);
2209 error
= (copy_from_user(&t
, ut
, sizeof(struct itimerspec
)) ||
2210 put_compat_itimerspec(otmr
, &t
)) ? -EFAULT
: 0;
2215 #endif /* CONFIG_TIMERFD */