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(filename
, t
? tv
: NULL
);
74 asmlinkage
long compat_sys_utimes(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(filename
, t
? tv
: NULL
);
88 asmlinkage
long compat_sys_newstat(char __user
* filename
,
89 struct compat_stat __user
*statbuf
)
92 int error
= vfs_stat(filename
, &stat
);
95 error
= cp_compat_stat(&stat
, statbuf
);
99 asmlinkage
long compat_sys_newlstat(char __user
* filename
,
100 struct compat_stat __user
*statbuf
)
103 int error
= vfs_lstat(filename
, &stat
);
106 error
= cp_compat_stat(&stat
, statbuf
);
110 asmlinkage
long compat_sys_newfstat(unsigned int fd
,
111 struct compat_stat __user
* statbuf
)
114 int error
= vfs_fstat(fd
, &stat
);
117 error
= cp_compat_stat(&stat
, statbuf
);
121 static int put_compat_statfs(struct compat_statfs __user
*ubuf
, struct kstatfs
*kbuf
)
124 if (sizeof ubuf
->f_blocks
== 4) {
125 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
126 0xffffffff00000000ULL
)
128 /* f_files and f_ffree may be -1; it's okay
129 * to stuff that into 32 bits */
130 if (kbuf
->f_files
!= 0xffffffffffffffffULL
131 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
133 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
134 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
137 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
138 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
139 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
140 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
141 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
142 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
143 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
144 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
145 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
146 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
147 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
148 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
) ||
149 __put_user(0, &ubuf
->f_spare
[0]) ||
150 __put_user(0, &ubuf
->f_spare
[1]) ||
151 __put_user(0, &ubuf
->f_spare
[2]) ||
152 __put_user(0, &ubuf
->f_spare
[3]) ||
153 __put_user(0, &ubuf
->f_spare
[4]))
159 * The following statfs calls are copies of code from fs/open.c and
160 * should be checked against those from time to time
162 asmlinkage
long compat_sys_statfs(const char __user
*path
, struct compat_statfs __user
*buf
)
167 error
= user_path_walk(path
, &nd
);
170 error
= vfs_statfs(nd
.dentry
->d_inode
->i_sb
, &tmp
);
171 if (!error
&& put_compat_statfs(buf
, &tmp
))
178 asmlinkage
long compat_sys_fstatfs(unsigned int fd
, struct compat_statfs __user
*buf
)
188 error
= vfs_statfs(file
->f_dentry
->d_inode
->i_sb
, &tmp
);
189 if (!error
&& put_compat_statfs(buf
, &tmp
))
196 static int put_compat_statfs64(struct compat_statfs64 __user
*ubuf
, struct kstatfs
*kbuf
)
198 if (sizeof ubuf
->f_blocks
== 4) {
199 if ((kbuf
->f_blocks
| kbuf
->f_bfree
| kbuf
->f_bavail
) &
200 0xffffffff00000000ULL
)
202 /* f_files and f_ffree may be -1; it's okay
203 * to stuff that into 32 bits */
204 if (kbuf
->f_files
!= 0xffffffffffffffffULL
205 && (kbuf
->f_files
& 0xffffffff00000000ULL
))
207 if (kbuf
->f_ffree
!= 0xffffffffffffffffULL
208 && (kbuf
->f_ffree
& 0xffffffff00000000ULL
))
211 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)) ||
212 __put_user(kbuf
->f_type
, &ubuf
->f_type
) ||
213 __put_user(kbuf
->f_bsize
, &ubuf
->f_bsize
) ||
214 __put_user(kbuf
->f_blocks
, &ubuf
->f_blocks
) ||
215 __put_user(kbuf
->f_bfree
, &ubuf
->f_bfree
) ||
216 __put_user(kbuf
->f_bavail
, &ubuf
->f_bavail
) ||
217 __put_user(kbuf
->f_files
, &ubuf
->f_files
) ||
218 __put_user(kbuf
->f_ffree
, &ubuf
->f_ffree
) ||
219 __put_user(kbuf
->f_namelen
, &ubuf
->f_namelen
) ||
220 __put_user(kbuf
->f_fsid
.val
[0], &ubuf
->f_fsid
.val
[0]) ||
221 __put_user(kbuf
->f_fsid
.val
[1], &ubuf
->f_fsid
.val
[1]) ||
222 __put_user(kbuf
->f_frsize
, &ubuf
->f_frsize
))
227 asmlinkage
long compat_sys_statfs64(const char __user
*path
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
232 if (sz
!= sizeof(*buf
))
235 error
= user_path_walk(path
, &nd
);
238 error
= vfs_statfs(nd
.dentry
->d_inode
->i_sb
, &tmp
);
239 if (!error
&& put_compat_statfs64(buf
, &tmp
))
246 asmlinkage
long compat_sys_fstatfs64(unsigned int fd
, compat_size_t sz
, struct compat_statfs64 __user
*buf
)
252 if (sz
!= sizeof(*buf
))
259 error
= vfs_statfs(file
->f_dentry
->d_inode
->i_sb
, &tmp
);
260 if (!error
&& put_compat_statfs64(buf
, &tmp
))
267 /* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */
269 #define IOCTL_HASHSIZE 256
270 static struct ioctl_trans
*ioctl32_hash_table
[IOCTL_HASHSIZE
];
271 static DECLARE_RWSEM(ioctl32_sem
);
273 extern struct ioctl_trans ioctl_start
[];
274 extern int ioctl_table_size
;
276 static inline unsigned long ioctl32_hash(unsigned long cmd
)
278 return (((cmd
>> 6) ^ (cmd
>> 4) ^ cmd
)) % IOCTL_HASHSIZE
;
281 static void ioctl32_insert_translation(struct ioctl_trans
*trans
)
284 struct ioctl_trans
*t
;
286 hash
= ioctl32_hash (trans
->cmd
);
287 if (!ioctl32_hash_table
[hash
])
288 ioctl32_hash_table
[hash
] = trans
;
290 t
= ioctl32_hash_table
[hash
];
298 static int __init
init_sys32_ioctl(void)
302 for (i
= 0; i
< ioctl_table_size
; i
++) {
303 if (ioctl_start
[i
].next
!= 0) {
304 printk("ioctl translation %d bad\n",i
);
308 ioctl32_insert_translation(&ioctl_start
[i
]);
313 __initcall(init_sys32_ioctl
);
315 static void compat_ioctl_error(struct file
*filp
, unsigned int fd
,
316 unsigned int cmd
, unsigned long arg
)
322 /* find the name of the device. */
323 path
= (char *)__get_free_page(GFP_KERNEL
);
325 fn
= d_path(filp
->f_dentry
, filp
->f_vfsmnt
, path
, PAGE_SIZE
);
330 sprintf(buf
,"'%c'", (cmd
>>24) & 0x3f);
331 if (!isprint(buf
[1]))
332 sprintf(buf
, "%02x", buf
[1]);
333 printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
334 "cmd(%08x){%s} arg(%08x) on %s\n",
335 current
->comm
, current
->pid
,
336 (int)fd
, (unsigned int)cmd
, buf
,
337 (unsigned int)arg
, fn
);
340 free_page((unsigned long)path
);
343 asmlinkage
long compat_sys_ioctl(unsigned int fd
, unsigned int cmd
,
348 struct ioctl_trans
*t
;
351 filp
= fget_light(fd
, &fput_needed
);
355 /* RED-PEN how should LSM module know it's handling 32bit? */
356 error
= security_file_ioctl(filp
, cmd
, arg
);
361 * To allow the compat_ioctl handlers to be self contained
362 * we need to check the common ioctls here first.
363 * Just handle them with the standard handlers below.
376 if (S_ISREG(filp
->f_dentry
->d_inode
->i_mode
))
381 if (filp
->f_op
&& filp
->f_op
->compat_ioctl
) {
382 error
= filp
->f_op
->compat_ioctl(filp
, cmd
, arg
);
383 if (error
!= -ENOIOCTLCMD
)
388 (!filp
->f_op
->ioctl
&& !filp
->f_op
->unlocked_ioctl
))
393 /* When register_ioctl32_conversion is finally gone remove
395 down_read(&ioctl32_sem
);
396 for (t
= ioctl32_hash_table
[ioctl32_hash(cmd
)]; t
; t
= t
->next
) {
400 up_read(&ioctl32_sem
);
402 if (S_ISSOCK(filp
->f_dentry
->d_inode
->i_mode
) &&
403 cmd
>= SIOCDEVPRIVATE
&& cmd
<= (SIOCDEVPRIVATE
+ 15)) {
404 error
= siocdevprivate_ioctl(fd
, cmd
, arg
);
409 compat_ioctl_error(filp
, fd
, cmd
, arg
);
418 error
= t
->handler(fd
, cmd
, arg
, filp
);
420 up_read(&ioctl32_sem
);
424 up_read(&ioctl32_sem
);
426 error
= vfs_ioctl(filp
, fd
, cmd
, arg
);
428 fput_light(filp
, fput_needed
);
433 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
435 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
436 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
437 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
438 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
439 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
440 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
445 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
447 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
448 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
449 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
450 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
451 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
452 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
457 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
458 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
460 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
461 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
462 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
463 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
464 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
465 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
471 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
472 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
474 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
475 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
476 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
477 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
478 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
479 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
485 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
496 ret
= get_compat_flock(&f
, compat_ptr(arg
));
501 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
503 if (cmd
== F_GETLK
&& ret
== 0) {
504 if ((f
.l_start
>= COMPAT_OFF_T_MAX
) ||
505 ((f
.l_start
+ f
.l_len
) > COMPAT_OFF_T_MAX
))
508 ret
= put_compat_flock(&f
, compat_ptr(arg
));
515 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
520 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
521 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
524 if (cmd
== F_GETLK64
&& ret
== 0) {
525 if ((f
.l_start
>= COMPAT_LOFF_T_MAX
) ||
526 ((f
.l_start
+ f
.l_len
) > COMPAT_LOFF_T_MAX
))
529 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
534 ret
= sys_fcntl(fd
, cmd
, arg
);
540 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
543 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
545 return compat_sys_fcntl64(fd
, cmd
, arg
);
549 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
554 mm_segment_t oldfs
= get_fs();
555 if (unlikely(get_user(ctx64
, ctx32p
)))
559 /* The __user pointer cast is valid because of the set_fs() */
560 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
562 /* truncating is ok because it's a user address */
564 ret
= put_user((u32
) ctx64
, ctx32p
);
569 compat_sys_io_getevents(aio_context_t ctx_id
,
570 unsigned long min_nr
,
572 struct io_event __user
*events
,
573 struct compat_timespec __user
*timeout
)
577 struct timespec __user
*ut
= NULL
;
580 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
581 nr
* sizeof(struct io_event
))))
584 if (get_compat_timespec(&t
, timeout
))
587 ut
= compat_alloc_user_space(sizeof(*ut
));
588 if (copy_to_user(ut
, &t
, sizeof(t
)) )
591 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
597 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
602 for (i
= 0; i
< nr
; ++i
) {
603 if (get_user(uptr
, ptr32
+ i
))
605 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
611 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
614 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
616 struct iocb __user
* __user
*iocb64
;
619 if (unlikely(nr
< 0))
622 if (nr
> MAX_AIO_SUBMITS
)
623 nr
= MAX_AIO_SUBMITS
;
625 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
626 ret
= copy_iocb(nr
, iocb
, iocb64
);
628 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
632 struct compat_ncp_mount_data
{
633 compat_int_t version
;
634 compat_uint_t ncp_fd
;
635 __compat_uid_t mounted_uid
;
636 compat_pid_t wdog_pid
;
637 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
638 compat_uint_t time_out
;
639 compat_uint_t retry_count
;
643 compat_mode_t file_mode
;
644 compat_mode_t dir_mode
;
647 struct compat_ncp_mount_data_v4
{
648 compat_int_t version
;
649 compat_ulong_t flags
;
650 compat_ulong_t mounted_uid
;
651 compat_long_t wdog_pid
;
652 compat_uint_t ncp_fd
;
653 compat_uint_t time_out
;
654 compat_uint_t retry_count
;
657 compat_ulong_t file_mode
;
658 compat_ulong_t dir_mode
;
661 static void *do_ncp_super_data_conv(void *raw_data
)
663 int version
= *(unsigned int *)raw_data
;
666 struct compat_ncp_mount_data
*c_n
= raw_data
;
667 struct ncp_mount_data
*n
= raw_data
;
669 n
->dir_mode
= c_n
->dir_mode
;
670 n
->file_mode
= c_n
->file_mode
;
673 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
674 n
->wdog_pid
= c_n
->wdog_pid
;
675 n
->mounted_uid
= c_n
->mounted_uid
;
676 } else if (version
== 4) {
677 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
678 struct ncp_mount_data_v4
*n
= raw_data
;
680 n
->dir_mode
= c_n
->dir_mode
;
681 n
->file_mode
= c_n
->file_mode
;
684 n
->retry_count
= c_n
->retry_count
;
685 n
->time_out
= c_n
->time_out
;
686 n
->ncp_fd
= c_n
->ncp_fd
;
687 n
->wdog_pid
= c_n
->wdog_pid
;
688 n
->mounted_uid
= c_n
->mounted_uid
;
689 n
->flags
= c_n
->flags
;
690 } else if (version
!= 5) {
697 struct compat_smb_mount_data
{
698 compat_int_t version
;
699 __compat_uid_t mounted_uid
;
702 compat_mode_t file_mode
;
703 compat_mode_t dir_mode
;
706 static void *do_smb_super_data_conv(void *raw_data
)
708 struct smb_mount_data
*s
= raw_data
;
709 struct compat_smb_mount_data
*c_s
= raw_data
;
711 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
713 s
->dir_mode
= c_s
->dir_mode
;
714 s
->file_mode
= c_s
->file_mode
;
717 s
->mounted_uid
= c_s
->mounted_uid
;
722 struct compat_nfs_string
{
727 static inline void compat_nfs_string(struct nfs_string
*dst
,
728 struct compat_nfs_string
*src
)
730 dst
->data
= compat_ptr(src
->data
);
734 struct compat_nfs4_mount_data_v1
{
735 compat_int_t version
;
740 compat_int_t retrans
;
741 compat_int_t acregmin
;
742 compat_int_t acregmax
;
743 compat_int_t acdirmin
;
744 compat_int_t acdirmax
;
745 struct compat_nfs_string client_addr
;
746 struct compat_nfs_string mnt_path
;
747 struct compat_nfs_string hostname
;
748 compat_uint_t host_addrlen
;
749 compat_uptr_t host_addr
;
751 compat_int_t auth_flavourlen
;
752 compat_uptr_t auth_flavours
;
755 static int do_nfs4_super_data_conv(void *raw_data
)
757 int version
= *(compat_uint_t
*) raw_data
;
760 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
761 struct nfs4_mount_data
*real
= raw_data
;
763 /* copy the fields backwards */
764 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
765 real
->auth_flavourlen
= raw
->auth_flavourlen
;
766 real
->proto
= raw
->proto
;
767 real
->host_addr
= compat_ptr(raw
->host_addr
);
768 real
->host_addrlen
= raw
->host_addrlen
;
769 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
770 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
771 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
772 real
->acdirmax
= raw
->acdirmax
;
773 real
->acdirmin
= raw
->acdirmin
;
774 real
->acregmax
= raw
->acregmax
;
775 real
->acregmin
= raw
->acregmin
;
776 real
->retrans
= raw
->retrans
;
777 real
->timeo
= raw
->timeo
;
778 real
->wsize
= raw
->wsize
;
779 real
->rsize
= raw
->rsize
;
780 real
->flags
= raw
->flags
;
781 real
->version
= raw
->version
;
790 extern int copy_mount_options (const void __user
*, unsigned long *);
792 #define SMBFS_NAME "smbfs"
793 #define NCPFS_NAME "ncpfs"
794 #define NFS4_NAME "nfs4"
796 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
797 char __user
* type
, unsigned long flags
,
800 unsigned long type_page
;
801 unsigned long data_page
;
802 unsigned long dev_page
;
806 retval
= copy_mount_options (type
, &type_page
);
810 dir_page
= getname(dir_name
);
811 retval
= PTR_ERR(dir_page
);
812 if (IS_ERR(dir_page
))
815 retval
= copy_mount_options (dev_name
, &dev_page
);
819 retval
= copy_mount_options (data
, &data_page
);
826 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
827 do_smb_super_data_conv((void *)data_page
);
828 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
829 do_ncp_super_data_conv((void *)data_page
);
830 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
831 if (do_nfs4_super_data_conv((void *) data_page
))
837 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
838 flags
, (void*)data_page
);
842 free_page(data_page
);
848 free_page(type_page
);
853 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
854 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
855 ~(sizeof(compat_long_t)-1))
857 struct compat_old_linux_dirent
{
858 compat_ulong_t d_ino
;
859 compat_ulong_t d_offset
;
860 unsigned short d_namlen
;
864 struct compat_readdir_callback
{
865 struct compat_old_linux_dirent __user
*dirent
;
869 static int compat_fillonedir(void *__buf
, const char *name
, int namlen
,
870 loff_t offset
, ino_t ino
, unsigned int d_type
)
872 struct compat_readdir_callback
*buf
= __buf
;
873 struct compat_old_linux_dirent __user
*dirent
;
878 dirent
= buf
->dirent
;
879 if (!access_ok(VERIFY_WRITE
, dirent
,
880 (unsigned long)(dirent
->d_name
+ namlen
+ 1) -
881 (unsigned long)dirent
))
883 if ( __put_user(ino
, &dirent
->d_ino
) ||
884 __put_user(offset
, &dirent
->d_offset
) ||
885 __put_user(namlen
, &dirent
->d_namlen
) ||
886 __copy_to_user(dirent
->d_name
, name
, namlen
) ||
887 __put_user(0, dirent
->d_name
+ namlen
))
891 buf
->result
= -EFAULT
;
895 asmlinkage
long compat_sys_old_readdir(unsigned int fd
,
896 struct compat_old_linux_dirent __user
*dirent
, unsigned int count
)
900 struct compat_readdir_callback buf
;
910 error
= vfs_readdir(file
, compat_fillonedir
, &buf
);
919 struct compat_linux_dirent
{
920 compat_ulong_t d_ino
;
921 compat_ulong_t d_off
;
922 unsigned short d_reclen
;
926 struct compat_getdents_callback
{
927 struct compat_linux_dirent __user
*current_dir
;
928 struct compat_linux_dirent __user
*previous
;
933 static int compat_filldir(void *__buf
, const char *name
, int namlen
,
934 loff_t offset
, ino_t ino
, unsigned int d_type
)
936 struct compat_linux_dirent __user
* dirent
;
937 struct compat_getdents_callback
*buf
= __buf
;
938 int reclen
= COMPAT_ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 2);
940 buf
->error
= -EINVAL
; /* only used if we fail.. */
941 if (reclen
> buf
->count
)
943 dirent
= buf
->previous
;
945 if (__put_user(offset
, &dirent
->d_off
))
948 dirent
= buf
->current_dir
;
949 if (__put_user(ino
, &dirent
->d_ino
))
951 if (__put_user(reclen
, &dirent
->d_reclen
))
953 if (copy_to_user(dirent
->d_name
, name
, namlen
))
955 if (__put_user(0, dirent
->d_name
+ namlen
))
957 if (__put_user(d_type
, (char __user
*) dirent
+ reclen
- 1))
959 buf
->previous
= dirent
;
960 dirent
= (void __user
*)dirent
+ reclen
;
961 buf
->current_dir
= dirent
;
962 buf
->count
-= reclen
;
965 buf
->error
= -EFAULT
;
969 asmlinkage
long compat_sys_getdents(unsigned int fd
,
970 struct compat_linux_dirent __user
*dirent
, unsigned int count
)
973 struct compat_linux_dirent __user
* lastdirent
;
974 struct compat_getdents_callback buf
;
978 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
986 buf
.current_dir
= dirent
;
991 error
= vfs_readdir(file
, compat_filldir
, &buf
);
995 lastdirent
= buf
.previous
;
997 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
1000 error
= count
- buf
.count
;
1009 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1010 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1012 struct compat_getdents_callback64
{
1013 struct linux_dirent64 __user
*current_dir
;
1014 struct linux_dirent64 __user
*previous
;
1019 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
1020 ino_t ino
, unsigned int d_type
)
1022 struct linux_dirent64 __user
*dirent
;
1023 struct compat_getdents_callback64
*buf
= __buf
;
1024 int jj
= NAME_OFFSET(dirent
);
1025 int reclen
= COMPAT_ROUND_UP64(jj
+ namlen
+ 1);
1028 buf
->error
= -EINVAL
; /* only used if we fail.. */
1029 if (reclen
> buf
->count
)
1031 dirent
= buf
->previous
;
1034 if (__put_user_unaligned(offset
, &dirent
->d_off
))
1037 dirent
= buf
->current_dir
;
1038 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
1041 if (__put_user_unaligned(off
, &dirent
->d_off
))
1043 if (__put_user(reclen
, &dirent
->d_reclen
))
1045 if (__put_user(d_type
, &dirent
->d_type
))
1047 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1049 if (__put_user(0, dirent
->d_name
+ namlen
))
1051 buf
->previous
= dirent
;
1052 dirent
= (void __user
*)dirent
+ reclen
;
1053 buf
->current_dir
= dirent
;
1054 buf
->count
-= reclen
;
1057 buf
->error
= -EFAULT
;
1061 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
1062 struct linux_dirent64 __user
* dirent
, unsigned int count
)
1065 struct linux_dirent64 __user
* lastdirent
;
1066 struct compat_getdents_callback64 buf
;
1070 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1078 buf
.current_dir
= dirent
;
1079 buf
.previous
= NULL
;
1083 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1087 lastdirent
= buf
.previous
;
1089 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1090 __put_user_unaligned(d_off
, &lastdirent
->d_off
);
1091 error
= count
- buf
.count
;
1099 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1101 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1102 const struct compat_iovec __user
*uvector
,
1103 unsigned long nr_segs
, loff_t
*pos
)
1105 typedef ssize_t (*io_fn_t
)(struct file
*, char __user
*, size_t, loff_t
*);
1106 typedef ssize_t (*iov_fn_t
)(struct file
*, const struct iovec
*, unsigned long, loff_t
*);
1108 compat_ssize_t tot_len
;
1109 struct iovec iovstack
[UIO_FASTIOV
];
1110 struct iovec
*iov
=iovstack
, *vector
;
1117 * SuS says "The readv() function *may* fail if the iovcnt argument
1118 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1119 * traditionally returned zero for zero segments, so...
1126 * First get the "struct iovec" from user memory and
1127 * verify all the pointers
1130 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1134 if (nr_segs
> UIO_FASTIOV
) {
1136 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1141 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1145 * Single unix specification:
1146 * We should -EINVAL if an element length is not >= 0 and fitting an
1147 * ssize_t. The total length is fitting an ssize_t
1149 * Be careful here because iov_len is a size_t not an ssize_t
1154 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1155 compat_ssize_t tmp
= tot_len
;
1159 if (__get_user(len
, &uvector
->iov_len
) ||
1160 __get_user(buf
, &uvector
->iov_base
)) {
1164 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1167 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1169 vector
->iov_base
= compat_ptr(buf
);
1170 vector
->iov_len
= (compat_size_t
) len
;
1179 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1185 fn
= file
->f_op
->read
;
1186 fnv
= file
->f_op
->readv
;
1188 fn
= (io_fn_t
)file
->f_op
->write
;
1189 fnv
= file
->f_op
->writev
;
1192 ret
= fnv(file
, iov
, nr_segs
, pos
);
1196 /* Do it by hand, with file-ops */
1199 while (nr_segs
> 0) {
1204 base
= vector
->iov_base
;
1205 len
= vector
->iov_len
;
1209 nr
= fn(file
, base
, len
, pos
);
1220 if (iov
!= iovstack
)
1222 if ((ret
+ (type
== READ
)) > 0) {
1223 struct dentry
*dentry
= file
->f_dentry
;
1225 fsnotify_access(dentry
);
1227 fsnotify_modify(dentry
);
1233 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1236 ssize_t ret
= -EBADF
;
1242 if (!(file
->f_mode
& FMODE_READ
))
1246 if (!file
->f_op
|| (!file
->f_op
->readv
&& !file
->f_op
->read
))
1249 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1257 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1260 ssize_t ret
= -EBADF
;
1265 if (!(file
->f_mode
& FMODE_WRITE
))
1269 if (!file
->f_op
|| (!file
->f_op
->writev
&& !file
->f_op
->write
))
1272 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1280 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1284 compat_sys_open(const char __user
*filename
, int flags
, int mode
)
1286 return do_sys_open(filename
, flags
, mode
);
1290 * compat_count() counts the number of arguments/envelopes. It is basically
1291 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1292 * and envp pointers.
1294 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1302 if (get_user(p
, argv
))
1315 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1316 * except that it works with 32 bit argv and envp pointers.
1318 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1319 struct linux_binprm
*bprm
)
1321 struct page
*kmapped_page
= NULL
;
1325 while (argc
-- > 0) {
1330 if (get_user(str
, argv
+argc
) ||
1331 !(len
= strnlen_user(compat_ptr(str
), bprm
->p
))) {
1336 if (bprm
->p
< len
) {
1342 /* XXX: add architecture specific overflow check here. */
1347 int offset
, bytes_to_copy
;
1350 offset
= pos
% PAGE_SIZE
;
1352 page
= bprm
->page
[i
];
1355 page
= alloc_page(GFP_HIGHUSER
);
1356 bprm
->page
[i
] = page
;
1364 if (page
!= kmapped_page
) {
1366 kunmap(kmapped_page
);
1367 kmapped_page
= page
;
1368 kaddr
= kmap(kmapped_page
);
1371 memset(kaddr
, 0, offset
);
1372 bytes_to_copy
= PAGE_SIZE
- offset
;
1373 if (bytes_to_copy
> len
) {
1374 bytes_to_copy
= len
;
1376 memset(kaddr
+offset
+len
, 0,
1377 PAGE_SIZE
-offset
-len
);
1379 err
= copy_from_user(kaddr
+offset
, compat_ptr(str
),
1386 pos
+= bytes_to_copy
;
1387 str
+= bytes_to_copy
;
1388 len
-= bytes_to_copy
;
1394 kunmap(kmapped_page
);
1400 #define free_arg_pages(bprm) do { } while (0)
1404 static inline void free_arg_pages(struct linux_binprm
*bprm
)
1408 for (i
= 0; i
< MAX_ARG_PAGES
; i
++) {
1410 __free_page(bprm
->page
[i
]);
1411 bprm
->page
[i
] = NULL
;
1415 #endif /* CONFIG_MMU */
1418 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1419 * that it processes 32 bit argv and envp pointers.
1421 int compat_do_execve(char * filename
,
1422 compat_uptr_t __user
*argv
,
1423 compat_uptr_t __user
*envp
,
1424 struct pt_regs
* regs
)
1426 struct linux_binprm
*bprm
;
1432 bprm
= kmalloc(sizeof(*bprm
), GFP_KERNEL
);
1435 memset(bprm
, 0, sizeof(*bprm
));
1437 file
= open_exec(filename
);
1438 retval
= PTR_ERR(file
);
1444 bprm
->p
= PAGE_SIZE
*MAX_ARG_PAGES
-sizeof(void *);
1446 bprm
->filename
= filename
;
1447 bprm
->interp
= filename
;
1448 bprm
->mm
= mm_alloc();
1453 retval
= init_new_context(current
, bprm
->mm
);
1457 bprm
->argc
= compat_count(argv
, bprm
->p
/ sizeof(compat_uptr_t
));
1458 if ((retval
= bprm
->argc
) < 0)
1461 bprm
->envc
= compat_count(envp
, bprm
->p
/ sizeof(compat_uptr_t
));
1462 if ((retval
= bprm
->envc
) < 0)
1465 retval
= security_bprm_alloc(bprm
);
1469 retval
= prepare_binprm(bprm
);
1473 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1477 bprm
->exec
= bprm
->p
;
1478 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1482 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1486 retval
= search_binary_handler(bprm
, regs
);
1488 free_arg_pages(bprm
);
1490 /* execve success */
1491 security_bprm_free(bprm
);
1492 acct_update_integrals(current
);
1498 /* Something went wrong, return the inode and free the argument pages*/
1499 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
1500 struct page
* page
= bprm
->page
[i
];
1506 security_bprm_free(bprm
);
1514 allow_write_access(bprm
->file
);
1525 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1527 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1530 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1531 * 64-bit unsigned longs.
1534 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1535 unsigned long *fdset
)
1537 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1541 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1548 __get_user(l
, ufdset
);
1549 __get_user(h
, ufdset
+1);
1551 *fdset
++ = h
<< 32 | l
;
1555 __get_user(*fdset
, ufdset
);
1557 /* Tricky, must clear full unsigned long in the
1558 * kernel fdset at the end, this makes sure that
1561 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1567 void compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1568 unsigned long *fdset
)
1571 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1582 __put_user(l
, ufdset
);
1583 __put_user(h
, ufdset
+1);
1588 __put_user(*fdset
, ufdset
);
1593 * This is a virtual copy of sys_select from fs/select.c and probably
1594 * should be compared to it from time to time
1596 static void *select_bits_alloc(int size
)
1598 return kmalloc(6 * size
, GFP_KERNEL
);
1601 static void select_bits_free(void *bits
, int size
)
1607 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1608 * like to be certain this leads to no problems. So I return
1609 * EINTR just for safety.
1611 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1612 * I'm trying ERESTARTNOHAND which restart only when you want to.
1614 #define MAX_SELECT_SECONDS \
1615 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1618 compat_sys_select(int n
, compat_ulong_t __user
*inp
, compat_ulong_t __user
*outp
,
1619 compat_ulong_t __user
*exp
, struct compat_timeval __user
*tvp
)
1624 int size
, max_fdset
, ret
= -EINVAL
;
1625 struct fdtable
*fdt
;
1627 timeout
= MAX_SCHEDULE_TIMEOUT
;
1631 if (!access_ok(VERIFY_READ
, tvp
, sizeof(*tvp
))
1632 || __get_user(sec
, &tvp
->tv_sec
)
1633 || __get_user(usec
, &tvp
->tv_usec
)) {
1638 if (sec
< 0 || usec
< 0)
1641 if ((unsigned long) sec
< MAX_SELECT_SECONDS
) {
1642 timeout
= ROUND_UP(usec
, 1000000/HZ
);
1643 timeout
+= sec
* (unsigned long) HZ
;
1650 /* max_fdset can increase, so grab it once to avoid race */
1652 fdt
= files_fdtable(current
->files
);
1653 max_fdset
= fdt
->max_fdset
;
1659 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1660 * since we used fdset we need to allocate memory in units of
1664 size
= FDS_BYTES(n
);
1665 bits
= select_bits_alloc(size
);
1668 fds
.in
= (unsigned long *) bits
;
1669 fds
.out
= (unsigned long *) (bits
+ size
);
1670 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1671 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1672 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1673 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1675 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1676 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1677 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1679 zero_fd_set(n
, fds
.res_in
);
1680 zero_fd_set(n
, fds
.res_out
);
1681 zero_fd_set(n
, fds
.res_ex
);
1683 ret
= do_select(n
, &fds
, &timeout
);
1685 if (tvp
&& !(current
->personality
& STICKY_TIMEOUTS
)) {
1686 time_t sec
= 0, usec
= 0;
1689 usec
= timeout
% HZ
;
1690 usec
*= (1000000/HZ
);
1692 if (put_user(sec
, &tvp
->tv_sec
) ||
1693 put_user(usec
, &tvp
->tv_usec
))
1700 ret
= -ERESTARTNOHAND
;
1701 if (signal_pending(current
))
1706 compat_set_fd_set(n
, inp
, fds
.res_in
);
1707 compat_set_fd_set(n
, outp
, fds
.res_out
);
1708 compat_set_fd_set(n
, exp
, fds
.res_ex
);
1711 select_bits_free(bits
, size
);
1716 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1717 /* Stuff for NFS server syscalls... */
1718 struct compat_nfsctl_svc
{
1723 struct compat_nfsctl_client
{
1724 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
1726 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
1729 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
1732 struct compat_nfsctl_export
{
1733 char ex32_client
[NFSCLNT_IDMAX
+1];
1734 char ex32_path
[NFS_MAXPATHLEN
+1];
1735 compat_dev_t ex32_dev
;
1736 compat_ino_t ex32_ino
;
1737 compat_int_t ex32_flags
;
1738 __compat_uid_t ex32_anon_uid
;
1739 __compat_gid_t ex32_anon_gid
;
1742 struct compat_nfsctl_fdparm
{
1743 struct sockaddr gd32_addr
;
1744 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1745 compat_int_t gd32_version
;
1748 struct compat_nfsctl_fsparm
{
1749 struct sockaddr gd32_addr
;
1750 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1751 compat_int_t gd32_maxlen
;
1754 struct compat_nfsctl_arg
{
1755 compat_int_t ca32_version
; /* safeguard */
1757 struct compat_nfsctl_svc u32_svc
;
1758 struct compat_nfsctl_client u32_client
;
1759 struct compat_nfsctl_export u32_export
;
1760 struct compat_nfsctl_fdparm u32_getfd
;
1761 struct compat_nfsctl_fsparm u32_getfs
;
1763 #define ca32_svc u.u32_svc
1764 #define ca32_client u.u32_client
1765 #define ca32_export u.u32_export
1766 #define ca32_getfd u.u32_getfd
1767 #define ca32_getfs u.u32_getfs
1770 union compat_nfsctl_res
{
1771 __u8 cr32_getfh
[NFS_FHSIZE
];
1772 struct knfsd_fh cr32_getfs
;
1775 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1779 err
= access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
));
1780 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1781 err
|= __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
);
1782 err
|= __get_user(karg
->ca_svc
.svc_nthreads
, &arg
->ca32_svc
.svc32_nthreads
);
1783 return (err
) ? -EFAULT
: 0;
1786 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1790 err
= access_ok(VERIFY_READ
, &arg
->ca32_client
, sizeof(arg
->ca32_client
));
1791 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1792 err
|= __copy_from_user(&karg
->ca_client
.cl_ident
[0],
1793 &arg
->ca32_client
.cl32_ident
[0],
1795 err
|= __get_user(karg
->ca_client
.cl_naddr
, &arg
->ca32_client
.cl32_naddr
);
1796 err
|= __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
1797 &arg
->ca32_client
.cl32_addrlist
[0],
1798 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
));
1799 err
|= __get_user(karg
->ca_client
.cl_fhkeytype
,
1800 &arg
->ca32_client
.cl32_fhkeytype
);
1801 err
|= __get_user(karg
->ca_client
.cl_fhkeylen
,
1802 &arg
->ca32_client
.cl32_fhkeylen
);
1803 err
|= __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
1804 &arg
->ca32_client
.cl32_fhkey
[0],
1807 return (err
) ? -EFAULT
: 0;
1810 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1814 err
= access_ok(VERIFY_READ
, &arg
->ca32_export
, sizeof(arg
->ca32_export
));
1815 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1816 err
|= __copy_from_user(&karg
->ca_export
.ex_client
[0],
1817 &arg
->ca32_export
.ex32_client
[0],
1819 err
|= __copy_from_user(&karg
->ca_export
.ex_path
[0],
1820 &arg
->ca32_export
.ex32_path
[0],
1822 err
|= __get_user(karg
->ca_export
.ex_dev
,
1823 &arg
->ca32_export
.ex32_dev
);
1824 err
|= __get_user(karg
->ca_export
.ex_ino
,
1825 &arg
->ca32_export
.ex32_ino
);
1826 err
|= __get_user(karg
->ca_export
.ex_flags
,
1827 &arg
->ca32_export
.ex32_flags
);
1828 err
|= __get_user(karg
->ca_export
.ex_anon_uid
,
1829 &arg
->ca32_export
.ex32_anon_uid
);
1830 err
|= __get_user(karg
->ca_export
.ex_anon_gid
,
1831 &arg
->ca32_export
.ex32_anon_gid
);
1832 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
1833 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
1835 return (err
) ? -EFAULT
: 0;
1838 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1842 err
= access_ok(VERIFY_READ
, &arg
->ca32_getfd
, sizeof(arg
->ca32_getfd
));
1843 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1844 err
|= __copy_from_user(&karg
->ca_getfd
.gd_addr
,
1845 &arg
->ca32_getfd
.gd32_addr
,
1846 (sizeof(struct sockaddr
)));
1847 err
|= __copy_from_user(&karg
->ca_getfd
.gd_path
,
1848 &arg
->ca32_getfd
.gd32_path
,
1849 (NFS_MAXPATHLEN
+1));
1850 err
|= __get_user(karg
->ca_getfd
.gd_version
,
1851 &arg
->ca32_getfd
.gd32_version
);
1853 return (err
) ? -EFAULT
: 0;
1856 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1860 err
= access_ok(VERIFY_READ
, &arg
->ca32_getfs
, sizeof(arg
->ca32_getfs
));
1861 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1862 err
|= __copy_from_user(&karg
->ca_getfs
.gd_addr
,
1863 &arg
->ca32_getfs
.gd32_addr
,
1864 (sizeof(struct sockaddr
)));
1865 err
|= __copy_from_user(&karg
->ca_getfs
.gd_path
,
1866 &arg
->ca32_getfs
.gd32_path
,
1867 (NFS_MAXPATHLEN
+1));
1868 err
|= __get_user(karg
->ca_getfs
.gd_maxlen
,
1869 &arg
->ca32_getfs
.gd32_maxlen
);
1871 return (err
) ? -EFAULT
: 0;
1874 /* This really doesn't need translations, we are only passing
1875 * back a union which contains opaque nfs file handle data.
1877 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
, union compat_nfsctl_res __user
*res
)
1881 err
= copy_to_user(res
, kres
, sizeof(*res
));
1883 return (err
) ? -EFAULT
: 0;
1886 asmlinkage
long compat_sys_nfsservctl(int cmd
, struct compat_nfsctl_arg __user
*arg
,
1887 union compat_nfsctl_res __user
*res
)
1889 struct nfsctl_arg
*karg
;
1890 union nfsctl_res
*kres
;
1894 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
1895 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
1896 if(!karg
|| !kres
) {
1903 err
= compat_nfs_svc_trans(karg
, arg
);
1906 case NFSCTL_ADDCLIENT
:
1907 err
= compat_nfs_clnt_trans(karg
, arg
);
1910 case NFSCTL_DELCLIENT
:
1911 err
= compat_nfs_clnt_trans(karg
, arg
);
1915 case NFSCTL_UNEXPORT
:
1916 err
= compat_nfs_exp_trans(karg
, arg
);
1920 err
= compat_nfs_getfd_trans(karg
, arg
);
1924 err
= compat_nfs_getfs_trans(karg
, arg
);
1934 /* The __user pointer casts are valid because of the set_fs() */
1935 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
1941 if((cmd
== NFSCTL_GETFD
) ||
1942 (cmd
== NFSCTL_GETFS
))
1943 err
= compat_nfs_getfh_res_trans(kres
, res
);
1951 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
1953 return sys_ni_syscall();