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/acct.h>
50 #include <net/sock.h> /* siocdevprivate_ioctl */
52 #include <asm/uaccess.h>
53 #include <asm/mmu_context.h>
54 #include <asm/ioctls.h>
57 * Not all architectures have sys_utime, so implement this in terms
60 asmlinkage
long compat_sys_utime(char __user
*filename
, struct compat_utimbuf __user
*t
)
65 if (get_user(tv
[0].tv_sec
, &t
->actime
) ||
66 get_user(tv
[1].tv_sec
, &t
->modtime
))
71 return do_utimes(AT_FDCWD
, filename
, t
? tv
: NULL
);
74 asmlinkage
long compat_sys_futimesat(int dfd
, char __user
*filename
, struct compat_timeval __user
*t
)
79 if (get_user(tv
[0].tv_sec
, &t
[0].tv_sec
) ||
80 get_user(tv
[0].tv_usec
, &t
[0].tv_usec
) ||
81 get_user(tv
[1].tv_sec
, &t
[1].tv_sec
) ||
82 get_user(tv
[1].tv_usec
, &t
[1].tv_usec
))
85 return do_utimes(dfd
, filename
, t
? tv
: NULL
);
88 asmlinkage
long compat_sys_utimes(char __user
*filename
, struct compat_timeval __user
*t
)
90 return compat_sys_futimesat(AT_FDCWD
, filename
, t
);
93 asmlinkage
long compat_sys_newstat(char __user
* filename
,
94 struct compat_stat __user
*statbuf
)
97 int error
= vfs_stat_fd(AT_FDCWD
, filename
, &stat
);
100 error
= cp_compat_stat(&stat
, statbuf
);
104 asmlinkage
long compat_sys_newlstat(char __user
* filename
,
105 struct compat_stat __user
*statbuf
)
108 int error
= vfs_lstat_fd(AT_FDCWD
, filename
, &stat
);
111 error
= cp_compat_stat(&stat
, statbuf
);
115 asmlinkage
long compat_sys_newfstatat(int dfd
, char __user
*filename
,
116 struct compat_stat __user
*statbuf
, int flag
)
121 if ((flag
& ~AT_SYMLINK_NOFOLLOW
) != 0)
124 if (flag
& AT_SYMLINK_NOFOLLOW
)
125 error
= vfs_lstat_fd(dfd
, filename
, &stat
);
127 error
= vfs_stat_fd(dfd
, filename
, &stat
);
130 error
= cp_compat_stat(&stat
, statbuf
);
136 asmlinkage
long compat_sys_newfstat(unsigned int fd
,
137 struct compat_stat __user
* statbuf
)
140 int error
= vfs_fstat(fd
, &stat
);
143 error
= cp_compat_stat(&stat
, statbuf
);
147 static int put_compat_statfs(struct compat_statfs __user
*ubuf
, struct kstatfs
*kbuf
)
150 if (sizeof ubuf
->f_blocks
== 4) {
151 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
152 0xffffffff00000000ULL
)
154 /* f_files and f_ffree may be -1; it's okay
155 * to stuff that into 32 bits */
156 if (kbuf
->f_files
!= 0xffffffffffffffffULL
157 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
159 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
160 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
163 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
164 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
165 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
166 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
167 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
168 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
169 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
170 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
171 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
172 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
173 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
174 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
) ||
175 __put_user(0, &ubuf
->f_spare
[0]) ||
176 __put_user(0, &ubuf
->f_spare
[1]) ||
177 __put_user(0, &ubuf
->f_spare
[2]) ||
178 __put_user(0, &ubuf
->f_spare
[3]) ||
179 __put_user(0, &ubuf
->f_spare
[4]))
185 * The following statfs calls are copies of code from fs/open.c and
186 * should be checked against those from time to time
188 asmlinkage
long compat_sys_statfs(const char __user
*path
, struct compat_statfs __user
*buf
)
193 error
= user_path_walk(path
, &nd
);
196 error
= vfs_statfs(nd
.dentry
->d_inode
->i_sb
, &tmp
);
198 error
= put_compat_statfs(buf
, &tmp
);
204 asmlinkage
long compat_sys_fstatfs(unsigned int fd
, struct compat_statfs __user
*buf
)
214 error
= vfs_statfs(file
->f_dentry
->d_inode
->i_sb
, &tmp
);
216 error
= put_compat_statfs(buf
, &tmp
);
222 static int put_compat_statfs64(struct compat_statfs64 __user
*ubuf
, struct kstatfs
*kbuf
)
224 if (sizeof ubuf
->f_blocks
== 4) {
225 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
226 0xffffffff00000000ULL
)
228 /* f_files and f_ffree may be -1; it's okay
229 * to stuff that into 32 bits */
230 if (kbuf
->f_files
!= 0xffffffffffffffffULL
231 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
233 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
234 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
237 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
238 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
239 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
240 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
241 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
242 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
243 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
244 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
245 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
246 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
247 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
248 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
))
253 asmlinkage
long compat_sys_statfs64(const char __user
*path
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
258 if (sz
!= sizeof(*buf
))
261 error
= user_path_walk(path
, &nd
);
264 error
= vfs_statfs(nd
.dentry
->d_inode
->i_sb
, &tmp
);
266 error
= put_compat_statfs64(buf
, &tmp
);
272 asmlinkage
long compat_sys_fstatfs64(unsigned int fd
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
278 if (sz
!= sizeof(*buf
))
285 error
= vfs_statfs(file
->f_dentry
->d_inode
->i_sb
, &tmp
);
287 error
= put_compat_statfs64(buf
, &tmp
);
293 /* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */
295 #define IOCTL_HASHSIZE 256
296 static struct ioctl_trans
*ioctl32_hash_table
[IOCTL_HASHSIZE
];
298 extern struct ioctl_trans ioctl_start
[];
299 extern int ioctl_table_size
;
301 static inline unsigned long ioctl32_hash(unsigned long cmd
)
303 return (((cmd
>> 6) ^ (cmd
>> 4) ^ cmd
)) % IOCTL_HASHSIZE
;
306 static void ioctl32_insert_translation(struct ioctl_trans
*trans
)
309 struct ioctl_trans
*t
;
311 hash
= ioctl32_hash (trans
->cmd
);
312 if (!ioctl32_hash_table
[hash
])
313 ioctl32_hash_table
[hash
] = trans
;
315 t
= ioctl32_hash_table
[hash
];
323 static int __init
init_sys32_ioctl(void)
327 for (i
= 0; i
< ioctl_table_size
; i
++) {
328 if (ioctl_start
[i
].next
!= 0) {
329 printk("ioctl translation %d bad\n",i
);
333 ioctl32_insert_translation(&ioctl_start
[i
]);
338 __initcall(init_sys32_ioctl
);
340 static void compat_ioctl_error(struct file
*filp
, unsigned int fd
,
341 unsigned int cmd
, unsigned long arg
)
347 /* find the name of the device. */
348 path
= (char *)__get_free_page(GFP_KERNEL
);
350 fn
= d_path(filp
->f_dentry
, filp
->f_vfsmnt
, path
, PAGE_SIZE
);
355 sprintf(buf
,"'%c'", (cmd
>>24) & 0x3f);
356 if (!isprint(buf
[1]))
357 sprintf(buf
, "%02x", buf
[1]);
358 printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
359 "cmd(%08x){%s} arg(%08x) on %s\n",
360 current
->comm
, current
->pid
,
361 (int)fd
, (unsigned int)cmd
, buf
,
362 (unsigned int)arg
, fn
);
365 free_page((unsigned long)path
);
368 asmlinkage
long compat_sys_ioctl(unsigned int fd
, unsigned int cmd
,
373 struct ioctl_trans
*t
;
376 filp
= fget_light(fd
, &fput_needed
);
380 /* RED-PEN how should LSM module know it's handling 32bit? */
381 error
= security_file_ioctl(filp
, cmd
, arg
);
386 * To allow the compat_ioctl handlers to be self contained
387 * we need to check the common ioctls here first.
388 * Just handle them with the standard handlers below.
401 if (S_ISREG(filp
->f_dentry
->d_inode
->i_mode
))
406 if (filp
->f_op
&& filp
->f_op
->compat_ioctl
) {
407 error
= filp
->f_op
->compat_ioctl(filp
, cmd
, arg
);
408 if (error
!= -ENOIOCTLCMD
)
413 (!filp
->f_op
->ioctl
&& !filp
->f_op
->unlocked_ioctl
))
418 for (t
= ioctl32_hash_table
[ioctl32_hash(cmd
)]; t
; t
= t
->next
) {
423 if (S_ISSOCK(filp
->f_dentry
->d_inode
->i_mode
) &&
424 cmd
>= SIOCDEVPRIVATE
&& cmd
<= (SIOCDEVPRIVATE
+ 15)) {
425 error
= siocdevprivate_ioctl(fd
, cmd
, arg
);
430 compat_ioctl_error(filp
, fd
, cmd
, arg
);
439 error
= t
->handler(fd
, cmd
, arg
, filp
);
445 error
= vfs_ioctl(filp
, fd
, cmd
, arg
);
447 fput_light(filp
, fput_needed
);
452 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
454 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
455 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
456 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
457 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
458 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
459 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
464 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
466 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
467 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
468 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
469 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
470 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
471 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
476 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
477 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
479 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
480 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
481 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
482 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
483 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
484 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
490 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
491 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
493 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
494 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
495 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
496 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
497 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
498 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
504 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
515 ret
= get_compat_flock(&f
, compat_ptr(arg
));
520 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
522 if (cmd
== F_GETLK
&& ret
== 0) {
523 /* GETLK was successfule and we need to return the data...
524 * but it needs to fit in the compat structure.
525 * l_start shouldn't be too big, unless the original
526 * start + end is greater than COMPAT_OFF_T_MAX, in which
527 * case the app was asking for trouble, so we return
528 * -EOVERFLOW in that case.
529 * l_len could be too big, in which case we just truncate it,
530 * and only allow the app to see that part of the conflicting
531 * lock that might make sense to it anyway
534 if (f
.l_start
> COMPAT_OFF_T_MAX
)
536 if (f
.l_len
> COMPAT_OFF_T_MAX
)
537 f
.l_len
= COMPAT_OFF_T_MAX
;
539 ret
= put_compat_flock(&f
, compat_ptr(arg
));
546 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
551 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
552 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
555 if (cmd
== F_GETLK64
&& ret
== 0) {
556 /* need to return lock information - see above for commentary */
557 if (f
.l_start
> COMPAT_LOFF_T_MAX
)
559 if (f
.l_len
> COMPAT_LOFF_T_MAX
)
560 f
.l_len
= COMPAT_LOFF_T_MAX
;
562 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
567 ret
= sys_fcntl(fd
, cmd
, arg
);
573 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
576 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
578 return compat_sys_fcntl64(fd
, cmd
, arg
);
582 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
587 mm_segment_t oldfs
= get_fs();
588 if (unlikely(get_user(ctx64
, ctx32p
)))
592 /* The __user pointer cast is valid because of the set_fs() */
593 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
595 /* truncating is ok because it's a user address */
597 ret
= put_user((u32
) ctx64
, ctx32p
);
602 compat_sys_io_getevents(aio_context_t ctx_id
,
603 unsigned long min_nr
,
605 struct io_event __user
*events
,
606 struct compat_timespec __user
*timeout
)
610 struct timespec __user
*ut
= NULL
;
613 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
614 nr
* sizeof(struct io_event
))))
617 if (get_compat_timespec(&t
, timeout
))
620 ut
= compat_alloc_user_space(sizeof(*ut
));
621 if (copy_to_user(ut
, &t
, sizeof(t
)) )
624 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
630 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
635 for (i
= 0; i
< nr
; ++i
) {
636 if (get_user(uptr
, ptr32
+ i
))
638 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
644 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
647 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
649 struct iocb __user
* __user
*iocb64
;
652 if (unlikely(nr
< 0))
655 if (nr
> MAX_AIO_SUBMITS
)
656 nr
= MAX_AIO_SUBMITS
;
658 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
659 ret
= copy_iocb(nr
, iocb
, iocb64
);
661 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
665 struct compat_ncp_mount_data
{
666 compat_int_t version
;
667 compat_uint_t ncp_fd
;
668 __compat_uid_t mounted_uid
;
669 compat_pid_t wdog_pid
;
670 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
671 compat_uint_t time_out
;
672 compat_uint_t retry_count
;
676 compat_mode_t file_mode
;
677 compat_mode_t dir_mode
;
680 struct compat_ncp_mount_data_v4
{
681 compat_int_t version
;
682 compat_ulong_t flags
;
683 compat_ulong_t mounted_uid
;
684 compat_long_t wdog_pid
;
685 compat_uint_t ncp_fd
;
686 compat_uint_t time_out
;
687 compat_uint_t retry_count
;
690 compat_ulong_t file_mode
;
691 compat_ulong_t dir_mode
;
694 static void *do_ncp_super_data_conv(void *raw_data
)
696 int version
= *(unsigned int *)raw_data
;
699 struct compat_ncp_mount_data
*c_n
= raw_data
;
700 struct ncp_mount_data
*n
= raw_data
;
702 n
->dir_mode
= c_n
->dir_mode
;
703 n
->file_mode
= c_n
->file_mode
;
706 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
707 n
->wdog_pid
= c_n
->wdog_pid
;
708 n
->mounted_uid
= c_n
->mounted_uid
;
709 } else if (version
== 4) {
710 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
711 struct ncp_mount_data_v4
*n
= raw_data
;
713 n
->dir_mode
= c_n
->dir_mode
;
714 n
->file_mode
= c_n
->file_mode
;
717 n
->retry_count
= c_n
->retry_count
;
718 n
->time_out
= c_n
->time_out
;
719 n
->ncp_fd
= c_n
->ncp_fd
;
720 n
->wdog_pid
= c_n
->wdog_pid
;
721 n
->mounted_uid
= c_n
->mounted_uid
;
722 n
->flags
= c_n
->flags
;
723 } else if (version
!= 5) {
730 struct compat_smb_mount_data
{
731 compat_int_t version
;
732 __compat_uid_t mounted_uid
;
735 compat_mode_t file_mode
;
736 compat_mode_t dir_mode
;
739 static void *do_smb_super_data_conv(void *raw_data
)
741 struct smb_mount_data
*s
= raw_data
;
742 struct compat_smb_mount_data
*c_s
= raw_data
;
744 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
746 s
->dir_mode
= c_s
->dir_mode
;
747 s
->file_mode
= c_s
->file_mode
;
750 s
->mounted_uid
= c_s
->mounted_uid
;
755 struct compat_nfs_string
{
760 static inline void compat_nfs_string(struct nfs_string
*dst
,
761 struct compat_nfs_string
*src
)
763 dst
->data
= compat_ptr(src
->data
);
767 struct compat_nfs4_mount_data_v1
{
768 compat_int_t version
;
773 compat_int_t retrans
;
774 compat_int_t acregmin
;
775 compat_int_t acregmax
;
776 compat_int_t acdirmin
;
777 compat_int_t acdirmax
;
778 struct compat_nfs_string client_addr
;
779 struct compat_nfs_string mnt_path
;
780 struct compat_nfs_string hostname
;
781 compat_uint_t host_addrlen
;
782 compat_uptr_t host_addr
;
784 compat_int_t auth_flavourlen
;
785 compat_uptr_t auth_flavours
;
788 static int do_nfs4_super_data_conv(void *raw_data
)
790 int version
= *(compat_uint_t
*) raw_data
;
793 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
794 struct nfs4_mount_data
*real
= raw_data
;
796 /* copy the fields backwards */
797 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
798 real
->auth_flavourlen
= raw
->auth_flavourlen
;
799 real
->proto
= raw
->proto
;
800 real
->host_addr
= compat_ptr(raw
->host_addr
);
801 real
->host_addrlen
= raw
->host_addrlen
;
802 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
803 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
804 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
805 real
->acdirmax
= raw
->acdirmax
;
806 real
->acdirmin
= raw
->acdirmin
;
807 real
->acregmax
= raw
->acregmax
;
808 real
->acregmin
= raw
->acregmin
;
809 real
->retrans
= raw
->retrans
;
810 real
->timeo
= raw
->timeo
;
811 real
->wsize
= raw
->wsize
;
812 real
->rsize
= raw
->rsize
;
813 real
->flags
= raw
->flags
;
814 real
->version
= raw
->version
;
823 extern int copy_mount_options (const void __user
*, unsigned long *);
825 #define SMBFS_NAME "smbfs"
826 #define NCPFS_NAME "ncpfs"
827 #define NFS4_NAME "nfs4"
829 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
830 char __user
* type
, unsigned long flags
,
833 unsigned long type_page
;
834 unsigned long data_page
;
835 unsigned long dev_page
;
839 retval
= copy_mount_options (type
, &type_page
);
843 dir_page
= getname(dir_name
);
844 retval
= PTR_ERR(dir_page
);
845 if (IS_ERR(dir_page
))
848 retval
= copy_mount_options (dev_name
, &dev_page
);
852 retval
= copy_mount_options (data
, &data_page
);
859 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
860 do_smb_super_data_conv((void *)data_page
);
861 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
862 do_ncp_super_data_conv((void *)data_page
);
863 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
864 if (do_nfs4_super_data_conv((void *) data_page
))
870 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
871 flags
, (void*)data_page
);
875 free_page(data_page
);
881 free_page(type_page
);
886 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
887 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
888 ~(sizeof(compat_long_t)-1))
890 struct compat_old_linux_dirent
{
891 compat_ulong_t d_ino
;
892 compat_ulong_t d_offset
;
893 unsigned short d_namlen
;
897 struct compat_readdir_callback
{
898 struct compat_old_linux_dirent __user
*dirent
;
902 static int compat_fillonedir(void *__buf
, const char *name
, int namlen
,
903 loff_t offset
, ino_t ino
, unsigned int d_type
)
905 struct compat_readdir_callback
*buf
= __buf
;
906 struct compat_old_linux_dirent __user
*dirent
;
911 dirent
= buf
->dirent
;
912 if (!access_ok(VERIFY_WRITE
, dirent
,
913 (unsigned long)(dirent
->d_name
+ namlen
+ 1) -
914 (unsigned long)dirent
))
916 if ( __put_user(ino
, &dirent
->d_ino
) ||
917 __put_user(offset
, &dirent
->d_offset
) ||
918 __put_user(namlen
, &dirent
->d_namlen
) ||
919 __copy_to_user(dirent
->d_name
, name
, namlen
) ||
920 __put_user(0, dirent
->d_name
+ namlen
))
924 buf
->result
= -EFAULT
;
928 asmlinkage
long compat_sys_old_readdir(unsigned int fd
,
929 struct compat_old_linux_dirent __user
*dirent
, unsigned int count
)
933 struct compat_readdir_callback buf
;
943 error
= vfs_readdir(file
, compat_fillonedir
, &buf
);
952 struct compat_linux_dirent
{
953 compat_ulong_t d_ino
;
954 compat_ulong_t d_off
;
955 unsigned short d_reclen
;
959 struct compat_getdents_callback
{
960 struct compat_linux_dirent __user
*current_dir
;
961 struct compat_linux_dirent __user
*previous
;
966 static int compat_filldir(void *__buf
, const char *name
, int namlen
,
967 loff_t offset
, ino_t ino
, unsigned int d_type
)
969 struct compat_linux_dirent __user
* dirent
;
970 struct compat_getdents_callback
*buf
= __buf
;
971 int reclen
= COMPAT_ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 2);
973 buf
->error
= -EINVAL
; /* only used if we fail.. */
974 if (reclen
> buf
->count
)
976 dirent
= buf
->previous
;
978 if (__put_user(offset
, &dirent
->d_off
))
981 dirent
= buf
->current_dir
;
982 if (__put_user(ino
, &dirent
->d_ino
))
984 if (__put_user(reclen
, &dirent
->d_reclen
))
986 if (copy_to_user(dirent
->d_name
, name
, namlen
))
988 if (__put_user(0, dirent
->d_name
+ namlen
))
990 if (__put_user(d_type
, (char __user
*) dirent
+ reclen
- 1))
992 buf
->previous
= dirent
;
993 dirent
= (void __user
*)dirent
+ reclen
;
994 buf
->current_dir
= dirent
;
995 buf
->count
-= reclen
;
998 buf
->error
= -EFAULT
;
1002 asmlinkage
long compat_sys_getdents(unsigned int fd
,
1003 struct compat_linux_dirent __user
*dirent
, unsigned int count
)
1006 struct compat_linux_dirent __user
* lastdirent
;
1007 struct compat_getdents_callback buf
;
1011 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1019 buf
.current_dir
= dirent
;
1020 buf
.previous
= NULL
;
1024 error
= vfs_readdir(file
, compat_filldir
, &buf
);
1028 lastdirent
= buf
.previous
;
1030 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
1033 error
= count
- buf
.count
;
1042 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1043 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1045 struct compat_getdents_callback64
{
1046 struct linux_dirent64 __user
*current_dir
;
1047 struct linux_dirent64 __user
*previous
;
1052 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
1053 ino_t ino
, unsigned int d_type
)
1055 struct linux_dirent64 __user
*dirent
;
1056 struct compat_getdents_callback64
*buf
= __buf
;
1057 int jj
= NAME_OFFSET(dirent
);
1058 int reclen
= COMPAT_ROUND_UP64(jj
+ namlen
+ 1);
1061 buf
->error
= -EINVAL
; /* only used if we fail.. */
1062 if (reclen
> buf
->count
)
1064 dirent
= buf
->previous
;
1067 if (__put_user_unaligned(offset
, &dirent
->d_off
))
1070 dirent
= buf
->current_dir
;
1071 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
1074 if (__put_user_unaligned(off
, &dirent
->d_off
))
1076 if (__put_user(reclen
, &dirent
->d_reclen
))
1078 if (__put_user(d_type
, &dirent
->d_type
))
1080 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1082 if (__put_user(0, dirent
->d_name
+ namlen
))
1084 buf
->previous
= dirent
;
1085 dirent
= (void __user
*)dirent
+ reclen
;
1086 buf
->current_dir
= dirent
;
1087 buf
->count
-= reclen
;
1090 buf
->error
= -EFAULT
;
1094 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
1095 struct linux_dirent64 __user
* dirent
, unsigned int count
)
1098 struct linux_dirent64 __user
* lastdirent
;
1099 struct compat_getdents_callback64 buf
;
1103 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1111 buf
.current_dir
= dirent
;
1112 buf
.previous
= NULL
;
1116 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1120 lastdirent
= buf
.previous
;
1122 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1123 __put_user_unaligned(d_off
, &lastdirent
->d_off
);
1124 error
= count
- buf
.count
;
1132 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1134 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1135 const struct compat_iovec __user
*uvector
,
1136 unsigned long nr_segs
, loff_t
*pos
)
1138 typedef ssize_t (*io_fn_t
)(struct file
*, char __user
*, size_t, loff_t
*);
1139 typedef ssize_t (*iov_fn_t
)(struct file
*, const struct iovec
*, unsigned long, loff_t
*);
1141 compat_ssize_t tot_len
;
1142 struct iovec iovstack
[UIO_FASTIOV
];
1143 struct iovec
*iov
=iovstack
, *vector
;
1150 * SuS says "The readv() function *may* fail if the iovcnt argument
1151 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1152 * traditionally returned zero for zero segments, so...
1159 * First get the "struct iovec" from user memory and
1160 * verify all the pointers
1163 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1167 if (nr_segs
> UIO_FASTIOV
) {
1169 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1174 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1178 * Single unix specification:
1179 * We should -EINVAL if an element length is not >= 0 and fitting an
1180 * ssize_t. The total length is fitting an ssize_t
1182 * Be careful here because iov_len is a size_t not an ssize_t
1187 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1188 compat_ssize_t tmp
= tot_len
;
1192 if (__get_user(len
, &uvector
->iov_len
) ||
1193 __get_user(buf
, &uvector
->iov_base
)) {
1197 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1200 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1202 vector
->iov_base
= compat_ptr(buf
);
1203 vector
->iov_len
= (compat_size_t
) len
;
1212 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1218 fn
= file
->f_op
->read
;
1219 fnv
= file
->f_op
->readv
;
1221 fn
= (io_fn_t
)file
->f_op
->write
;
1222 fnv
= file
->f_op
->writev
;
1225 ret
= fnv(file
, iov
, nr_segs
, pos
);
1229 /* Do it by hand, with file-ops */
1232 while (nr_segs
> 0) {
1237 base
= vector
->iov_base
;
1238 len
= vector
->iov_len
;
1242 nr
= fn(file
, base
, len
, pos
);
1253 if (iov
!= iovstack
)
1255 if ((ret
+ (type
== READ
)) > 0) {
1256 struct dentry
*dentry
= file
->f_dentry
;
1258 fsnotify_access(dentry
);
1260 fsnotify_modify(dentry
);
1266 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1269 ssize_t ret
= -EBADF
;
1275 if (!(file
->f_mode
& FMODE_READ
))
1279 if (!file
->f_op
|| (!file
->f_op
->readv
&& !file
->f_op
->read
))
1282 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1290 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1293 ssize_t ret
= -EBADF
;
1298 if (!(file
->f_mode
& FMODE_WRITE
))
1302 if (!file
->f_op
|| (!file
->f_op
->writev
&& !file
->f_op
->write
))
1305 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1313 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1317 compat_sys_open(const char __user
*filename
, int flags
, int mode
)
1319 return do_sys_open(AT_FDCWD
, filename
, flags
, mode
);
1323 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1327 compat_sys_openat(int dfd
, const char __user
*filename
, int flags
, int mode
)
1329 return do_sys_open(dfd
, filename
, flags
, mode
);
1333 * compat_count() counts the number of arguments/envelopes. It is basically
1334 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1335 * and envp pointers.
1337 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1345 if (get_user(p
, argv
))
1358 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1359 * except that it works with 32 bit argv and envp pointers.
1361 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1362 struct linux_binprm
*bprm
)
1364 struct page
*kmapped_page
= NULL
;
1368 while (argc
-- > 0) {
1373 if (get_user(str
, argv
+argc
) ||
1374 !(len
= strnlen_user(compat_ptr(str
), bprm
->p
))) {
1379 if (bprm
->p
< len
) {
1385 /* XXX: add architecture specific overflow check here. */
1390 int offset
, bytes_to_copy
;
1393 offset
= pos
% PAGE_SIZE
;
1395 page
= bprm
->page
[i
];
1398 page
= alloc_page(GFP_HIGHUSER
);
1399 bprm
->page
[i
] = page
;
1407 if (page
!= kmapped_page
) {
1409 kunmap(kmapped_page
);
1410 kmapped_page
= page
;
1411 kaddr
= kmap(kmapped_page
);
1414 memset(kaddr
, 0, offset
);
1415 bytes_to_copy
= PAGE_SIZE
- offset
;
1416 if (bytes_to_copy
> len
) {
1417 bytes_to_copy
= len
;
1419 memset(kaddr
+offset
+len
, 0,
1420 PAGE_SIZE
-offset
-len
);
1422 err
= copy_from_user(kaddr
+offset
, compat_ptr(str
),
1429 pos
+= bytes_to_copy
;
1430 str
+= bytes_to_copy
;
1431 len
-= bytes_to_copy
;
1437 kunmap(kmapped_page
);
1443 #define free_arg_pages(bprm) do { } while (0)
1447 static inline void free_arg_pages(struct linux_binprm
*bprm
)
1451 for (i
= 0; i
< MAX_ARG_PAGES
; i
++) {
1453 __free_page(bprm
->page
[i
]);
1454 bprm
->page
[i
] = NULL
;
1458 #endif /* CONFIG_MMU */
1461 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1462 * that it processes 32 bit argv and envp pointers.
1464 int compat_do_execve(char * filename
,
1465 compat_uptr_t __user
*argv
,
1466 compat_uptr_t __user
*envp
,
1467 struct pt_regs
* regs
)
1469 struct linux_binprm
*bprm
;
1475 bprm
= kmalloc(sizeof(*bprm
), GFP_KERNEL
);
1478 memset(bprm
, 0, sizeof(*bprm
));
1480 file
= open_exec(filename
);
1481 retval
= PTR_ERR(file
);
1487 bprm
->p
= PAGE_SIZE
*MAX_ARG_PAGES
-sizeof(void *);
1489 bprm
->filename
= filename
;
1490 bprm
->interp
= filename
;
1491 bprm
->mm
= mm_alloc();
1496 retval
= init_new_context(current
, bprm
->mm
);
1500 bprm
->argc
= compat_count(argv
, bprm
->p
/ sizeof(compat_uptr_t
));
1501 if ((retval
= bprm
->argc
) < 0)
1504 bprm
->envc
= compat_count(envp
, bprm
->p
/ sizeof(compat_uptr_t
));
1505 if ((retval
= bprm
->envc
) < 0)
1508 retval
= security_bprm_alloc(bprm
);
1512 retval
= prepare_binprm(bprm
);
1516 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1520 bprm
->exec
= bprm
->p
;
1521 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1525 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1529 retval
= search_binary_handler(bprm
, regs
);
1531 free_arg_pages(bprm
);
1533 /* execve success */
1534 security_bprm_free(bprm
);
1535 acct_update_integrals(current
);
1541 /* Something went wrong, return the inode and free the argument pages*/
1542 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
1543 struct page
* page
= bprm
->page
[i
];
1549 security_bprm_free(bprm
);
1557 allow_write_access(bprm
->file
);
1568 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1570 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1573 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1574 * 64-bit unsigned longs.
1577 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1578 unsigned long *fdset
)
1580 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1584 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1591 __get_user(l
, ufdset
);
1592 __get_user(h
, ufdset
+1);
1594 *fdset
++ = h
<< 32 | l
;
1598 __get_user(*fdset
, ufdset
);
1600 /* Tricky, must clear full unsigned long in the
1601 * kernel fdset at the end, this makes sure that
1604 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1610 void compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1611 unsigned long *fdset
)
1614 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1625 __put_user(l
, ufdset
);
1626 __put_user(h
, ufdset
+1);
1631 __put_user(*fdset
, ufdset
);
1636 * This is a virtual copy of sys_select from fs/select.c and probably
1637 * should be compared to it from time to time
1639 static void *select_bits_alloc(int size
)
1641 return kmalloc(6 * size
, GFP_KERNEL
);
1644 static void select_bits_free(void *bits
, int size
)
1650 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1651 * like to be certain this leads to no problems. So I return
1652 * EINTR just for safety.
1654 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1655 * I'm trying ERESTARTNOHAND which restart only when you want to.
1657 #define MAX_SELECT_SECONDS \
1658 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1661 compat_sys_select(int n
, compat_ulong_t __user
*inp
, compat_ulong_t __user
*outp
,
1662 compat_ulong_t __user
*exp
, struct compat_timeval __user
*tvp
)
1667 int size
, max_fdset
, ret
= -EINVAL
;
1668 struct fdtable
*fdt
;
1670 timeout
= MAX_SCHEDULE_TIMEOUT
;
1674 if (!access_ok(VERIFY_READ
, tvp
, sizeof(*tvp
))
1675 || __get_user(sec
, &tvp
->tv_sec
)
1676 || __get_user(usec
, &tvp
->tv_usec
)) {
1681 if (sec
< 0 || usec
< 0)
1684 if ((unsigned long) sec
< MAX_SELECT_SECONDS
) {
1685 timeout
= ROUND_UP(usec
, 1000000/HZ
);
1686 timeout
+= sec
* (unsigned long) HZ
;
1693 /* max_fdset can increase, so grab it once to avoid race */
1695 fdt
= files_fdtable(current
->files
);
1696 max_fdset
= fdt
->max_fdset
;
1702 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1703 * since we used fdset we need to allocate memory in units of
1707 size
= FDS_BYTES(n
);
1708 bits
= select_bits_alloc(size
);
1711 fds
.in
= (unsigned long *) bits
;
1712 fds
.out
= (unsigned long *) (bits
+ size
);
1713 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1714 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1715 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1716 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1718 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1719 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1720 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1722 zero_fd_set(n
, fds
.res_in
);
1723 zero_fd_set(n
, fds
.res_out
);
1724 zero_fd_set(n
, fds
.res_ex
);
1726 ret
= do_select(n
, &fds
, &timeout
);
1728 if (tvp
&& !(current
->personality
& STICKY_TIMEOUTS
)) {
1729 time_t sec
= 0, usec
= 0;
1732 usec
= timeout
% HZ
;
1733 usec
*= (1000000/HZ
);
1735 if (put_user(sec
, &tvp
->tv_sec
) ||
1736 put_user(usec
, &tvp
->tv_usec
))
1743 ret
= -ERESTARTNOHAND
;
1744 if (signal_pending(current
))
1749 compat_set_fd_set(n
, inp
, fds
.res_in
);
1750 compat_set_fd_set(n
, outp
, fds
.res_out
);
1751 compat_set_fd_set(n
, exp
, fds
.res_ex
);
1754 select_bits_free(bits
, size
);
1759 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1760 /* Stuff for NFS server syscalls... */
1761 struct compat_nfsctl_svc
{
1766 struct compat_nfsctl_client
{
1767 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
1769 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
1772 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
1775 struct compat_nfsctl_export
{
1776 char ex32_client
[NFSCLNT_IDMAX
+1];
1777 char ex32_path
[NFS_MAXPATHLEN
+1];
1778 compat_dev_t ex32_dev
;
1779 compat_ino_t ex32_ino
;
1780 compat_int_t ex32_flags
;
1781 __compat_uid_t ex32_anon_uid
;
1782 __compat_gid_t ex32_anon_gid
;
1785 struct compat_nfsctl_fdparm
{
1786 struct sockaddr gd32_addr
;
1787 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1788 compat_int_t gd32_version
;
1791 struct compat_nfsctl_fsparm
{
1792 struct sockaddr gd32_addr
;
1793 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1794 compat_int_t gd32_maxlen
;
1797 struct compat_nfsctl_arg
{
1798 compat_int_t ca32_version
; /* safeguard */
1800 struct compat_nfsctl_svc u32_svc
;
1801 struct compat_nfsctl_client u32_client
;
1802 struct compat_nfsctl_export u32_export
;
1803 struct compat_nfsctl_fdparm u32_getfd
;
1804 struct compat_nfsctl_fsparm u32_getfs
;
1806 #define ca32_svc u.u32_svc
1807 #define ca32_client u.u32_client
1808 #define ca32_export u.u32_export
1809 #define ca32_getfd u.u32_getfd
1810 #define ca32_getfs u.u32_getfs
1813 union compat_nfsctl_res
{
1814 __u8 cr32_getfh
[NFS_FHSIZE
];
1815 struct knfsd_fh cr32_getfs
;
1818 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1822 err
= access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
));
1823 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1824 err
|= __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
);
1825 err
|= __get_user(karg
->ca_svc
.svc_nthreads
, &arg
->ca32_svc
.svc32_nthreads
);
1826 return (err
) ? -EFAULT
: 0;
1829 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1833 err
= access_ok(VERIFY_READ
, &arg
->ca32_client
, sizeof(arg
->ca32_client
));
1834 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1835 err
|= __copy_from_user(&karg
->ca_client
.cl_ident
[0],
1836 &arg
->ca32_client
.cl32_ident
[0],
1838 err
|= __get_user(karg
->ca_client
.cl_naddr
, &arg
->ca32_client
.cl32_naddr
);
1839 err
|= __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
1840 &arg
->ca32_client
.cl32_addrlist
[0],
1841 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
));
1842 err
|= __get_user(karg
->ca_client
.cl_fhkeytype
,
1843 &arg
->ca32_client
.cl32_fhkeytype
);
1844 err
|= __get_user(karg
->ca_client
.cl_fhkeylen
,
1845 &arg
->ca32_client
.cl32_fhkeylen
);
1846 err
|= __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
1847 &arg
->ca32_client
.cl32_fhkey
[0],
1850 return (err
) ? -EFAULT
: 0;
1853 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1857 err
= access_ok(VERIFY_READ
, &arg
->ca32_export
, sizeof(arg
->ca32_export
));
1858 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1859 err
|= __copy_from_user(&karg
->ca_export
.ex_client
[0],
1860 &arg
->ca32_export
.ex32_client
[0],
1862 err
|= __copy_from_user(&karg
->ca_export
.ex_path
[0],
1863 &arg
->ca32_export
.ex32_path
[0],
1865 err
|= __get_user(karg
->ca_export
.ex_dev
,
1866 &arg
->ca32_export
.ex32_dev
);
1867 err
|= __get_user(karg
->ca_export
.ex_ino
,
1868 &arg
->ca32_export
.ex32_ino
);
1869 err
|= __get_user(karg
->ca_export
.ex_flags
,
1870 &arg
->ca32_export
.ex32_flags
);
1871 err
|= __get_user(karg
->ca_export
.ex_anon_uid
,
1872 &arg
->ca32_export
.ex32_anon_uid
);
1873 err
|= __get_user(karg
->ca_export
.ex_anon_gid
,
1874 &arg
->ca32_export
.ex32_anon_gid
);
1875 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
1876 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
1878 return (err
) ? -EFAULT
: 0;
1881 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1885 err
= access_ok(VERIFY_READ
, &arg
->ca32_getfd
, sizeof(arg
->ca32_getfd
));
1886 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1887 err
|= __copy_from_user(&karg
->ca_getfd
.gd_addr
,
1888 &arg
->ca32_getfd
.gd32_addr
,
1889 (sizeof(struct sockaddr
)));
1890 err
|= __copy_from_user(&karg
->ca_getfd
.gd_path
,
1891 &arg
->ca32_getfd
.gd32_path
,
1892 (NFS_MAXPATHLEN
+1));
1893 err
|= __get_user(karg
->ca_getfd
.gd_version
,
1894 &arg
->ca32_getfd
.gd32_version
);
1896 return (err
) ? -EFAULT
: 0;
1899 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1903 err
= access_ok(VERIFY_READ
, &arg
->ca32_getfs
, sizeof(arg
->ca32_getfs
));
1904 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1905 err
|= __copy_from_user(&karg
->ca_getfs
.gd_addr
,
1906 &arg
->ca32_getfs
.gd32_addr
,
1907 (sizeof(struct sockaddr
)));
1908 err
|= __copy_from_user(&karg
->ca_getfs
.gd_path
,
1909 &arg
->ca32_getfs
.gd32_path
,
1910 (NFS_MAXPATHLEN
+1));
1911 err
|= __get_user(karg
->ca_getfs
.gd_maxlen
,
1912 &arg
->ca32_getfs
.gd32_maxlen
);
1914 return (err
) ? -EFAULT
: 0;
1917 /* This really doesn't need translations, we are only passing
1918 * back a union which contains opaque nfs file handle data.
1920 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
, union compat_nfsctl_res __user
*res
)
1924 err
= copy_to_user(res
, kres
, sizeof(*res
));
1926 return (err
) ? -EFAULT
: 0;
1929 asmlinkage
long compat_sys_nfsservctl(int cmd
, struct compat_nfsctl_arg __user
*arg
,
1930 union compat_nfsctl_res __user
*res
)
1932 struct nfsctl_arg
*karg
;
1933 union nfsctl_res
*kres
;
1937 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
1938 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
1939 if(!karg
|| !kres
) {
1946 err
= compat_nfs_svc_trans(karg
, arg
);
1949 case NFSCTL_ADDCLIENT
:
1950 err
= compat_nfs_clnt_trans(karg
, arg
);
1953 case NFSCTL_DELCLIENT
:
1954 err
= compat_nfs_clnt_trans(karg
, arg
);
1958 case NFSCTL_UNEXPORT
:
1959 err
= compat_nfs_exp_trans(karg
, arg
);
1963 err
= compat_nfs_getfd_trans(karg
, arg
);
1967 err
= compat_nfs_getfs_trans(karg
, arg
);
1977 /* The __user pointer casts are valid because of the set_fs() */
1978 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
1984 if((cmd
== NFSCTL_GETFD
) ||
1985 (cmd
== NFSCTL_GETFS
))
1986 err
= compat_nfs_getfh_res_trans(kres
, res
);
1994 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
1996 return sys_ni_syscall();