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 int register_ioctl32_conversion(unsigned int cmd
,
314 ioctl_trans_handler_t handler
)
316 struct ioctl_trans
*t
;
317 struct ioctl_trans
*new_t
;
318 unsigned long hash
= ioctl32_hash(cmd
);
320 new_t
= kmalloc(sizeof(*new_t
), GFP_KERNEL
);
324 down_write(&ioctl32_sem
);
325 for (t
= ioctl32_hash_table
[hash
]; t
; t
= t
->next
) {
327 printk(KERN_ERR
"Trying to register duplicated ioctl32 "
328 "handler %x\n", cmd
);
329 up_write(&ioctl32_sem
);
336 new_t
->handler
= handler
;
337 ioctl32_insert_translation(new_t
);
339 up_write(&ioctl32_sem
);
342 EXPORT_SYMBOL(register_ioctl32_conversion
);
344 static inline int builtin_ioctl(struct ioctl_trans
*t
)
346 return t
>= ioctl_start
&& t
< (ioctl_start
+ ioctl_table_size
);
350 This function cannot unregister duplicate ioctls, because they are not
352 When they happen we need to extend the prototype to pass the handler too. */
354 int unregister_ioctl32_conversion(unsigned int cmd
)
356 unsigned long hash
= ioctl32_hash(cmd
);
357 struct ioctl_trans
*t
, *t1
;
359 down_write(&ioctl32_sem
);
361 t
= ioctl32_hash_table
[hash
];
363 up_write(&ioctl32_sem
);
368 if (builtin_ioctl(t
)) {
369 printk("%p tried to unregister builtin ioctl %x\n",
370 __builtin_return_address(0), cmd
);
372 ioctl32_hash_table
[hash
] = t
->next
;
373 up_write(&ioctl32_sem
);
380 if (t1
->cmd
== cmd
) {
381 if (builtin_ioctl(t1
)) {
382 printk("%p tried to unregister builtin "
384 __builtin_return_address(0), cmd
);
388 up_write(&ioctl32_sem
);
395 printk(KERN_ERR
"Trying to free unknown 32bit ioctl handler %x\n",
398 up_write(&ioctl32_sem
);
401 EXPORT_SYMBOL(unregister_ioctl32_conversion
);
403 static void compat_ioctl_error(struct file
*filp
, unsigned int fd
,
404 unsigned int cmd
, unsigned long arg
)
410 /* find the name of the device. */
411 path
= (char *)__get_free_page(GFP_KERNEL
);
413 fn
= d_path(filp
->f_dentry
, filp
->f_vfsmnt
, path
, PAGE_SIZE
);
418 sprintf(buf
,"'%c'", (cmd
>>24) & 0x3f);
419 if (!isprint(buf
[1]))
420 sprintf(buf
, "%02x", buf
[1]);
421 printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
422 "cmd(%08x){%s} arg(%08x) on %s\n",
423 current
->comm
, current
->pid
,
424 (int)fd
, (unsigned int)cmd
, buf
,
425 (unsigned int)arg
, fn
);
428 free_page((unsigned long)path
);
431 asmlinkage
long compat_sys_ioctl(unsigned int fd
, unsigned int cmd
,
436 struct ioctl_trans
*t
;
439 filp
= fget_light(fd
, &fput_needed
);
443 /* RED-PEN how should LSM module know it's handling 32bit? */
444 error
= security_file_ioctl(filp
, cmd
, arg
);
449 * To allow the compat_ioctl handlers to be self contained
450 * we need to check the common ioctls here first.
451 * Just handle them with the standard handlers below.
464 if (S_ISREG(filp
->f_dentry
->d_inode
->i_mode
))
469 if (filp
->f_op
&& filp
->f_op
->compat_ioctl
) {
470 error
= filp
->f_op
->compat_ioctl(filp
, cmd
, arg
);
471 if (error
!= -ENOIOCTLCMD
)
476 (!filp
->f_op
->ioctl
&& !filp
->f_op
->unlocked_ioctl
))
481 /* When register_ioctl32_conversion is finally gone remove
483 down_read(&ioctl32_sem
);
484 for (t
= ioctl32_hash_table
[ioctl32_hash(cmd
)]; t
; t
= t
->next
) {
488 up_read(&ioctl32_sem
);
490 if (S_ISSOCK(filp
->f_dentry
->d_inode
->i_mode
) &&
491 cmd
>= SIOCDEVPRIVATE
&& cmd
<= (SIOCDEVPRIVATE
+ 15)) {
492 error
= siocdevprivate_ioctl(fd
, cmd
, arg
);
497 compat_ioctl_error(filp
, fd
, cmd
, arg
);
506 error
= t
->handler(fd
, cmd
, arg
, filp
);
508 up_read(&ioctl32_sem
);
512 up_read(&ioctl32_sem
);
514 error
= vfs_ioctl(filp
, fd
, cmd
, arg
);
516 fput_light(filp
, fput_needed
);
521 static int get_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
523 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
524 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
525 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
526 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
527 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
528 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
533 static int put_compat_flock(struct flock
*kfl
, struct compat_flock __user
*ufl
)
535 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
536 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
537 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
538 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
539 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
540 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
545 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
546 static int get_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
548 if (!access_ok(VERIFY_READ
, ufl
, sizeof(*ufl
)) ||
549 __get_user(kfl
->l_type
, &ufl
->l_type
) ||
550 __get_user(kfl
->l_whence
, &ufl
->l_whence
) ||
551 __get_user(kfl
->l_start
, &ufl
->l_start
) ||
552 __get_user(kfl
->l_len
, &ufl
->l_len
) ||
553 __get_user(kfl
->l_pid
, &ufl
->l_pid
))
559 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
560 static int put_compat_flock64(struct flock
*kfl
, struct compat_flock64 __user
*ufl
)
562 if (!access_ok(VERIFY_WRITE
, ufl
, sizeof(*ufl
)) ||
563 __put_user(kfl
->l_type
, &ufl
->l_type
) ||
564 __put_user(kfl
->l_whence
, &ufl
->l_whence
) ||
565 __put_user(kfl
->l_start
, &ufl
->l_start
) ||
566 __put_user(kfl
->l_len
, &ufl
->l_len
) ||
567 __put_user(kfl
->l_pid
, &ufl
->l_pid
))
573 asmlinkage
long compat_sys_fcntl64(unsigned int fd
, unsigned int cmd
,
584 ret
= get_compat_flock(&f
, compat_ptr(arg
));
589 ret
= sys_fcntl(fd
, cmd
, (unsigned long)&f
);
591 if (cmd
== F_GETLK
&& ret
== 0) {
592 if ((f
.l_start
>= COMPAT_OFF_T_MAX
) ||
593 ((f
.l_start
+ f
.l_len
) > COMPAT_OFF_T_MAX
))
596 ret
= put_compat_flock(&f
, compat_ptr(arg
));
603 ret
= get_compat_flock64(&f
, compat_ptr(arg
));
608 ret
= sys_fcntl(fd
, (cmd
== F_GETLK64
) ? F_GETLK
:
609 ((cmd
== F_SETLK64
) ? F_SETLK
: F_SETLKW
),
612 if (cmd
== F_GETLK64
&& ret
== 0) {
613 if ((f
.l_start
>= COMPAT_LOFF_T_MAX
) ||
614 ((f
.l_start
+ f
.l_len
) > COMPAT_LOFF_T_MAX
))
617 ret
= put_compat_flock64(&f
, compat_ptr(arg
));
622 ret
= sys_fcntl(fd
, cmd
, arg
);
628 asmlinkage
long compat_sys_fcntl(unsigned int fd
, unsigned int cmd
,
631 if ((cmd
== F_GETLK64
) || (cmd
== F_SETLK64
) || (cmd
== F_SETLKW64
))
633 return compat_sys_fcntl64(fd
, cmd
, arg
);
637 compat_sys_io_setup(unsigned nr_reqs
, u32 __user
*ctx32p
)
642 mm_segment_t oldfs
= get_fs();
643 if (unlikely(get_user(ctx64
, ctx32p
)))
647 /* The __user pointer cast is valid because of the set_fs() */
648 ret
= sys_io_setup(nr_reqs
, (aio_context_t __user
*) &ctx64
);
650 /* truncating is ok because it's a user address */
652 ret
= put_user((u32
) ctx64
, ctx32p
);
657 compat_sys_io_getevents(aio_context_t ctx_id
,
658 unsigned long min_nr
,
660 struct io_event __user
*events
,
661 struct compat_timespec __user
*timeout
)
665 struct timespec __user
*ut
= NULL
;
668 if (unlikely(!access_ok(VERIFY_WRITE
, events
,
669 nr
* sizeof(struct io_event
))))
672 if (get_compat_timespec(&t
, timeout
))
675 ut
= compat_alloc_user_space(sizeof(*ut
));
676 if (copy_to_user(ut
, &t
, sizeof(t
)) )
679 ret
= sys_io_getevents(ctx_id
, min_nr
, nr
, events
, ut
);
685 copy_iocb(long nr
, u32 __user
*ptr32
, struct iocb __user
* __user
*ptr64
)
690 for (i
= 0; i
< nr
; ++i
) {
691 if (get_user(uptr
, ptr32
+ i
))
693 if (put_user(compat_ptr(uptr
), ptr64
+ i
))
699 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
702 compat_sys_io_submit(aio_context_t ctx_id
, int nr
, u32 __user
*iocb
)
704 struct iocb __user
* __user
*iocb64
;
707 if (unlikely(nr
< 0))
710 if (nr
> MAX_AIO_SUBMITS
)
711 nr
= MAX_AIO_SUBMITS
;
713 iocb64
= compat_alloc_user_space(nr
* sizeof(*iocb64
));
714 ret
= copy_iocb(nr
, iocb
, iocb64
);
716 ret
= sys_io_submit(ctx_id
, nr
, iocb64
);
720 struct compat_ncp_mount_data
{
721 compat_int_t version
;
722 compat_uint_t ncp_fd
;
723 compat_uid_t mounted_uid
;
724 compat_pid_t wdog_pid
;
725 unsigned char mounted_vol
[NCP_VOLNAME_LEN
+ 1];
726 compat_uint_t time_out
;
727 compat_uint_t retry_count
;
731 compat_mode_t file_mode
;
732 compat_mode_t dir_mode
;
735 struct compat_ncp_mount_data_v4
{
736 compat_int_t version
;
737 compat_ulong_t flags
;
738 compat_ulong_t mounted_uid
;
739 compat_long_t wdog_pid
;
740 compat_uint_t ncp_fd
;
741 compat_uint_t time_out
;
742 compat_uint_t retry_count
;
745 compat_ulong_t file_mode
;
746 compat_ulong_t dir_mode
;
749 static void *do_ncp_super_data_conv(void *raw_data
)
751 int version
= *(unsigned int *)raw_data
;
754 struct compat_ncp_mount_data
*c_n
= raw_data
;
755 struct ncp_mount_data
*n
= raw_data
;
757 n
->dir_mode
= c_n
->dir_mode
;
758 n
->file_mode
= c_n
->file_mode
;
761 memmove (n
->mounted_vol
, c_n
->mounted_vol
, (sizeof (c_n
->mounted_vol
) + 3 * sizeof (unsigned int)));
762 n
->wdog_pid
= c_n
->wdog_pid
;
763 n
->mounted_uid
= c_n
->mounted_uid
;
764 } else if (version
== 4) {
765 struct compat_ncp_mount_data_v4
*c_n
= raw_data
;
766 struct ncp_mount_data_v4
*n
= raw_data
;
768 n
->dir_mode
= c_n
->dir_mode
;
769 n
->file_mode
= c_n
->file_mode
;
772 n
->retry_count
= c_n
->retry_count
;
773 n
->time_out
= c_n
->time_out
;
774 n
->ncp_fd
= c_n
->ncp_fd
;
775 n
->wdog_pid
= c_n
->wdog_pid
;
776 n
->mounted_uid
= c_n
->mounted_uid
;
777 n
->flags
= c_n
->flags
;
778 } else if (version
!= 5) {
785 struct compat_smb_mount_data
{
786 compat_int_t version
;
787 compat_uid_t mounted_uid
;
790 compat_mode_t file_mode
;
791 compat_mode_t dir_mode
;
794 static void *do_smb_super_data_conv(void *raw_data
)
796 struct smb_mount_data
*s
= raw_data
;
797 struct compat_smb_mount_data
*c_s
= raw_data
;
799 if (c_s
->version
!= SMB_MOUNT_OLDVERSION
)
801 s
->dir_mode
= c_s
->dir_mode
;
802 s
->file_mode
= c_s
->file_mode
;
805 s
->mounted_uid
= c_s
->mounted_uid
;
810 struct compat_nfs_string
{
815 static inline void compat_nfs_string(struct nfs_string
*dst
,
816 struct compat_nfs_string
*src
)
818 dst
->data
= compat_ptr(src
->data
);
822 struct compat_nfs4_mount_data_v1
{
823 compat_int_t version
;
828 compat_int_t retrans
;
829 compat_int_t acregmin
;
830 compat_int_t acregmax
;
831 compat_int_t acdirmin
;
832 compat_int_t acdirmax
;
833 struct compat_nfs_string client_addr
;
834 struct compat_nfs_string mnt_path
;
835 struct compat_nfs_string hostname
;
836 compat_uint_t host_addrlen
;
837 compat_uptr_t host_addr
;
839 compat_int_t auth_flavourlen
;
840 compat_uptr_t auth_flavours
;
843 static int do_nfs4_super_data_conv(void *raw_data
)
845 int version
= *(compat_uint_t
*) raw_data
;
848 struct compat_nfs4_mount_data_v1
*raw
= raw_data
;
849 struct nfs4_mount_data
*real
= raw_data
;
851 /* copy the fields backwards */
852 real
->auth_flavours
= compat_ptr(raw
->auth_flavours
);
853 real
->auth_flavourlen
= raw
->auth_flavourlen
;
854 real
->proto
= raw
->proto
;
855 real
->host_addr
= compat_ptr(raw
->host_addr
);
856 real
->host_addrlen
= raw
->host_addrlen
;
857 compat_nfs_string(&real
->hostname
, &raw
->hostname
);
858 compat_nfs_string(&real
->mnt_path
, &raw
->mnt_path
);
859 compat_nfs_string(&real
->client_addr
, &raw
->client_addr
);
860 real
->acdirmax
= raw
->acdirmax
;
861 real
->acdirmin
= raw
->acdirmin
;
862 real
->acregmax
= raw
->acregmax
;
863 real
->acregmin
= raw
->acregmin
;
864 real
->retrans
= raw
->retrans
;
865 real
->timeo
= raw
->timeo
;
866 real
->wsize
= raw
->wsize
;
867 real
->rsize
= raw
->rsize
;
868 real
->flags
= raw
->flags
;
869 real
->version
= raw
->version
;
878 extern int copy_mount_options (const void __user
*, unsigned long *);
880 #define SMBFS_NAME "smbfs"
881 #define NCPFS_NAME "ncpfs"
882 #define NFS4_NAME "nfs4"
884 asmlinkage
long compat_sys_mount(char __user
* dev_name
, char __user
* dir_name
,
885 char __user
* type
, unsigned long flags
,
888 unsigned long type_page
;
889 unsigned long data_page
;
890 unsigned long dev_page
;
894 retval
= copy_mount_options (type
, &type_page
);
898 dir_page
= getname(dir_name
);
899 retval
= PTR_ERR(dir_page
);
900 if (IS_ERR(dir_page
))
903 retval
= copy_mount_options (dev_name
, &dev_page
);
907 retval
= copy_mount_options (data
, &data_page
);
914 if (!strcmp((char *)type_page
, SMBFS_NAME
)) {
915 do_smb_super_data_conv((void *)data_page
);
916 } else if (!strcmp((char *)type_page
, NCPFS_NAME
)) {
917 do_ncp_super_data_conv((void *)data_page
);
918 } else if (!strcmp((char *)type_page
, NFS4_NAME
)) {
919 if (do_nfs4_super_data_conv((void *) data_page
))
925 retval
= do_mount((char*)dev_page
, dir_page
, (char*)type_page
,
926 flags
, (void*)data_page
);
930 free_page(data_page
);
936 free_page(type_page
);
941 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
942 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
943 ~(sizeof(compat_long_t)-1))
945 struct compat_old_linux_dirent
{
946 compat_ulong_t d_ino
;
947 compat_ulong_t d_offset
;
948 unsigned short d_namlen
;
952 struct compat_readdir_callback
{
953 struct compat_old_linux_dirent __user
*dirent
;
957 static int compat_fillonedir(void *__buf
, const char *name
, int namlen
,
958 loff_t offset
, ino_t ino
, unsigned int d_type
)
960 struct compat_readdir_callback
*buf
= __buf
;
961 struct compat_old_linux_dirent __user
*dirent
;
966 dirent
= buf
->dirent
;
967 if (!access_ok(VERIFY_WRITE
, dirent
,
968 (unsigned long)(dirent
->d_name
+ namlen
+ 1) -
969 (unsigned long)dirent
))
971 if ( __put_user(ino
, &dirent
->d_ino
) ||
972 __put_user(offset
, &dirent
->d_offset
) ||
973 __put_user(namlen
, &dirent
->d_namlen
) ||
974 __copy_to_user(dirent
->d_name
, name
, namlen
) ||
975 __put_user(0, dirent
->d_name
+ namlen
))
979 buf
->result
= -EFAULT
;
983 asmlinkage
long compat_sys_old_readdir(unsigned int fd
,
984 struct compat_old_linux_dirent __user
*dirent
, unsigned int count
)
988 struct compat_readdir_callback buf
;
998 error
= vfs_readdir(file
, compat_fillonedir
, &buf
);
1007 struct compat_linux_dirent
{
1008 compat_ulong_t d_ino
;
1009 compat_ulong_t d_off
;
1010 unsigned short d_reclen
;
1014 struct compat_getdents_callback
{
1015 struct compat_linux_dirent __user
*current_dir
;
1016 struct compat_linux_dirent __user
*previous
;
1021 static int compat_filldir(void *__buf
, const char *name
, int namlen
,
1022 loff_t offset
, ino_t ino
, unsigned int d_type
)
1024 struct compat_linux_dirent __user
* dirent
;
1025 struct compat_getdents_callback
*buf
= __buf
;
1026 int reclen
= COMPAT_ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 2);
1028 buf
->error
= -EINVAL
; /* only used if we fail.. */
1029 if (reclen
> buf
->count
)
1031 dirent
= buf
->previous
;
1033 if (__put_user(offset
, &dirent
->d_off
))
1036 dirent
= buf
->current_dir
;
1037 if (__put_user(ino
, &dirent
->d_ino
))
1039 if (__put_user(reclen
, &dirent
->d_reclen
))
1041 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1043 if (__put_user(0, dirent
->d_name
+ namlen
))
1045 if (__put_user(d_type
, (char __user
*) dirent
+ reclen
- 1))
1047 buf
->previous
= dirent
;
1048 dirent
= (void __user
*)dirent
+ reclen
;
1049 buf
->current_dir
= dirent
;
1050 buf
->count
-= reclen
;
1053 buf
->error
= -EFAULT
;
1057 asmlinkage
long compat_sys_getdents(unsigned int fd
,
1058 struct compat_linux_dirent __user
*dirent
, unsigned int count
)
1061 struct compat_linux_dirent __user
* lastdirent
;
1062 struct compat_getdents_callback buf
;
1066 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1074 buf
.current_dir
= dirent
;
1075 buf
.previous
= NULL
;
1079 error
= vfs_readdir(file
, compat_filldir
, &buf
);
1083 lastdirent
= buf
.previous
;
1085 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
1088 error
= count
- buf
.count
;
1097 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1098 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1100 struct compat_getdents_callback64
{
1101 struct linux_dirent64 __user
*current_dir
;
1102 struct linux_dirent64 __user
*previous
;
1107 static int compat_filldir64(void * __buf
, const char * name
, int namlen
, loff_t offset
,
1108 ino_t ino
, unsigned int d_type
)
1110 struct linux_dirent64 __user
*dirent
;
1111 struct compat_getdents_callback64
*buf
= __buf
;
1112 int jj
= NAME_OFFSET(dirent
);
1113 int reclen
= COMPAT_ROUND_UP64(jj
+ namlen
+ 1);
1116 buf
->error
= -EINVAL
; /* only used if we fail.. */
1117 if (reclen
> buf
->count
)
1119 dirent
= buf
->previous
;
1122 if (__put_user_unaligned(offset
, &dirent
->d_off
))
1125 dirent
= buf
->current_dir
;
1126 if (__put_user_unaligned(ino
, &dirent
->d_ino
))
1129 if (__put_user_unaligned(off
, &dirent
->d_off
))
1131 if (__put_user(reclen
, &dirent
->d_reclen
))
1133 if (__put_user(d_type
, &dirent
->d_type
))
1135 if (copy_to_user(dirent
->d_name
, name
, namlen
))
1137 if (__put_user(0, dirent
->d_name
+ namlen
))
1139 buf
->previous
= dirent
;
1140 dirent
= (void __user
*)dirent
+ reclen
;
1141 buf
->current_dir
= dirent
;
1142 buf
->count
-= reclen
;
1145 buf
->error
= -EFAULT
;
1149 asmlinkage
long compat_sys_getdents64(unsigned int fd
,
1150 struct linux_dirent64 __user
* dirent
, unsigned int count
)
1153 struct linux_dirent64 __user
* lastdirent
;
1154 struct compat_getdents_callback64 buf
;
1158 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1166 buf
.current_dir
= dirent
;
1167 buf
.previous
= NULL
;
1171 error
= vfs_readdir(file
, compat_filldir64
, &buf
);
1175 lastdirent
= buf
.previous
;
1177 typeof(lastdirent
->d_off
) d_off
= file
->f_pos
;
1178 __put_user_unaligned(d_off
, &lastdirent
->d_off
);
1179 error
= count
- buf
.count
;
1187 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1189 static ssize_t
compat_do_readv_writev(int type
, struct file
*file
,
1190 const struct compat_iovec __user
*uvector
,
1191 unsigned long nr_segs
, loff_t
*pos
)
1193 typedef ssize_t (*io_fn_t
)(struct file
*, char __user
*, size_t, loff_t
*);
1194 typedef ssize_t (*iov_fn_t
)(struct file
*, const struct iovec
*, unsigned long, loff_t
*);
1196 compat_ssize_t tot_len
;
1197 struct iovec iovstack
[UIO_FASTIOV
];
1198 struct iovec
*iov
=iovstack
, *vector
;
1205 * SuS says "The readv() function *may* fail if the iovcnt argument
1206 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1207 * traditionally returned zero for zero segments, so...
1214 * First get the "struct iovec" from user memory and
1215 * verify all the pointers
1218 if ((nr_segs
> UIO_MAXIOV
) || (nr_segs
<= 0))
1222 if (nr_segs
> UIO_FASTIOV
) {
1224 iov
= kmalloc(nr_segs
*sizeof(struct iovec
), GFP_KERNEL
);
1229 if (!access_ok(VERIFY_READ
, uvector
, nr_segs
*sizeof(*uvector
)))
1233 * Single unix specification:
1234 * We should -EINVAL if an element length is not >= 0 and fitting an
1235 * ssize_t. The total length is fitting an ssize_t
1237 * Be careful here because iov_len is a size_t not an ssize_t
1242 for (seg
= 0 ; seg
< nr_segs
; seg
++) {
1243 compat_ssize_t tmp
= tot_len
;
1247 if (__get_user(len
, &uvector
->iov_len
) ||
1248 __get_user(buf
, &uvector
->iov_base
)) {
1252 if (len
< 0) /* size_t not fitting an compat_ssize_t .. */
1255 if (tot_len
< tmp
) /* maths overflow on the compat_ssize_t */
1257 vector
->iov_base
= compat_ptr(buf
);
1258 vector
->iov_len
= (compat_size_t
) len
;
1267 ret
= rw_verify_area(type
, file
, pos
, tot_len
);
1273 fn
= file
->f_op
->read
;
1274 fnv
= file
->f_op
->readv
;
1276 fn
= (io_fn_t
)file
->f_op
->write
;
1277 fnv
= file
->f_op
->writev
;
1280 ret
= fnv(file
, iov
, nr_segs
, pos
);
1284 /* Do it by hand, with file-ops */
1287 while (nr_segs
> 0) {
1292 base
= vector
->iov_base
;
1293 len
= vector
->iov_len
;
1297 nr
= fn(file
, base
, len
, pos
);
1308 if (iov
!= iovstack
)
1310 if ((ret
+ (type
== READ
)) > 0) {
1311 struct dentry
*dentry
= file
->f_dentry
;
1313 fsnotify_access(dentry
);
1315 fsnotify_modify(dentry
);
1321 compat_sys_readv(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1324 ssize_t ret
= -EBADF
;
1330 if (!(file
->f_mode
& FMODE_READ
))
1334 if (!file
->f_op
|| (!file
->f_op
->readv
&& !file
->f_op
->read
))
1337 ret
= compat_do_readv_writev(READ
, file
, vec
, vlen
, &file
->f_pos
);
1345 compat_sys_writev(unsigned long fd
, const struct compat_iovec __user
*vec
, unsigned long vlen
)
1348 ssize_t ret
= -EBADF
;
1353 if (!(file
->f_mode
& FMODE_WRITE
))
1357 if (!file
->f_op
|| (!file
->f_op
->writev
&& !file
->f_op
->write
))
1360 ret
= compat_do_readv_writev(WRITE
, file
, vec
, vlen
, &file
->f_pos
);
1368 * compat_count() counts the number of arguments/envelopes. It is basically
1369 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1370 * and envp pointers.
1372 static int compat_count(compat_uptr_t __user
*argv
, int max
)
1380 if (get_user(p
, argv
))
1393 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1394 * except that it works with 32 bit argv and envp pointers.
1396 static int compat_copy_strings(int argc
, compat_uptr_t __user
*argv
,
1397 struct linux_binprm
*bprm
)
1399 struct page
*kmapped_page
= NULL
;
1403 while (argc
-- > 0) {
1408 if (get_user(str
, argv
+argc
) ||
1409 !(len
= strnlen_user(compat_ptr(str
), bprm
->p
))) {
1414 if (bprm
->p
< len
) {
1420 /* XXX: add architecture specific overflow check here. */
1425 int offset
, bytes_to_copy
;
1428 offset
= pos
% PAGE_SIZE
;
1430 page
= bprm
->page
[i
];
1433 page
= alloc_page(GFP_HIGHUSER
);
1434 bprm
->page
[i
] = page
;
1442 if (page
!= kmapped_page
) {
1444 kunmap(kmapped_page
);
1445 kmapped_page
= page
;
1446 kaddr
= kmap(kmapped_page
);
1449 memset(kaddr
, 0, offset
);
1450 bytes_to_copy
= PAGE_SIZE
- offset
;
1451 if (bytes_to_copy
> len
) {
1452 bytes_to_copy
= len
;
1454 memset(kaddr
+offset
+len
, 0,
1455 PAGE_SIZE
-offset
-len
);
1457 err
= copy_from_user(kaddr
+offset
, compat_ptr(str
),
1464 pos
+= bytes_to_copy
;
1465 str
+= bytes_to_copy
;
1466 len
-= bytes_to_copy
;
1472 kunmap(kmapped_page
);
1478 #define free_arg_pages(bprm) do { } while (0)
1482 static inline void free_arg_pages(struct linux_binprm
*bprm
)
1486 for (i
= 0; i
< MAX_ARG_PAGES
; i
++) {
1488 __free_page(bprm
->page
[i
]);
1489 bprm
->page
[i
] = NULL
;
1493 #endif /* CONFIG_MMU */
1496 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1497 * that it processes 32 bit argv and envp pointers.
1499 int compat_do_execve(char * filename
,
1500 compat_uptr_t __user
*argv
,
1501 compat_uptr_t __user
*envp
,
1502 struct pt_regs
* regs
)
1504 struct linux_binprm
*bprm
;
1510 bprm
= kmalloc(sizeof(*bprm
), GFP_KERNEL
);
1513 memset(bprm
, 0, sizeof(*bprm
));
1515 file
= open_exec(filename
);
1516 retval
= PTR_ERR(file
);
1522 bprm
->p
= PAGE_SIZE
*MAX_ARG_PAGES
-sizeof(void *);
1524 bprm
->filename
= filename
;
1525 bprm
->interp
= filename
;
1526 bprm
->mm
= mm_alloc();
1531 retval
= init_new_context(current
, bprm
->mm
);
1535 bprm
->argc
= compat_count(argv
, bprm
->p
/ sizeof(compat_uptr_t
));
1536 if ((retval
= bprm
->argc
) < 0)
1539 bprm
->envc
= compat_count(envp
, bprm
->p
/ sizeof(compat_uptr_t
));
1540 if ((retval
= bprm
->envc
) < 0)
1543 retval
= security_bprm_alloc(bprm
);
1547 retval
= prepare_binprm(bprm
);
1551 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1555 bprm
->exec
= bprm
->p
;
1556 retval
= compat_copy_strings(bprm
->envc
, envp
, bprm
);
1560 retval
= compat_copy_strings(bprm
->argc
, argv
, bprm
);
1564 retval
= search_binary_handler(bprm
, regs
);
1566 free_arg_pages(bprm
);
1568 /* execve success */
1569 security_bprm_free(bprm
);
1575 /* Something went wrong, return the inode and free the argument pages*/
1576 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
1577 struct page
* page
= bprm
->page
[i
];
1583 security_bprm_free(bprm
);
1591 allow_write_access(bprm
->file
);
1602 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1604 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1607 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1608 * 64-bit unsigned longs.
1611 int compat_get_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1612 unsigned long *fdset
)
1614 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1618 if (!access_ok(VERIFY_WRITE
, ufdset
, nr
*sizeof(compat_ulong_t
)))
1625 __get_user(l
, ufdset
);
1626 __get_user(h
, ufdset
+1);
1628 *fdset
++ = h
<< 32 | l
;
1632 __get_user(*fdset
, ufdset
);
1634 /* Tricky, must clear full unsigned long in the
1635 * kernel fdset at the end, this makes sure that
1638 memset(fdset
, 0, ((nr
+ 1) & ~1)*sizeof(compat_ulong_t
));
1644 void compat_set_fd_set(unsigned long nr
, compat_ulong_t __user
*ufdset
,
1645 unsigned long *fdset
)
1648 nr
= ROUND_UP(nr
, __COMPAT_NFDBITS
);
1659 __put_user(l
, ufdset
);
1660 __put_user(h
, ufdset
+1);
1665 __put_user(*fdset
, ufdset
);
1670 * This is a virtual copy of sys_select from fs/select.c and probably
1671 * should be compared to it from time to time
1673 static void *select_bits_alloc(int size
)
1675 return kmalloc(6 * size
, GFP_KERNEL
);
1678 static void select_bits_free(void *bits
, int size
)
1684 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1685 * like to be certain this leads to no problems. So I return
1686 * EINTR just for safety.
1688 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1689 * I'm trying ERESTARTNOHAND which restart only when you want to.
1691 #define MAX_SELECT_SECONDS \
1692 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1695 compat_sys_select(int n
, compat_ulong_t __user
*inp
, compat_ulong_t __user
*outp
,
1696 compat_ulong_t __user
*exp
, struct compat_timeval __user
*tvp
)
1701 int size
, max_fdset
, ret
= -EINVAL
;
1703 timeout
= MAX_SCHEDULE_TIMEOUT
;
1707 if (!access_ok(VERIFY_READ
, tvp
, sizeof(*tvp
))
1708 || __get_user(sec
, &tvp
->tv_sec
)
1709 || __get_user(usec
, &tvp
->tv_usec
)) {
1714 if (sec
< 0 || usec
< 0)
1717 if ((unsigned long) sec
< MAX_SELECT_SECONDS
) {
1718 timeout
= ROUND_UP(usec
, 1000000/HZ
);
1719 timeout
+= sec
* (unsigned long) HZ
;
1726 /* max_fdset can increase, so grab it once to avoid race */
1727 max_fdset
= current
->files
->max_fdset
;
1732 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1733 * since we used fdset we need to allocate memory in units of
1737 size
= FDS_BYTES(n
);
1738 bits
= select_bits_alloc(size
);
1741 fds
.in
= (unsigned long *) bits
;
1742 fds
.out
= (unsigned long *) (bits
+ size
);
1743 fds
.ex
= (unsigned long *) (bits
+ 2*size
);
1744 fds
.res_in
= (unsigned long *) (bits
+ 3*size
);
1745 fds
.res_out
= (unsigned long *) (bits
+ 4*size
);
1746 fds
.res_ex
= (unsigned long *) (bits
+ 5*size
);
1748 if ((ret
= compat_get_fd_set(n
, inp
, fds
.in
)) ||
1749 (ret
= compat_get_fd_set(n
, outp
, fds
.out
)) ||
1750 (ret
= compat_get_fd_set(n
, exp
, fds
.ex
)))
1752 zero_fd_set(n
, fds
.res_in
);
1753 zero_fd_set(n
, fds
.res_out
);
1754 zero_fd_set(n
, fds
.res_ex
);
1756 ret
= do_select(n
, &fds
, &timeout
);
1758 if (tvp
&& !(current
->personality
& STICKY_TIMEOUTS
)) {
1759 time_t sec
= 0, usec
= 0;
1762 usec
= timeout
% HZ
;
1763 usec
*= (1000000/HZ
);
1765 if (put_user(sec
, &tvp
->tv_sec
) ||
1766 put_user(usec
, &tvp
->tv_usec
))
1773 ret
= -ERESTARTNOHAND
;
1774 if (signal_pending(current
))
1779 compat_set_fd_set(n
, inp
, fds
.res_in
);
1780 compat_set_fd_set(n
, outp
, fds
.res_out
);
1781 compat_set_fd_set(n
, exp
, fds
.res_ex
);
1784 select_bits_free(bits
, size
);
1789 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1790 /* Stuff for NFS server syscalls... */
1791 struct compat_nfsctl_svc
{
1796 struct compat_nfsctl_client
{
1797 s8 cl32_ident
[NFSCLNT_IDMAX
+1];
1799 struct in_addr cl32_addrlist
[NFSCLNT_ADDRMAX
];
1802 u8 cl32_fhkey
[NFSCLNT_KEYMAX
];
1805 struct compat_nfsctl_export
{
1806 char ex32_client
[NFSCLNT_IDMAX
+1];
1807 char ex32_path
[NFS_MAXPATHLEN
+1];
1808 compat_dev_t ex32_dev
;
1809 compat_ino_t ex32_ino
;
1810 compat_int_t ex32_flags
;
1811 compat_uid_t ex32_anon_uid
;
1812 compat_gid_t ex32_anon_gid
;
1815 struct compat_nfsctl_fdparm
{
1816 struct sockaddr gd32_addr
;
1817 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1818 compat_int_t gd32_version
;
1821 struct compat_nfsctl_fsparm
{
1822 struct sockaddr gd32_addr
;
1823 s8 gd32_path
[NFS_MAXPATHLEN
+1];
1824 compat_int_t gd32_maxlen
;
1827 struct compat_nfsctl_arg
{
1828 compat_int_t ca32_version
; /* safeguard */
1830 struct compat_nfsctl_svc u32_svc
;
1831 struct compat_nfsctl_client u32_client
;
1832 struct compat_nfsctl_export u32_export
;
1833 struct compat_nfsctl_fdparm u32_getfd
;
1834 struct compat_nfsctl_fsparm u32_getfs
;
1836 #define ca32_svc u.u32_svc
1837 #define ca32_client u.u32_client
1838 #define ca32_export u.u32_export
1839 #define ca32_getfd u.u32_getfd
1840 #define ca32_getfs u.u32_getfs
1843 union compat_nfsctl_res
{
1844 __u8 cr32_getfh
[NFS_FHSIZE
];
1845 struct knfsd_fh cr32_getfs
;
1848 static int compat_nfs_svc_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1852 err
= access_ok(VERIFY_READ
, &arg
->ca32_svc
, sizeof(arg
->ca32_svc
));
1853 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1854 err
|= __get_user(karg
->ca_svc
.svc_port
, &arg
->ca32_svc
.svc32_port
);
1855 err
|= __get_user(karg
->ca_svc
.svc_nthreads
, &arg
->ca32_svc
.svc32_nthreads
);
1856 return (err
) ? -EFAULT
: 0;
1859 static int compat_nfs_clnt_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1863 err
= access_ok(VERIFY_READ
, &arg
->ca32_client
, sizeof(arg
->ca32_client
));
1864 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1865 err
|= __copy_from_user(&karg
->ca_client
.cl_ident
[0],
1866 &arg
->ca32_client
.cl32_ident
[0],
1868 err
|= __get_user(karg
->ca_client
.cl_naddr
, &arg
->ca32_client
.cl32_naddr
);
1869 err
|= __copy_from_user(&karg
->ca_client
.cl_addrlist
[0],
1870 &arg
->ca32_client
.cl32_addrlist
[0],
1871 (sizeof(struct in_addr
) * NFSCLNT_ADDRMAX
));
1872 err
|= __get_user(karg
->ca_client
.cl_fhkeytype
,
1873 &arg
->ca32_client
.cl32_fhkeytype
);
1874 err
|= __get_user(karg
->ca_client
.cl_fhkeylen
,
1875 &arg
->ca32_client
.cl32_fhkeylen
);
1876 err
|= __copy_from_user(&karg
->ca_client
.cl_fhkey
[0],
1877 &arg
->ca32_client
.cl32_fhkey
[0],
1880 return (err
) ? -EFAULT
: 0;
1883 static int compat_nfs_exp_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1887 err
= access_ok(VERIFY_READ
, &arg
->ca32_export
, sizeof(arg
->ca32_export
));
1888 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1889 err
|= __copy_from_user(&karg
->ca_export
.ex_client
[0],
1890 &arg
->ca32_export
.ex32_client
[0],
1892 err
|= __copy_from_user(&karg
->ca_export
.ex_path
[0],
1893 &arg
->ca32_export
.ex32_path
[0],
1895 err
|= __get_user(karg
->ca_export
.ex_dev
,
1896 &arg
->ca32_export
.ex32_dev
);
1897 err
|= __get_user(karg
->ca_export
.ex_ino
,
1898 &arg
->ca32_export
.ex32_ino
);
1899 err
|= __get_user(karg
->ca_export
.ex_flags
,
1900 &arg
->ca32_export
.ex32_flags
);
1901 err
|= __get_user(karg
->ca_export
.ex_anon_uid
,
1902 &arg
->ca32_export
.ex32_anon_uid
);
1903 err
|= __get_user(karg
->ca_export
.ex_anon_gid
,
1904 &arg
->ca32_export
.ex32_anon_gid
);
1905 SET_UID(karg
->ca_export
.ex_anon_uid
, karg
->ca_export
.ex_anon_uid
);
1906 SET_GID(karg
->ca_export
.ex_anon_gid
, karg
->ca_export
.ex_anon_gid
);
1908 return (err
) ? -EFAULT
: 0;
1911 static int compat_nfs_getfd_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1915 err
= access_ok(VERIFY_READ
, &arg
->ca32_getfd
, sizeof(arg
->ca32_getfd
));
1916 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1917 err
|= __copy_from_user(&karg
->ca_getfd
.gd_addr
,
1918 &arg
->ca32_getfd
.gd32_addr
,
1919 (sizeof(struct sockaddr
)));
1920 err
|= __copy_from_user(&karg
->ca_getfd
.gd_path
,
1921 &arg
->ca32_getfd
.gd32_path
,
1922 (NFS_MAXPATHLEN
+1));
1923 err
|= __get_user(karg
->ca_getfd
.gd_version
,
1924 &arg
->ca32_getfd
.gd32_version
);
1926 return (err
) ? -EFAULT
: 0;
1929 static int compat_nfs_getfs_trans(struct nfsctl_arg
*karg
, struct compat_nfsctl_arg __user
*arg
)
1933 err
= access_ok(VERIFY_READ
, &arg
->ca32_getfs
, sizeof(arg
->ca32_getfs
));
1934 err
|= get_user(karg
->ca_version
, &arg
->ca32_version
);
1935 err
|= __copy_from_user(&karg
->ca_getfs
.gd_addr
,
1936 &arg
->ca32_getfs
.gd32_addr
,
1937 (sizeof(struct sockaddr
)));
1938 err
|= __copy_from_user(&karg
->ca_getfs
.gd_path
,
1939 &arg
->ca32_getfs
.gd32_path
,
1940 (NFS_MAXPATHLEN
+1));
1941 err
|= __get_user(karg
->ca_getfs
.gd_maxlen
,
1942 &arg
->ca32_getfs
.gd32_maxlen
);
1944 return (err
) ? -EFAULT
: 0;
1947 /* This really doesn't need translations, we are only passing
1948 * back a union which contains opaque nfs file handle data.
1950 static int compat_nfs_getfh_res_trans(union nfsctl_res
*kres
, union compat_nfsctl_res __user
*res
)
1954 err
= copy_to_user(res
, kres
, sizeof(*res
));
1956 return (err
) ? -EFAULT
: 0;
1959 asmlinkage
long compat_sys_nfsservctl(int cmd
, struct compat_nfsctl_arg __user
*arg
,
1960 union compat_nfsctl_res __user
*res
)
1962 struct nfsctl_arg
*karg
;
1963 union nfsctl_res
*kres
;
1967 karg
= kmalloc(sizeof(*karg
), GFP_USER
);
1968 kres
= kmalloc(sizeof(*kres
), GFP_USER
);
1969 if(!karg
|| !kres
) {
1976 err
= compat_nfs_svc_trans(karg
, arg
);
1979 case NFSCTL_ADDCLIENT
:
1980 err
= compat_nfs_clnt_trans(karg
, arg
);
1983 case NFSCTL_DELCLIENT
:
1984 err
= compat_nfs_clnt_trans(karg
, arg
);
1988 case NFSCTL_UNEXPORT
:
1989 err
= compat_nfs_exp_trans(karg
, arg
);
1993 err
= compat_nfs_getfd_trans(karg
, arg
);
1997 err
= compat_nfs_getfs_trans(karg
, arg
);
2007 /* The __user pointer casts are valid because of the set_fs() */
2008 err
= sys_nfsservctl(cmd
, (void __user
*) karg
, (void __user
*) kres
);
2014 if((cmd
== NFSCTL_GETFD
) ||
2015 (cmd
== NFSCTL_GETFS
))
2016 err
= compat_nfs_getfh_res_trans(kres
, res
);
2024 long asmlinkage
compat_sys_nfsservctl(int cmd
, void *notused
, void *notused2
)
2026 return sys_ni_syscall();