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>
48 #include <net/sock.h> /* siocdevprivate_ioctl */
50 #include <asm/uaccess.h>
51 #include <asm/mmu_context.h>
52 #include <asm/ioctls.h>
55 * Not all architectures have sys_utime, so implement this in terms
58 asmlinkage
long compat_sys_utime(char __user
*filename
, struct compat_utimbuf __user
*t
)
63 if (get_user(tv
[0].tv_sec
, &t
->actime
) ||
64 get_user(tv
[1].tv_sec
, &t
->modtime
))
69 return do_utimes(filename
, t
? tv
: NULL
);
72 asmlinkage
long compat_sys_utimes(char __user
*filename
, struct compat_timeval __user
*t
)
77 if (get_user(tv
[0].tv_sec
, &t
[0].tv_sec
) ||
78 get_user(tv
[0].tv_usec
, &t
[0].tv_usec
) ||
79 get_user(tv
[1].tv_sec
, &t
[1].tv_sec
) ||
80 get_user(tv
[1].tv_usec
, &t
[1].tv_usec
))
83 return do_utimes(filename
, t
? tv
: NULL
);
86 asmlinkage
long compat_sys_newstat(char __user
* filename
,
87 struct compat_stat __user
*statbuf
)
90 int error
= vfs_stat(filename
, &stat
);
93 error
= cp_compat_stat(&stat
, statbuf
);
97 asmlinkage
long compat_sys_newlstat(char __user
* filename
,
98 struct compat_stat __user
*statbuf
)
101 int error
= vfs_lstat(filename
, &stat
);
104 error
= cp_compat_stat(&stat
, statbuf
);
108 asmlinkage
long compat_sys_newfstat(unsigned int fd
,
109 struct compat_stat __user
* statbuf
)
112 int error
= vfs_fstat(fd
, &stat
);
115 error
= cp_compat_stat(&stat
, statbuf
);
119 static int put_compat_statfs(struct compat_statfs __user
*ubuf
, struct kstatfs
*kbuf
)
122 if (sizeof ubuf
->f_blocks
== 4) {
123 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
124 0xffffffff00000000ULL
)
126 /* f_files and f_ffree may be -1; it's okay
127 * to stuff that into 32 bits */
128 if (kbuf
->f_files
!= 0xffffffffffffffffULL
129 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
131 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
132 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
135 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
136 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
137 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
138 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
139 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
140 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
141 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
142 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
143 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
144 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
145 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
146 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
) ||
147 __put_user(0, &ubuf
->f_spare
[0]) ||
148 __put_user(0, &ubuf
->f_spare
[1]) ||
149 __put_user(0, &ubuf
->f_spare
[2]) ||
150 __put_user(0, &ubuf
->f_spare
[3]) ||
151 __put_user(0, &ubuf
->f_spare
[4]))
157 * The following statfs calls are copies of code from fs/open.c and
158 * should be checked against those from time to time
160 asmlinkage
long compat_sys_statfs(const char __user
*path
, struct compat_statfs __user
*buf
)
165 error
= user_path_walk(path
, &nd
);
168 error
= vfs_statfs(nd
.dentry
->d_inode
->i_sb
, &tmp
);
169 if (!error
&& put_compat_statfs(buf
, &tmp
))
176 asmlinkage
long compat_sys_fstatfs(unsigned int fd
, struct compat_statfs __user
*buf
)
186 error
= vfs_statfs(file
->f_dentry
->d_inode
->i_sb
, &tmp
);
187 if (!error
&& put_compat_statfs(buf
, &tmp
))
194 static int put_compat_statfs64(struct compat_statfs64 __user
*ubuf
, struct kstatfs
*kbuf
)
196 if (sizeof ubuf
->f_blocks
== 4) {
197 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
198 0xffffffff00000000ULL
)
200 /* f_files and f_ffree may be -1; it's okay
201 * to stuff that into 32 bits */
202 if (kbuf
->f_files
!= 0xffffffffffffffffULL
203 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
205 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
206 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
209 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
210 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
211 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
212 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
213 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
214 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
215 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
216 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
217 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
218 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
219 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
220 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
))
225 asmlinkage
long compat_sys_statfs64(const char __user
*path
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
230 if (sz
!= sizeof(*buf
))
233 error
= user_path_walk(path
, &nd
);
236 error
= vfs_statfs(nd
.dentry
->d_inode
->i_sb
, &tmp
);
237 if (!error
&& put_compat_statfs64(buf
, &tmp
))
244 asmlinkage
long compat_sys_fstatfs64(unsigned int fd
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
250 if (sz
!= sizeof(*buf
))
257 error
= vfs_statfs(file
->f_dentry
->d_inode
->i_sb
, &tmp
);
258 if (!error
&& put_compat_statfs64(buf
, &tmp
))
265 /* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */
267 #define IOCTL_HASHSIZE 256
268 static struct ioctl_trans
*ioctl32_hash_table
[IOCTL_HASHSIZE
];
269 static DECLARE_RWSEM(ioctl32_sem
);
271 extern struct ioctl_trans ioctl_start
[];
272 extern int ioctl_table_size
;
274 static inline unsigned long ioctl32_hash(unsigned long cmd
)
276 return (((cmd
>> 6) ^ (cmd
>> 4) ^ cmd
)) % IOCTL_HASHSIZE
;
279 static void ioctl32_insert_translation(struct ioctl_trans
*trans
)
282 struct ioctl_trans
*t
;
284 hash
= ioctl32_hash (trans
->cmd
);
285 if (!ioctl32_hash_table
[hash
])
286 ioctl32_hash_table
[hash
] = trans
;
288 t
= ioctl32_hash_table
[hash
];
296 static int __init
init_sys32_ioctl(void)
300 for (i
= 0; i
< ioctl_table_size
; i
++) {
301 if (ioctl_start
[i
].next
!= 0) {
302 printk("ioctl translation %d bad\n",i
);
306 ioctl32_insert_translation(&ioctl_start
[i
]);
311 __initcall(init_sys32_ioctl
);
313 static void compat_ioctl_error(struct file
*filp
, unsigned int fd
,
314 unsigned int cmd
, unsigned long arg
)
320 /* find the name of the device. */
321 path
= (char *)__get_free_page(GFP_KERNEL
);
323 fn
= d_path(filp
->f_dentry
, filp
->f_vfsmnt
, path
, PAGE_SIZE
);
328 sprintf(buf
,"'%c'", (cmd
>>24) & 0x3f);
329 if (!isprint(buf
[1]))
330 sprintf(buf
, "%02x", buf
[1]);
331 printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
332 "cmd(%08x){%s} arg(%08x) on %s\n",
333 current
->comm
, current
->pid
,
334 (int)fd
, (unsigned int)cmd
, buf
,
335 (unsigned int)arg
, fn
);
338 free_page((unsigned long)path
);
341 asmlinkage
long compat_sys_ioctl(unsigned int fd
, unsigned int cmd
,
346 struct ioctl_trans
*t
;
349 filp
= fget_light(fd
, &fput_needed
);
353 /* RED-PEN how should LSM module know it's handling 32bit? */
354 error
= security_file_ioctl(filp
, cmd
, arg
);
359 * To allow the compat_ioctl handlers to be self contained
360 * we need to check the common ioctls here first.
361 * Just handle them with the standard handlers below.
374 if (S_ISREG(filp
->f_dentry
->d_inode
->i_mode
))
379 if (filp
->f_op
&& filp
->f_op
->compat_ioctl
) {
380 error
= filp
->f_op
->compat_ioctl(filp
, cmd
, arg
);
381 if (error
!= -ENOIOCTLCMD
)
386 (!filp
->f_op
->ioctl
&& !filp
->f_op
->unlocked_ioctl
))
391 /* When register_ioctl32_conversion is finally gone remove
393 down_read(&ioctl32_sem
);
394 for (t
= ioctl32_hash_table
[ioctl32_hash(cmd
)]; t
; t
= t
->next
) {
398 up_read(&ioctl32_sem
);
400 if (S_ISSOCK(filp
->f_dentry
->d_inode
->i_mode
) &&
401 cmd
>= SIOCDEVPRIVATE
&& cmd
<= (SIOCDEVPRIVATE
+ 15)) {
402 error
= siocdevprivate_ioctl(fd
, cmd
, arg
);
407 compat_ioctl_error(filp
, fd
, cmd
, arg
);
416 error
= t
->handler(fd
, cmd
, arg
, filp
);
418 up_read(&ioctl32_sem
);
422 up_read(&ioctl32_sem
);
424 error
= vfs_ioctl(filp
, fd
, cmd
, arg
);
426 fput_light(filp
, fput_needed
);
431 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
433 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
434 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
435 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
436 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
437 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
438 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
443 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
445 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
446 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
447 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
448 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
449 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
450 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
455 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
456 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
458 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
459 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
460 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
461 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
462 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
463 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
469 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
470 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
472 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
473 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
474 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
475 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
476 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
477 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
483 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
494 ret
= get_compat_flock(&f
, compat_ptr(arg
));
499 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
501 if (cmd
== F_GETLK
&& ret
== 0) {
502 if ((f
.l_start
>= COMPAT_OFF_T_MAX
) ||
503 ((f
.l_start
+ f
.l_len
) > COMPAT_OFF_T_MAX
))
506 ret
= put_compat_flock(&f
, compat_ptr(arg
));
513 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
518 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
519 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
522 if (cmd
== F_GETLK64
&& ret
== 0) {
523 if ((f
.l_start
>= COMPAT_LOFF_T_MAX
) ||
524 ((f
.l_start
+ f
.l_len
) > COMPAT_LOFF_T_MAX
))
527 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
532 ret
= sys_fcntl(fd
, cmd
, arg
);
538 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
541 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
543 return compat_sys_fcntl64(fd
, cmd
, arg
);
547 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
552 mm_segment_t oldfs
= get_fs();
553 if (unlikely(get_user(ctx64
, ctx32p
)))
557 /* The __user pointer cast is valid because of the set_fs() */
558 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
560 /* truncating is ok because it's a user address */
562 ret
= put_user((u32
) ctx64
, ctx32p
);
567 compat_sys_io_getevents(aio_context_t ctx_id
,
568 unsigned long min_nr
,
570 struct io_event __user
*events
,
571 struct compat_timespec __user
*timeout
)
575 struct timespec __user
*ut
= NULL
;
578 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
579 nr
* sizeof(struct io_event
))))
582 if (get_compat_timespec(&t
, timeout
))
585 ut
= compat_alloc_user_space(sizeof(*ut
));
586 if (copy_to_user(ut
, &t
, sizeof(t
)) )
589 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
595 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
600 for (i
= 0; i
< nr
; ++i
) {
601 if (get_user(uptr
, ptr32
+ i
))
603 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
609 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
612 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
614 struct iocb __user
* __user
*iocb64
;
617 if (unlikely(nr
< 0))
620 if (nr
> MAX_AIO_SUBMITS
)
621 nr
= MAX_AIO_SUBMITS
;
623 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
624 ret
= copy_iocb(nr
, iocb
, iocb64
);
626 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
630 struct compat_ncp_mount_data
{
631 compat_int_t version
;
632 compat_uint_t ncp_fd
;
633 __compat_uid_t mounted_uid
;
634 compat_pid_t wdog_pid
;
635 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
636 compat_uint_t time_out
;
637 compat_uint_t retry_count
;
641 compat_mode_t file_mode
;
642 compat_mode_t dir_mode
;
645 struct compat_ncp_mount_data_v4
{
646 compat_int_t version
;
647 compat_ulong_t flags
;
648 compat_ulong_t mounted_uid
;
649 compat_long_t wdog_pid
;
650 compat_uint_t ncp_fd
;
651 compat_uint_t time_out
;
652 compat_uint_t retry_count
;
655 compat_ulong_t file_mode
;
656 compat_ulong_t dir_mode
;
659 static void *do_ncp_super_data_conv(void *raw_data
)
661 int version
= *(unsigned int *)raw_data
;
664 struct compat_ncp_mount_data
*c_n
= raw_data
;
665 struct ncp_mount_data
*n
= raw_data
;
667 n
->dir_mode
= c_n
->dir_mode
;
668 n
->file_mode
= c_n
->file_mode
;
671 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
672 n
->wdog_pid
= c_n
->wdog_pid
;
673 n
->mounted_uid
= c_n
->mounted_uid
;
674 } else if (version
== 4) {
675 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
676 struct ncp_mount_data_v4
*n
= raw_data
;
678 n
->dir_mode
= c_n
->dir_mode
;
679 n
->file_mode
= c_n
->file_mode
;
682 n
->retry_count
= c_n
->retry_count
;
683 n
->time_out
= c_n
->time_out
;
684 n
->ncp_fd
= c_n
->ncp_fd
;
685 n
->wdog_pid
= c_n
->wdog_pid
;
686 n
->mounted_uid
= c_n
->mounted_uid
;
687 n
->flags
= c_n
->flags
;
688 } else if (version
!= 5) {
695 struct compat_smb_mount_data
{
696 compat_int_t version
;
697 __compat_uid_t mounted_uid
;
700 compat_mode_t file_mode
;
701 compat_mode_t dir_mode
;
704 static void *do_smb_super_data_conv(void *raw_data
)
706 struct smb_mount_data
*s
= raw_data
;
707 struct compat_smb_mount_data
*c_s
= raw_data
;
709 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
711 s
->dir_mode
= c_s
->dir_mode
;
712 s
->file_mode
= c_s
->file_mode
;
715 s
->mounted_uid
= c_s
->mounted_uid
;
720 struct compat_nfs_string
{
725 static inline void compat_nfs_string(struct nfs_string
*dst
,
726 struct compat_nfs_string
*src
)
728 dst
->data
= compat_ptr(src
->data
);
732 struct compat_nfs4_mount_data_v1
{
733 compat_int_t version
;
738 compat_int_t retrans
;
739 compat_int_t acregmin
;
740 compat_int_t acregmax
;
741 compat_int_t acdirmin
;
742 compat_int_t acdirmax
;
743 struct compat_nfs_string client_addr
;
744 struct compat_nfs_string mnt_path
;
745 struct compat_nfs_string hostname
;
746 compat_uint_t host_addrlen
;
747 compat_uptr_t host_addr
;
749 compat_int_t auth_flavourlen
;
750 compat_uptr_t auth_flavours
;
753 static int do_nfs4_super_data_conv(void *raw_data
)
755 int version
= *(compat_uint_t
*) raw_data
;
758 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
759 struct nfs4_mount_data
*real
= raw_data
;
761 /* copy the fields backwards */
762 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
763 real
->auth_flavourlen
= raw
->auth_flavourlen
;
764 real
->proto
= raw
->proto
;
765 real
->host_addr
= compat_ptr(raw
->host_addr
);
766 real
->host_addrlen
= raw
->host_addrlen
;
767 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
768 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
769 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
770 real
->acdirmax
= raw
->acdirmax
;
771 real
->acdirmin
= raw
->acdirmin
;
772 real
->acregmax
= raw
->acregmax
;
773 real
->acregmin
= raw
->acregmin
;
774 real
->retrans
= raw
->retrans
;
775 real
->timeo
= raw
->timeo
;
776 real
->wsize
= raw
->wsize
;
777 real
->rsize
= raw
->rsize
;
778 real
->flags
= raw
->flags
;
779 real
->version
= raw
->version
;
788 extern int copy_mount_options (const void __user
*, unsigned long *);
790 #define SMBFS_NAME "smbfs"
791 #define NCPFS_NAME "ncpfs"
792 #define NFS4_NAME "nfs4"
794 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
795 char __user
* type
, unsigned long flags
,
798 unsigned long type_page
;
799 unsigned long data_page
;
800 unsigned long dev_page
;
804 retval
= copy_mount_options (type
, &type_page
);
808 dir_page
= getname(dir_name
);
809 retval
= PTR_ERR(dir_page
);
810 if (IS_ERR(dir_page
))
813 retval
= copy_mount_options (dev_name
, &dev_page
);
817 retval
= copy_mount_options (data
, &data_page
);
824 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
825 do_smb_super_data_conv((void *)data_page
);
826 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
827 do_ncp_super_data_conv((void *)data_page
);
828 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
829 if (do_nfs4_super_data_conv((void *) data_page
))
835 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
836 flags
, (void*)data_page
);
840 free_page(data_page
);
846 free_page(type_page
);
851 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
852 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
853 ~(sizeof(compat_long_t)-1))
855 struct compat_old_linux_dirent
{
856 compat_ulong_t d_ino
;
857 compat_ulong_t d_offset
;
858 unsigned short d_namlen
;
862 struct compat_readdir_callback
{
863 struct compat_old_linux_dirent __user
*dirent
;
867 static int compat_fillonedir(void *__buf
, const char *name
, int namlen
,
868 loff_t offset
, ino_t ino
, unsigned int d_type
)
870 struct compat_readdir_callback
*buf
= __buf
;
871 struct compat_old_linux_dirent __user
*dirent
;
876 dirent
= buf
->dirent
;
877 if (!access_ok(VERIFY_WRITE
, dirent
,
878 (unsigned long)(dirent
->d_name
+ namlen
+ 1) -
879 (unsigned long)dirent
))
881 if ( __put_user(ino
, &dirent
->d_ino
) ||
882 __put_user(offset
, &dirent
->d_offset
) ||
883 __put_user(namlen
, &dirent
->d_namlen
) ||
884 __copy_to_user(dirent
->d_name
, name
, namlen
) ||
885 __put_user(0, dirent
->d_name
+ namlen
))
889 buf
->result
= -EFAULT
;
893 asmlinkage
long compat_sys_old_readdir(unsigned int fd
,
894 struct compat_old_linux_dirent __user
*dirent
, unsigned int count
)
898 struct compat_readdir_callback buf
;
908 error
= vfs_readdir(file
, compat_fillonedir
, &buf
);
917 struct compat_linux_dirent
{
918 compat_ulong_t d_ino
;
919 compat_ulong_t d_off
;
920 unsigned short d_reclen
;
924 struct compat_getdents_callback
{
925 struct compat_linux_dirent __user
*current_dir
;
926 struct compat_linux_dirent __user
*previous
;
931 static int compat_filldir(void *__buf
, const char *name
, int namlen
,
932 loff_t offset
, ino_t ino
, unsigned int d_type
)
934 struct compat_linux_dirent __user
* dirent
;
935 struct compat_getdents_callback
*buf
= __buf
;
936 int reclen
= COMPAT_ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 2);
938 buf
->error
= -EINVAL
; /* only used if we fail.. */
939 if (reclen
> buf
->count
)
941 dirent
= buf
->previous
;
943 if (__put_user(offset
, &dirent
->d_off
))
946 dirent
= buf
->current_dir
;
947 if (__put_user(ino
, &dirent
->d_ino
))
949 if (__put_user(reclen
, &dirent
->d_reclen
))
951 if (copy_to_user(dirent
->d_name
, name
, namlen
))
953 if (__put_user(0, dirent
->d_name
+ namlen
))
955 if (__put_user(d_type
, (char __user
*) dirent
+ reclen
- 1))
957 buf
->previous
= dirent
;
958 dirent
= (void __user
*)dirent
+ reclen
;
959 buf
->current_dir
= dirent
;
960 buf
->count
-= reclen
;
963 buf
->error
= -EFAULT
;
967 asmlinkage
long compat_sys_getdents(unsigned int fd
,
968 struct compat_linux_dirent __user
*dirent
, unsigned int count
)
971 struct compat_linux_dirent __user
* lastdirent
;
972 struct compat_getdents_callback buf
;
976 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
984 buf
.current_dir
= dirent
;
989 error
= vfs_readdir(file
, compat_filldir
, &buf
);
993 lastdirent
= buf
.previous
;
995 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
998 error
= count
- buf
.count
;
1007 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1008 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1010 struct compat_getdents_callback64
{
1011 struct linux_dirent64 __user
*current_dir
;
1012 struct linux_dirent64 __user
*previous
;
1017 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
1018 ino_t ino
, unsigned int d_type
)
1020 struct linux_dirent64 __user
*dirent
;
1021 struct compat_getdents_callback64
*buf
= __buf
;
1022 int jj
= NAME_OFFSET(dirent
);
1023 int reclen
= COMPAT_ROUND_UP64(jj
+ namlen
+ 1);
1026 buf
->error
= -EINVAL
; /* only used if we fail.. */
1027 if (reclen
> buf
->count
)
1029 dirent
= buf
->previous
;
1032 if (__put_user_unaligned(offset
, &dirent
->d_off
))
1035 dirent
= buf
->current_dir
;
1036 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
1039 if (__put_user_unaligned(off
, &dirent
->d_off
))
1041 if (__put_user(reclen
, &dirent
->d_reclen
))
1043 if (__put_user(d_type
, &dirent
->d_type
))
1045 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1047 if (__put_user(0, dirent
->d_name
+ namlen
))
1049 buf
->previous
= dirent
;
1050 dirent
= (void __user
*)dirent
+ reclen
;
1051 buf
->current_dir
= dirent
;
1052 buf
->count
-= reclen
;
1055 buf
->error
= -EFAULT
;
1059 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
1060 struct linux_dirent64 __user
* dirent
, unsigned int count
)
1063 struct linux_dirent64 __user
* lastdirent
;
1064 struct compat_getdents_callback64 buf
;
1068 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1076 buf
.current_dir
= dirent
;
1077 buf
.previous
= NULL
;
1081 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1085 lastdirent
= buf
.previous
;
1087 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1088 __put_user_unaligned(d_off
, &lastdirent
->d_off
);
1089 error
= count
- buf
.count
;
1097 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1099 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1100 const struct compat_iovec __user
*uvector
,
1101 unsigned long nr_segs
, loff_t
*pos
)
1103 typedef ssize_t (*io_fn_t
)(struct file
*, char __user
*, size_t, loff_t
*);
1104 typedef ssize_t (*iov_fn_t
)(struct file
*, const struct iovec
*, unsigned long, loff_t
*);
1106 compat_ssize_t tot_len
;
1107 struct iovec iovstack
[UIO_FASTIOV
];
1108 struct iovec
*iov
=iovstack
, *vector
;
1115 * SuS says "The readv() function *may* fail if the iovcnt argument
1116 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1117 * traditionally returned zero for zero segments, so...
1124 * First get the "struct iovec" from user memory and
1125 * verify all the pointers
1128 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1132 if (nr_segs
> UIO_FASTIOV
) {
1134 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1139 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1143 * Single unix specification:
1144 * We should -EINVAL if an element length is not >= 0 and fitting an
1145 * ssize_t. The total length is fitting an ssize_t
1147 * Be careful here because iov_len is a size_t not an ssize_t
1152 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1153 compat_ssize_t tmp
= tot_len
;
1157 if (__get_user(len
, &uvector
->iov_len
) ||
1158 __get_user(buf
, &uvector
->iov_base
)) {
1162 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1165 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1167 vector
->iov_base
= compat_ptr(buf
);
1168 vector
->iov_len
= (compat_size_t
) len
;
1177 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1183 fn
= file
->f_op
->read
;
1184 fnv
= file
->f_op
->readv
;
1186 fn
= (io_fn_t
)file
->f_op
->write
;
1187 fnv
= file
->f_op
->writev
;
1190 ret
= fnv(file
, iov
, nr_segs
, pos
);
1194 /* Do it by hand, with file-ops */
1197 while (nr_segs
> 0) {
1202 base
= vector
->iov_base
;
1203 len
= vector
->iov_len
;
1207 nr
= fn(file
, base
, len
, pos
);
1218 if (iov
!= iovstack
)
1220 if ((ret
+ (type
== READ
)) > 0) {
1221 struct dentry
*dentry
= file
->f_dentry
;
1223 fsnotify_access(dentry
);
1225 fsnotify_modify(dentry
);
1231 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1234 ssize_t ret
= -EBADF
;
1240 if (!(file
->f_mode
& FMODE_READ
))
1244 if (!file
->f_op
|| (!file
->f_op
->readv
&& !file
->f_op
->read
))
1247 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1255 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1258 ssize_t ret
= -EBADF
;
1263 if (!(file
->f_mode
& FMODE_WRITE
))
1267 if (!file
->f_op
|| (!file
->f_op
->writev
&& !file
->f_op
->write
))
1270 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1278 * compat_count() counts the number of arguments/envelopes. It is basically
1279 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1280 * and envp pointers.
1282 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1290 if (get_user(p
, argv
))
1303 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1304 * except that it works with 32 bit argv and envp pointers.
1306 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1307 struct linux_binprm
*bprm
)
1309 struct page
*kmapped_page
= NULL
;
1313 while (argc
-- > 0) {
1318 if (get_user(str
, argv
+argc
) ||
1319 !(len
= strnlen_user(compat_ptr(str
), bprm
->p
))) {
1324 if (bprm
->p
< len
) {
1330 /* XXX: add architecture specific overflow check here. */
1335 int offset
, bytes_to_copy
;
1338 offset
= pos
% PAGE_SIZE
;
1340 page
= bprm
->page
[i
];
1343 page
= alloc_page(GFP_HIGHUSER
);
1344 bprm
->page
[i
] = page
;
1352 if (page
!= kmapped_page
) {
1354 kunmap(kmapped_page
);
1355 kmapped_page
= page
;
1356 kaddr
= kmap(kmapped_page
);
1359 memset(kaddr
, 0, offset
);
1360 bytes_to_copy
= PAGE_SIZE
- offset
;
1361 if (bytes_to_copy
> len
) {
1362 bytes_to_copy
= len
;
1364 memset(kaddr
+offset
+len
, 0,
1365 PAGE_SIZE
-offset
-len
);
1367 err
= copy_from_user(kaddr
+offset
, compat_ptr(str
),
1374 pos
+= bytes_to_copy
;
1375 str
+= bytes_to_copy
;
1376 len
-= bytes_to_copy
;
1382 kunmap(kmapped_page
);
1388 #define free_arg_pages(bprm) do { } while (0)
1392 static inline void free_arg_pages(struct linux_binprm
*bprm
)
1396 for (i
= 0; i
< MAX_ARG_PAGES
; i
++) {
1398 __free_page(bprm
->page
[i
]);
1399 bprm
->page
[i
] = NULL
;
1403 #endif /* CONFIG_MMU */
1406 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1407 * that it processes 32 bit argv and envp pointers.
1409 int compat_do_execve(char * filename
,
1410 compat_uptr_t __user
*argv
,
1411 compat_uptr_t __user
*envp
,
1412 struct pt_regs
* regs
)
1414 struct linux_binprm
*bprm
;
1420 bprm
= kmalloc(sizeof(*bprm
), GFP_KERNEL
);
1423 memset(bprm
, 0, sizeof(*bprm
));
1425 file
= open_exec(filename
);
1426 retval
= PTR_ERR(file
);
1432 bprm
->p
= PAGE_SIZE
*MAX_ARG_PAGES
-sizeof(void *);
1434 bprm
->filename
= filename
;
1435 bprm
->interp
= filename
;
1436 bprm
->mm
= mm_alloc();
1441 retval
= init_new_context(current
, bprm
->mm
);
1445 bprm
->argc
= compat_count(argv
, bprm
->p
/ sizeof(compat_uptr_t
));
1446 if ((retval
= bprm
->argc
) < 0)
1449 bprm
->envc
= compat_count(envp
, bprm
->p
/ sizeof(compat_uptr_t
));
1450 if ((retval
= bprm
->envc
) < 0)
1453 retval
= security_bprm_alloc(bprm
);
1457 retval
= prepare_binprm(bprm
);
1461 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1465 bprm
->exec
= bprm
->p
;
1466 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1470 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1474 retval
= search_binary_handler(bprm
, regs
);
1476 free_arg_pages(bprm
);
1478 /* execve success */
1479 security_bprm_free(bprm
);
1485 /* Something went wrong, return the inode and free the argument pages*/
1486 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
1487 struct page
* page
= bprm
->page
[i
];
1493 security_bprm_free(bprm
);
1501 allow_write_access(bprm
->file
);
1512 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1514 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1517 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1518 * 64-bit unsigned longs.
1521 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1522 unsigned long *fdset
)
1524 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1528 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1535 __get_user(l
, ufdset
);
1536 __get_user(h
, ufdset
+1);
1538 *fdset
++ = h
<< 32 | l
;
1542 __get_user(*fdset
, ufdset
);
1544 /* Tricky, must clear full unsigned long in the
1545 * kernel fdset at the end, this makes sure that
1548 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1554 void compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1555 unsigned long *fdset
)
1558 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1569 __put_user(l
, ufdset
);
1570 __put_user(h
, ufdset
+1);
1575 __put_user(*fdset
, ufdset
);
1580 * This is a virtual copy of sys_select from fs/select.c and probably
1581 * should be compared to it from time to time
1583 static void *select_bits_alloc(int size
)
1585 return kmalloc(6 * size
, GFP_KERNEL
);
1588 static void select_bits_free(void *bits
, int size
)
1594 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1595 * like to be certain this leads to no problems. So I return
1596 * EINTR just for safety.
1598 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1599 * I'm trying ERESTARTNOHAND which restart only when you want to.
1601 #define MAX_SELECT_SECONDS \
1602 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1605 compat_sys_select(int n
, compat_ulong_t __user
*inp
, compat_ulong_t __user
*outp
,
1606 compat_ulong_t __user
*exp
, struct compat_timeval __user
*tvp
)
1611 int size
, max_fdset
, ret
= -EINVAL
;
1613 timeout
= MAX_SCHEDULE_TIMEOUT
;
1617 if (!access_ok(VERIFY_READ
, tvp
, sizeof(*tvp
))
1618 || __get_user(sec
, &tvp
->tv_sec
)
1619 || __get_user(usec
, &tvp
->tv_usec
)) {
1624 if (sec
< 0 || usec
< 0)
1627 if ((unsigned long) sec
< MAX_SELECT_SECONDS
) {
1628 timeout
= ROUND_UP(usec
, 1000000/HZ
);
1629 timeout
+= sec
* (unsigned long) HZ
;
1636 /* max_fdset can increase, so grab it once to avoid race */
1637 max_fdset
= current
->files
->max_fdset
;
1642 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1643 * since we used fdset we need to allocate memory in units of
1647 size
= FDS_BYTES(n
);
1648 bits
= select_bits_alloc(size
);
1651 fds
.in
= (unsigned long *) bits
;
1652 fds
.out
= (unsigned long *) (bits
+ size
);
1653 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1654 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1655 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1656 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1658 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1659 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1660 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1662 zero_fd_set(n
, fds
.res_in
);
1663 zero_fd_set(n
, fds
.res_out
);
1664 zero_fd_set(n
, fds
.res_ex
);
1666 ret
= do_select(n
, &fds
, &timeout
);
1668 if (tvp
&& !(current
->personality
& STICKY_TIMEOUTS
)) {
1669 time_t sec
= 0, usec
= 0;
1672 usec
= timeout
% HZ
;
1673 usec
*= (1000000/HZ
);
1675 if (put_user(sec
, &tvp
->tv_sec
) ||
1676 put_user(usec
, &tvp
->tv_usec
))
1683 ret
= -ERESTARTNOHAND
;
1684 if (signal_pending(current
))
1689 compat_set_fd_set(n
, inp
, fds
.res_in
);
1690 compat_set_fd_set(n
, outp
, fds
.res_out
);
1691 compat_set_fd_set(n
, exp
, fds
.res_ex
);
1694 select_bits_free(bits
, size
);
1699 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1700 /* Stuff for NFS server syscalls... */
1701 struct compat_nfsctl_svc
{
1706 struct compat_nfsctl_client
{
1707 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
1709 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
1712 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
1715 struct compat_nfsctl_export
{
1716 char ex32_client
[NFSCLNT_IDMAX
+1];
1717 char ex32_path
[NFS_MAXPATHLEN
+1];
1718 compat_dev_t ex32_dev
;
1719 compat_ino_t ex32_ino
;
1720 compat_int_t ex32_flags
;
1721 __compat_uid_t ex32_anon_uid
;
1722 __compat_gid_t ex32_anon_gid
;
1725 struct compat_nfsctl_fdparm
{
1726 struct sockaddr gd32_addr
;
1727 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1728 compat_int_t gd32_version
;
1731 struct compat_nfsctl_fsparm
{
1732 struct sockaddr gd32_addr
;
1733 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1734 compat_int_t gd32_maxlen
;
1737 struct compat_nfsctl_arg
{
1738 compat_int_t ca32_version
; /* safeguard */
1740 struct compat_nfsctl_svc u32_svc
;
1741 struct compat_nfsctl_client u32_client
;
1742 struct compat_nfsctl_export u32_export
;
1743 struct compat_nfsctl_fdparm u32_getfd
;
1744 struct compat_nfsctl_fsparm u32_getfs
;
1746 #define ca32_svc u.u32_svc
1747 #define ca32_client u.u32_client
1748 #define ca32_export u.u32_export
1749 #define ca32_getfd u.u32_getfd
1750 #define ca32_getfs u.u32_getfs
1753 union compat_nfsctl_res
{
1754 __u8 cr32_getfh
[NFS_FHSIZE
];
1755 struct knfsd_fh cr32_getfs
;
1758 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1762 err
= access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
));
1763 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1764 err
|= __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
);
1765 err
|= __get_user(karg
->ca_svc
.svc_nthreads
, &arg
->ca32_svc
.svc32_nthreads
);
1766 return (err
) ? -EFAULT
: 0;
1769 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1773 err
= access_ok(VERIFY_READ
, &arg
->ca32_client
, sizeof(arg
->ca32_client
));
1774 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1775 err
|= __copy_from_user(&karg
->ca_client
.cl_ident
[0],
1776 &arg
->ca32_client
.cl32_ident
[0],
1778 err
|= __get_user(karg
->ca_client
.cl_naddr
, &arg
->ca32_client
.cl32_naddr
);
1779 err
|= __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
1780 &arg
->ca32_client
.cl32_addrlist
[0],
1781 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
));
1782 err
|= __get_user(karg
->ca_client
.cl_fhkeytype
,
1783 &arg
->ca32_client
.cl32_fhkeytype
);
1784 err
|= __get_user(karg
->ca_client
.cl_fhkeylen
,
1785 &arg
->ca32_client
.cl32_fhkeylen
);
1786 err
|= __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
1787 &arg
->ca32_client
.cl32_fhkey
[0],
1790 return (err
) ? -EFAULT
: 0;
1793 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1797 err
= access_ok(VERIFY_READ
, &arg
->ca32_export
, sizeof(arg
->ca32_export
));
1798 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1799 err
|= __copy_from_user(&karg
->ca_export
.ex_client
[0],
1800 &arg
->ca32_export
.ex32_client
[0],
1802 err
|= __copy_from_user(&karg
->ca_export
.ex_path
[0],
1803 &arg
->ca32_export
.ex32_path
[0],
1805 err
|= __get_user(karg
->ca_export
.ex_dev
,
1806 &arg
->ca32_export
.ex32_dev
);
1807 err
|= __get_user(karg
->ca_export
.ex_ino
,
1808 &arg
->ca32_export
.ex32_ino
);
1809 err
|= __get_user(karg
->ca_export
.ex_flags
,
1810 &arg
->ca32_export
.ex32_flags
);
1811 err
|= __get_user(karg
->ca_export
.ex_anon_uid
,
1812 &arg
->ca32_export
.ex32_anon_uid
);
1813 err
|= __get_user(karg
->ca_export
.ex_anon_gid
,
1814 &arg
->ca32_export
.ex32_anon_gid
);
1815 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
1816 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
1818 return (err
) ? -EFAULT
: 0;
1821 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1825 err
= access_ok(VERIFY_READ
, &arg
->ca32_getfd
, sizeof(arg
->ca32_getfd
));
1826 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1827 err
|= __copy_from_user(&karg
->ca_getfd
.gd_addr
,
1828 &arg
->ca32_getfd
.gd32_addr
,
1829 (sizeof(struct sockaddr
)));
1830 err
|= __copy_from_user(&karg
->ca_getfd
.gd_path
,
1831 &arg
->ca32_getfd
.gd32_path
,
1832 (NFS_MAXPATHLEN
+1));
1833 err
|= __get_user(karg
->ca_getfd
.gd_version
,
1834 &arg
->ca32_getfd
.gd32_version
);
1836 return (err
) ? -EFAULT
: 0;
1839 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1843 err
= access_ok(VERIFY_READ
, &arg
->ca32_getfs
, sizeof(arg
->ca32_getfs
));
1844 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1845 err
|= __copy_from_user(&karg
->ca_getfs
.gd_addr
,
1846 &arg
->ca32_getfs
.gd32_addr
,
1847 (sizeof(struct sockaddr
)));
1848 err
|= __copy_from_user(&karg
->ca_getfs
.gd_path
,
1849 &arg
->ca32_getfs
.gd32_path
,
1850 (NFS_MAXPATHLEN
+1));
1851 err
|= __get_user(karg
->ca_getfs
.gd_maxlen
,
1852 &arg
->ca32_getfs
.gd32_maxlen
);
1854 return (err
) ? -EFAULT
: 0;
1857 /* This really doesn't need translations, we are only passing
1858 * back a union which contains opaque nfs file handle data.
1860 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
, union compat_nfsctl_res __user
*res
)
1864 err
= copy_to_user(res
, kres
, sizeof(*res
));
1866 return (err
) ? -EFAULT
: 0;
1869 asmlinkage
long compat_sys_nfsservctl(int cmd
, struct compat_nfsctl_arg __user
*arg
,
1870 union compat_nfsctl_res __user
*res
)
1872 struct nfsctl_arg
*karg
;
1873 union nfsctl_res
*kres
;
1877 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
1878 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
1879 if(!karg
|| !kres
) {
1886 err
= compat_nfs_svc_trans(karg
, arg
);
1889 case NFSCTL_ADDCLIENT
:
1890 err
= compat_nfs_clnt_trans(karg
, arg
);
1893 case NFSCTL_DELCLIENT
:
1894 err
= compat_nfs_clnt_trans(karg
, arg
);
1898 case NFSCTL_UNEXPORT
:
1899 err
= compat_nfs_exp_trans(karg
, arg
);
1903 err
= compat_nfs_getfd_trans(karg
, arg
);
1907 err
= compat_nfs_getfs_trans(karg
, arg
);
1917 /* The __user pointer casts are valid because of the set_fs() */
1918 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
1924 if((cmd
== NFSCTL_GETFD
) ||
1925 (cmd
== NFSCTL_GETFS
))
1926 err
= compat_nfs_getfh_res_trans(kres
, res
);
1934 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
1936 return sys_ni_syscall();