[MIPS] DECstation defconfig update
[linux-2.6/linux-mips.git] / fs / compat.c
blob13fb08d096c436f5caba903abd57420935baa0cd
1 /*
2 * linux/fs/compat.c
4 * Kernel compatibililty routines for e.g. 32 bit syscall support
5 * on 64 bit kernels.
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>
22 #include <linux/fs.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/tsacct_kern.h>
48 #include <linux/mm.h>
50 #include <net/sock.h> /* siocdevprivate_ioctl */
52 #include <asm/uaccess.h>
53 #include <asm/mmu_context.h>
54 #include <asm/ioctls.h>
55 #include "internal.h"
57 int compat_log = 1;
59 extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat);
61 int compat_printk(const char *fmt, ...)
63 va_list ap;
64 int ret;
65 if (!compat_log)
66 return 0;
67 va_start(ap, fmt);
68 ret = vprintk(fmt, ap);
69 va_end(ap);
70 return ret;
73 #include "read_write.h"
76 * Not all architectures have sys_utime, so implement this in terms
77 * of sys_utimes.
79 asmlinkage long compat_sys_utime(char __user *filename, struct compat_utimbuf __user *t)
81 struct timeval tv[2];
83 if (t) {
84 if (get_user(tv[0].tv_sec, &t->actime) ||
85 get_user(tv[1].tv_sec, &t->modtime))
86 return -EFAULT;
87 tv[0].tv_usec = 0;
88 tv[1].tv_usec = 0;
90 return do_utimes(AT_FDCWD, filename, t ? tv : NULL);
93 asmlinkage long compat_sys_futimesat(unsigned int dfd, char __user *filename, struct compat_timeval __user *t)
95 struct timeval tv[2];
97 if (t) {
98 if (get_user(tv[0].tv_sec, &t[0].tv_sec) ||
99 get_user(tv[0].tv_usec, &t[0].tv_usec) ||
100 get_user(tv[1].tv_sec, &t[1].tv_sec) ||
101 get_user(tv[1].tv_usec, &t[1].tv_usec))
102 return -EFAULT;
104 return do_utimes(dfd, filename, t ? tv : NULL);
107 asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval __user *t)
109 return compat_sys_futimesat(AT_FDCWD, filename, t);
112 asmlinkage long compat_sys_newstat(char __user * filename,
113 struct compat_stat __user *statbuf)
115 struct kstat stat;
116 int error = vfs_stat_fd(AT_FDCWD, filename, &stat);
118 if (!error)
119 error = cp_compat_stat(&stat, statbuf);
120 return error;
123 asmlinkage long compat_sys_newlstat(char __user * filename,
124 struct compat_stat __user *statbuf)
126 struct kstat stat;
127 int error = vfs_lstat_fd(AT_FDCWD, filename, &stat);
129 if (!error)
130 error = cp_compat_stat(&stat, statbuf);
131 return error;
134 #ifndef __ARCH_WANT_STAT64
135 asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user *filename,
136 struct compat_stat __user *statbuf, int flag)
138 struct kstat stat;
139 int error = -EINVAL;
141 if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
142 goto out;
144 if (flag & AT_SYMLINK_NOFOLLOW)
145 error = vfs_lstat_fd(dfd, filename, &stat);
146 else
147 error = vfs_stat_fd(dfd, filename, &stat);
149 if (!error)
150 error = cp_compat_stat(&stat, statbuf);
152 out:
153 return error;
155 #endif
157 asmlinkage long compat_sys_newfstat(unsigned int fd,
158 struct compat_stat __user * statbuf)
160 struct kstat stat;
161 int error = vfs_fstat(fd, &stat);
163 if (!error)
164 error = cp_compat_stat(&stat, statbuf);
165 return error;
168 static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf)
171 if (sizeof ubuf->f_blocks == 4) {
172 if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail) &
173 0xffffffff00000000ULL)
174 return -EOVERFLOW;
175 /* f_files and f_ffree may be -1; it's okay
176 * to stuff that into 32 bits */
177 if (kbuf->f_files != 0xffffffffffffffffULL
178 && (kbuf->f_files & 0xffffffff00000000ULL))
179 return -EOVERFLOW;
180 if (kbuf->f_ffree != 0xffffffffffffffffULL
181 && (kbuf->f_ffree & 0xffffffff00000000ULL))
182 return -EOVERFLOW;
184 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
185 __put_user(kbuf->f_type, &ubuf->f_type) ||
186 __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
187 __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
188 __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
189 __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
190 __put_user(kbuf->f_files, &ubuf->f_files) ||
191 __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
192 __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
193 __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
194 __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
195 __put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
196 __put_user(0, &ubuf->f_spare[0]) ||
197 __put_user(0, &ubuf->f_spare[1]) ||
198 __put_user(0, &ubuf->f_spare[2]) ||
199 __put_user(0, &ubuf->f_spare[3]) ||
200 __put_user(0, &ubuf->f_spare[4]))
201 return -EFAULT;
202 return 0;
206 * The following statfs calls are copies of code from fs/open.c and
207 * should be checked against those from time to time
209 asmlinkage long compat_sys_statfs(const char __user *path, struct compat_statfs __user *buf)
211 struct nameidata nd;
212 int error;
214 error = user_path_walk(path, &nd);
215 if (!error) {
216 struct kstatfs tmp;
217 error = vfs_statfs(nd.dentry, &tmp);
218 if (!error)
219 error = put_compat_statfs(buf, &tmp);
220 path_release(&nd);
222 return error;
225 asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs __user *buf)
227 struct file * file;
228 struct kstatfs tmp;
229 int error;
231 error = -EBADF;
232 file = fget(fd);
233 if (!file)
234 goto out;
235 error = vfs_statfs(file->f_dentry, &tmp);
236 if (!error)
237 error = put_compat_statfs(buf, &tmp);
238 fput(file);
239 out:
240 return error;
243 static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
245 if (sizeof ubuf->f_blocks == 4) {
246 if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail) &
247 0xffffffff00000000ULL)
248 return -EOVERFLOW;
249 /* f_files and f_ffree may be -1; it's okay
250 * to stuff that into 32 bits */
251 if (kbuf->f_files != 0xffffffffffffffffULL
252 && (kbuf->f_files & 0xffffffff00000000ULL))
253 return -EOVERFLOW;
254 if (kbuf->f_ffree != 0xffffffffffffffffULL
255 && (kbuf->f_ffree & 0xffffffff00000000ULL))
256 return -EOVERFLOW;
258 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
259 __put_user(kbuf->f_type, &ubuf->f_type) ||
260 __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
261 __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
262 __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
263 __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
264 __put_user(kbuf->f_files, &ubuf->f_files) ||
265 __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
266 __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
267 __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
268 __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
269 __put_user(kbuf->f_frsize, &ubuf->f_frsize))
270 return -EFAULT;
271 return 0;
274 asmlinkage long compat_sys_statfs64(const char __user *path, compat_size_t sz, struct compat_statfs64 __user *buf)
276 struct nameidata nd;
277 int error;
279 if (sz != sizeof(*buf))
280 return -EINVAL;
282 error = user_path_walk(path, &nd);
283 if (!error) {
284 struct kstatfs tmp;
285 error = vfs_statfs(nd.dentry, &tmp);
286 if (!error)
287 error = put_compat_statfs64(buf, &tmp);
288 path_release(&nd);
290 return error;
293 asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user *buf)
295 struct file * file;
296 struct kstatfs tmp;
297 int error;
299 if (sz != sizeof(*buf))
300 return -EINVAL;
302 error = -EBADF;
303 file = fget(fd);
304 if (!file)
305 goto out;
306 error = vfs_statfs(file->f_dentry, &tmp);
307 if (!error)
308 error = put_compat_statfs64(buf, &tmp);
309 fput(file);
310 out:
311 return error;
314 /* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */
316 #define IOCTL_HASHSIZE 256
317 static struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE];
319 static inline unsigned long ioctl32_hash(unsigned long cmd)
321 return (((cmd >> 6) ^ (cmd >> 4) ^ cmd)) % IOCTL_HASHSIZE;
324 static void ioctl32_insert_translation(struct ioctl_trans *trans)
326 unsigned long hash;
327 struct ioctl_trans *t;
329 hash = ioctl32_hash (trans->cmd);
330 if (!ioctl32_hash_table[hash])
331 ioctl32_hash_table[hash] = trans;
332 else {
333 t = ioctl32_hash_table[hash];
334 while (t->next)
335 t = t->next;
336 trans->next = NULL;
337 t->next = trans;
341 static int __init init_sys32_ioctl(void)
343 int i;
345 for (i = 0; i < ioctl_table_size; i++) {
346 if (ioctl_start[i].next != 0) {
347 printk("ioctl translation %d bad\n",i);
348 return -1;
351 ioctl32_insert_translation(&ioctl_start[i]);
353 return 0;
356 __initcall(init_sys32_ioctl);
358 static void compat_ioctl_error(struct file *filp, unsigned int fd,
359 unsigned int cmd, unsigned long arg)
361 char buf[10];
362 char *fn = "?";
363 char *path;
365 /* find the name of the device. */
366 path = (char *)__get_free_page(GFP_KERNEL);
367 if (path) {
368 fn = d_path(filp->f_dentry, filp->f_vfsmnt, path, PAGE_SIZE);
369 if (IS_ERR(fn))
370 fn = "?";
373 sprintf(buf,"'%c'", (cmd>>24) & 0x3f);
374 if (!isprint(buf[1]))
375 sprintf(buf, "%02x", buf[1]);
376 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
377 "cmd(%08x){%s} arg(%08x) on %s\n",
378 current->comm, current->pid,
379 (int)fd, (unsigned int)cmd, buf,
380 (unsigned int)arg, fn);
382 if (path)
383 free_page((unsigned long)path);
386 asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
387 unsigned long arg)
389 struct file *filp;
390 int error = -EBADF;
391 struct ioctl_trans *t;
392 int fput_needed;
394 filp = fget_light(fd, &fput_needed);
395 if (!filp)
396 goto out;
398 /* RED-PEN how should LSM module know it's handling 32bit? */
399 error = security_file_ioctl(filp, cmd, arg);
400 if (error)
401 goto out_fput;
404 * To allow the compat_ioctl handlers to be self contained
405 * we need to check the common ioctls here first.
406 * Just handle them with the standard handlers below.
408 switch (cmd) {
409 case FIOCLEX:
410 case FIONCLEX:
411 case FIONBIO:
412 case FIOASYNC:
413 case FIOQSIZE:
414 break;
416 case FIBMAP:
417 case FIGETBSZ:
418 case FIONREAD:
419 if (S_ISREG(filp->f_dentry->d_inode->i_mode))
420 break;
421 /*FALL THROUGH*/
423 default:
424 if (filp->f_op && filp->f_op->compat_ioctl) {
425 error = filp->f_op->compat_ioctl(filp, cmd, arg);
426 if (error != -ENOIOCTLCMD)
427 goto out_fput;
430 if (!filp->f_op ||
431 (!filp->f_op->ioctl && !filp->f_op->unlocked_ioctl))
432 goto do_ioctl;
433 break;
436 for (t = ioctl32_hash_table[ioctl32_hash(cmd)]; t; t = t->next) {
437 if (t->cmd == cmd)
438 goto found_handler;
441 if (S_ISSOCK(filp->f_dentry->d_inode->i_mode) &&
442 cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
443 error = siocdevprivate_ioctl(fd, cmd, arg);
444 } else {
445 static int count;
447 if (++count <= 50)
448 compat_ioctl_error(filp, fd, cmd, arg);
449 error = -EINVAL;
452 goto out_fput;
454 found_handler:
455 if (t->handler) {
456 lock_kernel();
457 error = t->handler(fd, cmd, arg, filp);
458 unlock_kernel();
459 goto out_fput;
462 do_ioctl:
463 error = vfs_ioctl(filp, fd, cmd, arg);
464 out_fput:
465 fput_light(filp, fput_needed);
466 out:
467 return error;
470 static int get_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
472 if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
473 __get_user(kfl->l_type, &ufl->l_type) ||
474 __get_user(kfl->l_whence, &ufl->l_whence) ||
475 __get_user(kfl->l_start, &ufl->l_start) ||
476 __get_user(kfl->l_len, &ufl->l_len) ||
477 __get_user(kfl->l_pid, &ufl->l_pid))
478 return -EFAULT;
479 return 0;
482 static int put_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
484 if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
485 __put_user(kfl->l_type, &ufl->l_type) ||
486 __put_user(kfl->l_whence, &ufl->l_whence) ||
487 __put_user(kfl->l_start, &ufl->l_start) ||
488 __put_user(kfl->l_len, &ufl->l_len) ||
489 __put_user(kfl->l_pid, &ufl->l_pid))
490 return -EFAULT;
491 return 0;
494 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
495 static int get_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl)
497 if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
498 __get_user(kfl->l_type, &ufl->l_type) ||
499 __get_user(kfl->l_whence, &ufl->l_whence) ||
500 __get_user(kfl->l_start, &ufl->l_start) ||
501 __get_user(kfl->l_len, &ufl->l_len) ||
502 __get_user(kfl->l_pid, &ufl->l_pid))
503 return -EFAULT;
504 return 0;
506 #endif
508 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
509 static int put_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl)
511 if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
512 __put_user(kfl->l_type, &ufl->l_type) ||
513 __put_user(kfl->l_whence, &ufl->l_whence) ||
514 __put_user(kfl->l_start, &ufl->l_start) ||
515 __put_user(kfl->l_len, &ufl->l_len) ||
516 __put_user(kfl->l_pid, &ufl->l_pid))
517 return -EFAULT;
518 return 0;
520 #endif
522 asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
523 unsigned long arg)
525 mm_segment_t old_fs;
526 struct flock f;
527 long ret;
529 switch (cmd) {
530 case F_GETLK:
531 case F_SETLK:
532 case F_SETLKW:
533 ret = get_compat_flock(&f, compat_ptr(arg));
534 if (ret != 0)
535 break;
536 old_fs = get_fs();
537 set_fs(KERNEL_DS);
538 ret = sys_fcntl(fd, cmd, (unsigned long)&f);
539 set_fs(old_fs);
540 if (cmd == F_GETLK && ret == 0) {
541 /* GETLK was successfule and we need to return the data...
542 * but it needs to fit in the compat structure.
543 * l_start shouldn't be too big, unless the original
544 * start + end is greater than COMPAT_OFF_T_MAX, in which
545 * case the app was asking for trouble, so we return
546 * -EOVERFLOW in that case.
547 * l_len could be too big, in which case we just truncate it,
548 * and only allow the app to see that part of the conflicting
549 * lock that might make sense to it anyway
552 if (f.l_start > COMPAT_OFF_T_MAX)
553 ret = -EOVERFLOW;
554 if (f.l_len > COMPAT_OFF_T_MAX)
555 f.l_len = COMPAT_OFF_T_MAX;
556 if (ret == 0)
557 ret = put_compat_flock(&f, compat_ptr(arg));
559 break;
561 case F_GETLK64:
562 case F_SETLK64:
563 case F_SETLKW64:
564 ret = get_compat_flock64(&f, compat_ptr(arg));
565 if (ret != 0)
566 break;
567 old_fs = get_fs();
568 set_fs(KERNEL_DS);
569 ret = sys_fcntl(fd, (cmd == F_GETLK64) ? F_GETLK :
570 ((cmd == F_SETLK64) ? F_SETLK : F_SETLKW),
571 (unsigned long)&f);
572 set_fs(old_fs);
573 if (cmd == F_GETLK64 && ret == 0) {
574 /* need to return lock information - see above for commentary */
575 if (f.l_start > COMPAT_LOFF_T_MAX)
576 ret = -EOVERFLOW;
577 if (f.l_len > COMPAT_LOFF_T_MAX)
578 f.l_len = COMPAT_LOFF_T_MAX;
579 if (ret == 0)
580 ret = put_compat_flock64(&f, compat_ptr(arg));
582 break;
584 default:
585 ret = sys_fcntl(fd, cmd, arg);
586 break;
588 return ret;
591 asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
592 unsigned long arg)
594 if ((cmd == F_GETLK64) || (cmd == F_SETLK64) || (cmd == F_SETLKW64))
595 return -EINVAL;
596 return compat_sys_fcntl64(fd, cmd, arg);
599 asmlinkage long
600 compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
602 long ret;
603 aio_context_t ctx64;
605 mm_segment_t oldfs = get_fs();
606 if (unlikely(get_user(ctx64, ctx32p)))
607 return -EFAULT;
609 set_fs(KERNEL_DS);
610 /* The __user pointer cast is valid because of the set_fs() */
611 ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
612 set_fs(oldfs);
613 /* truncating is ok because it's a user address */
614 if (!ret)
615 ret = put_user((u32) ctx64, ctx32p);
616 return ret;
619 asmlinkage long
620 compat_sys_io_getevents(aio_context_t ctx_id,
621 unsigned long min_nr,
622 unsigned long nr,
623 struct io_event __user *events,
624 struct compat_timespec __user *timeout)
626 long ret;
627 struct timespec t;
628 struct timespec __user *ut = NULL;
630 ret = -EFAULT;
631 if (unlikely(!access_ok(VERIFY_WRITE, events,
632 nr * sizeof(struct io_event))))
633 goto out;
634 if (timeout) {
635 if (get_compat_timespec(&t, timeout))
636 goto out;
638 ut = compat_alloc_user_space(sizeof(*ut));
639 if (copy_to_user(ut, &t, sizeof(t)) )
640 goto out;
642 ret = sys_io_getevents(ctx_id, min_nr, nr, events, ut);
643 out:
644 return ret;
647 static inline long
648 copy_iocb(long nr, u32 __user *ptr32, struct iocb __user * __user *ptr64)
650 compat_uptr_t uptr;
651 int i;
653 for (i = 0; i < nr; ++i) {
654 if (get_user(uptr, ptr32 + i))
655 return -EFAULT;
656 if (put_user(compat_ptr(uptr), ptr64 + i))
657 return -EFAULT;
659 return 0;
662 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
664 asmlinkage long
665 compat_sys_io_submit(aio_context_t ctx_id, int nr, u32 __user *iocb)
667 struct iocb __user * __user *iocb64;
668 long ret;
670 if (unlikely(nr < 0))
671 return -EINVAL;
673 if (nr > MAX_AIO_SUBMITS)
674 nr = MAX_AIO_SUBMITS;
676 iocb64 = compat_alloc_user_space(nr * sizeof(*iocb64));
677 ret = copy_iocb(nr, iocb, iocb64);
678 if (!ret)
679 ret = sys_io_submit(ctx_id, nr, iocb64);
680 return ret;
683 struct compat_ncp_mount_data {
684 compat_int_t version;
685 compat_uint_t ncp_fd;
686 __compat_uid_t mounted_uid;
687 compat_pid_t wdog_pid;
688 unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
689 compat_uint_t time_out;
690 compat_uint_t retry_count;
691 compat_uint_t flags;
692 __compat_uid_t uid;
693 __compat_gid_t gid;
694 compat_mode_t file_mode;
695 compat_mode_t dir_mode;
698 struct compat_ncp_mount_data_v4 {
699 compat_int_t version;
700 compat_ulong_t flags;
701 compat_ulong_t mounted_uid;
702 compat_long_t wdog_pid;
703 compat_uint_t ncp_fd;
704 compat_uint_t time_out;
705 compat_uint_t retry_count;
706 compat_ulong_t uid;
707 compat_ulong_t gid;
708 compat_ulong_t file_mode;
709 compat_ulong_t dir_mode;
712 static void *do_ncp_super_data_conv(void *raw_data)
714 int version = *(unsigned int *)raw_data;
716 if (version == 3) {
717 struct compat_ncp_mount_data *c_n = raw_data;
718 struct ncp_mount_data *n = raw_data;
720 n->dir_mode = c_n->dir_mode;
721 n->file_mode = c_n->file_mode;
722 n->gid = c_n->gid;
723 n->uid = c_n->uid;
724 memmove (n->mounted_vol, c_n->mounted_vol, (sizeof (c_n->mounted_vol) + 3 * sizeof (unsigned int)));
725 n->wdog_pid = c_n->wdog_pid;
726 n->mounted_uid = c_n->mounted_uid;
727 } else if (version == 4) {
728 struct compat_ncp_mount_data_v4 *c_n = raw_data;
729 struct ncp_mount_data_v4 *n = raw_data;
731 n->dir_mode = c_n->dir_mode;
732 n->file_mode = c_n->file_mode;
733 n->gid = c_n->gid;
734 n->uid = c_n->uid;
735 n->retry_count = c_n->retry_count;
736 n->time_out = c_n->time_out;
737 n->ncp_fd = c_n->ncp_fd;
738 n->wdog_pid = c_n->wdog_pid;
739 n->mounted_uid = c_n->mounted_uid;
740 n->flags = c_n->flags;
741 } else if (version != 5) {
742 return NULL;
745 return raw_data;
748 struct compat_smb_mount_data {
749 compat_int_t version;
750 __compat_uid_t mounted_uid;
751 __compat_uid_t uid;
752 __compat_gid_t gid;
753 compat_mode_t file_mode;
754 compat_mode_t dir_mode;
757 static void *do_smb_super_data_conv(void *raw_data)
759 struct smb_mount_data *s = raw_data;
760 struct compat_smb_mount_data *c_s = raw_data;
762 if (c_s->version != SMB_MOUNT_OLDVERSION)
763 goto out;
764 s->dir_mode = c_s->dir_mode;
765 s->file_mode = c_s->file_mode;
766 s->gid = c_s->gid;
767 s->uid = c_s->uid;
768 s->mounted_uid = c_s->mounted_uid;
769 out:
770 return raw_data;
773 struct compat_nfs_string {
774 compat_uint_t len;
775 compat_uptr_t data;
778 static inline void compat_nfs_string(struct nfs_string *dst,
779 struct compat_nfs_string *src)
781 dst->data = compat_ptr(src->data);
782 dst->len = src->len;
785 struct compat_nfs4_mount_data_v1 {
786 compat_int_t version;
787 compat_int_t flags;
788 compat_int_t rsize;
789 compat_int_t wsize;
790 compat_int_t timeo;
791 compat_int_t retrans;
792 compat_int_t acregmin;
793 compat_int_t acregmax;
794 compat_int_t acdirmin;
795 compat_int_t acdirmax;
796 struct compat_nfs_string client_addr;
797 struct compat_nfs_string mnt_path;
798 struct compat_nfs_string hostname;
799 compat_uint_t host_addrlen;
800 compat_uptr_t host_addr;
801 compat_int_t proto;
802 compat_int_t auth_flavourlen;
803 compat_uptr_t auth_flavours;
806 static int do_nfs4_super_data_conv(void *raw_data)
808 int version = *(compat_uint_t *) raw_data;
810 if (version == 1) {
811 struct compat_nfs4_mount_data_v1 *raw = raw_data;
812 struct nfs4_mount_data *real = raw_data;
814 /* copy the fields backwards */
815 real->auth_flavours = compat_ptr(raw->auth_flavours);
816 real->auth_flavourlen = raw->auth_flavourlen;
817 real->proto = raw->proto;
818 real->host_addr = compat_ptr(raw->host_addr);
819 real->host_addrlen = raw->host_addrlen;
820 compat_nfs_string(&real->hostname, &raw->hostname);
821 compat_nfs_string(&real->mnt_path, &raw->mnt_path);
822 compat_nfs_string(&real->client_addr, &raw->client_addr);
823 real->acdirmax = raw->acdirmax;
824 real->acdirmin = raw->acdirmin;
825 real->acregmax = raw->acregmax;
826 real->acregmin = raw->acregmin;
827 real->retrans = raw->retrans;
828 real->timeo = raw->timeo;
829 real->wsize = raw->wsize;
830 real->rsize = raw->rsize;
831 real->flags = raw->flags;
832 real->version = raw->version;
834 else {
835 return -EINVAL;
838 return 0;
841 #define SMBFS_NAME "smbfs"
842 #define NCPFS_NAME "ncpfs"
843 #define NFS4_NAME "nfs4"
845 asmlinkage long compat_sys_mount(char __user * dev_name, char __user * dir_name,
846 char __user * type, unsigned long flags,
847 void __user * data)
849 unsigned long type_page;
850 unsigned long data_page;
851 unsigned long dev_page;
852 char *dir_page;
853 int retval;
855 retval = copy_mount_options (type, &type_page);
856 if (retval < 0)
857 goto out;
859 dir_page = getname(dir_name);
860 retval = PTR_ERR(dir_page);
861 if (IS_ERR(dir_page))
862 goto out1;
864 retval = copy_mount_options (dev_name, &dev_page);
865 if (retval < 0)
866 goto out2;
868 retval = copy_mount_options (data, &data_page);
869 if (retval < 0)
870 goto out3;
872 retval = -EINVAL;
874 if (type_page) {
875 if (!strcmp((char *)type_page, SMBFS_NAME)) {
876 do_smb_super_data_conv((void *)data_page);
877 } else if (!strcmp((char *)type_page, NCPFS_NAME)) {
878 do_ncp_super_data_conv((void *)data_page);
879 } else if (!strcmp((char *)type_page, NFS4_NAME)) {
880 if (do_nfs4_super_data_conv((void *) data_page))
881 goto out4;
885 lock_kernel();
886 retval = do_mount((char*)dev_page, dir_page, (char*)type_page,
887 flags, (void*)data_page);
888 unlock_kernel();
890 out4:
891 free_page(data_page);
892 out3:
893 free_page(dev_page);
894 out2:
895 putname(dir_page);
896 out1:
897 free_page(type_page);
898 out:
899 return retval;
902 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
903 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
904 ~(sizeof(compat_long_t)-1))
906 struct compat_old_linux_dirent {
907 compat_ulong_t d_ino;
908 compat_ulong_t d_offset;
909 unsigned short d_namlen;
910 char d_name[1];
913 struct compat_readdir_callback {
914 struct compat_old_linux_dirent __user *dirent;
915 int result;
918 static int compat_fillonedir(void *__buf, const char *name, int namlen,
919 loff_t offset, ino_t ino, unsigned int d_type)
921 struct compat_readdir_callback *buf = __buf;
922 struct compat_old_linux_dirent __user *dirent;
924 if (buf->result)
925 return -EINVAL;
926 buf->result++;
927 dirent = buf->dirent;
928 if (!access_ok(VERIFY_WRITE, dirent,
929 (unsigned long)(dirent->d_name + namlen + 1) -
930 (unsigned long)dirent))
931 goto efault;
932 if ( __put_user(ino, &dirent->d_ino) ||
933 __put_user(offset, &dirent->d_offset) ||
934 __put_user(namlen, &dirent->d_namlen) ||
935 __copy_to_user(dirent->d_name, name, namlen) ||
936 __put_user(0, dirent->d_name + namlen))
937 goto efault;
938 return 0;
939 efault:
940 buf->result = -EFAULT;
941 return -EFAULT;
944 asmlinkage long compat_sys_old_readdir(unsigned int fd,
945 struct compat_old_linux_dirent __user *dirent, unsigned int count)
947 int error;
948 struct file *file;
949 struct compat_readdir_callback buf;
951 error = -EBADF;
952 file = fget(fd);
953 if (!file)
954 goto out;
956 buf.result = 0;
957 buf.dirent = dirent;
959 error = vfs_readdir(file, compat_fillonedir, &buf);
960 if (error >= 0)
961 error = buf.result;
963 fput(file);
964 out:
965 return error;
968 struct compat_linux_dirent {
969 compat_ulong_t d_ino;
970 compat_ulong_t d_off;
971 unsigned short d_reclen;
972 char d_name[1];
975 struct compat_getdents_callback {
976 struct compat_linux_dirent __user *current_dir;
977 struct compat_linux_dirent __user *previous;
978 int count;
979 int error;
982 static int compat_filldir(void *__buf, const char *name, int namlen,
983 loff_t offset, ino_t ino, unsigned int d_type)
985 struct compat_linux_dirent __user * dirent;
986 struct compat_getdents_callback *buf = __buf;
987 int reclen = COMPAT_ROUND_UP(NAME_OFFSET(dirent) + namlen + 2);
989 buf->error = -EINVAL; /* only used if we fail.. */
990 if (reclen > buf->count)
991 return -EINVAL;
992 dirent = buf->previous;
993 if (dirent) {
994 if (__put_user(offset, &dirent->d_off))
995 goto efault;
997 dirent = buf->current_dir;
998 if (__put_user(ino, &dirent->d_ino))
999 goto efault;
1000 if (__put_user(reclen, &dirent->d_reclen))
1001 goto efault;
1002 if (copy_to_user(dirent->d_name, name, namlen))
1003 goto efault;
1004 if (__put_user(0, dirent->d_name + namlen))
1005 goto efault;
1006 if (__put_user(d_type, (char __user *) dirent + reclen - 1))
1007 goto efault;
1008 buf->previous = dirent;
1009 dirent = (void __user *)dirent + reclen;
1010 buf->current_dir = dirent;
1011 buf->count -= reclen;
1012 return 0;
1013 efault:
1014 buf->error = -EFAULT;
1015 return -EFAULT;
1018 asmlinkage long compat_sys_getdents(unsigned int fd,
1019 struct compat_linux_dirent __user *dirent, unsigned int count)
1021 struct file * file;
1022 struct compat_linux_dirent __user * lastdirent;
1023 struct compat_getdents_callback buf;
1024 int error;
1026 error = -EFAULT;
1027 if (!access_ok(VERIFY_WRITE, dirent, count))
1028 goto out;
1030 error = -EBADF;
1031 file = fget(fd);
1032 if (!file)
1033 goto out;
1035 buf.current_dir = dirent;
1036 buf.previous = NULL;
1037 buf.count = count;
1038 buf.error = 0;
1040 error = vfs_readdir(file, compat_filldir, &buf);
1041 if (error < 0)
1042 goto out_putf;
1043 error = buf.error;
1044 lastdirent = buf.previous;
1045 if (lastdirent) {
1046 if (put_user(file->f_pos, &lastdirent->d_off))
1047 error = -EFAULT;
1048 else
1049 error = count - buf.count;
1052 out_putf:
1053 fput(file);
1054 out:
1055 return error;
1058 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1059 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1061 struct compat_getdents_callback64 {
1062 struct linux_dirent64 __user *current_dir;
1063 struct linux_dirent64 __user *previous;
1064 int count;
1065 int error;
1068 static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t offset,
1069 ino_t ino, unsigned int d_type)
1071 struct linux_dirent64 __user *dirent;
1072 struct compat_getdents_callback64 *buf = __buf;
1073 int jj = NAME_OFFSET(dirent);
1074 int reclen = COMPAT_ROUND_UP64(jj + namlen + 1);
1075 u64 off;
1077 buf->error = -EINVAL; /* only used if we fail.. */
1078 if (reclen > buf->count)
1079 return -EINVAL;
1080 dirent = buf->previous;
1082 if (dirent) {
1083 if (__put_user_unaligned(offset, &dirent->d_off))
1084 goto efault;
1086 dirent = buf->current_dir;
1087 if (__put_user_unaligned(ino, &dirent->d_ino))
1088 goto efault;
1089 off = 0;
1090 if (__put_user_unaligned(off, &dirent->d_off))
1091 goto efault;
1092 if (__put_user(reclen, &dirent->d_reclen))
1093 goto efault;
1094 if (__put_user(d_type, &dirent->d_type))
1095 goto efault;
1096 if (copy_to_user(dirent->d_name, name, namlen))
1097 goto efault;
1098 if (__put_user(0, dirent->d_name + namlen))
1099 goto efault;
1100 buf->previous = dirent;
1101 dirent = (void __user *)dirent + reclen;
1102 buf->current_dir = dirent;
1103 buf->count -= reclen;
1104 return 0;
1105 efault:
1106 buf->error = -EFAULT;
1107 return -EFAULT;
1110 asmlinkage long compat_sys_getdents64(unsigned int fd,
1111 struct linux_dirent64 __user * dirent, unsigned int count)
1113 struct file * file;
1114 struct linux_dirent64 __user * lastdirent;
1115 struct compat_getdents_callback64 buf;
1116 int error;
1118 error = -EFAULT;
1119 if (!access_ok(VERIFY_WRITE, dirent, count))
1120 goto out;
1122 error = -EBADF;
1123 file = fget(fd);
1124 if (!file)
1125 goto out;
1127 buf.current_dir = dirent;
1128 buf.previous = NULL;
1129 buf.count = count;
1130 buf.error = 0;
1132 error = vfs_readdir(file, compat_filldir64, &buf);
1133 if (error < 0)
1134 goto out_putf;
1135 error = buf.error;
1136 lastdirent = buf.previous;
1137 if (lastdirent) {
1138 typeof(lastdirent->d_off) d_off = file->f_pos;
1139 __put_user_unaligned(d_off, &lastdirent->d_off);
1140 error = count - buf.count;
1143 out_putf:
1144 fput(file);
1145 out:
1146 return error;
1148 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1150 static ssize_t compat_do_readv_writev(int type, struct file *file,
1151 const struct compat_iovec __user *uvector,
1152 unsigned long nr_segs, loff_t *pos)
1154 compat_ssize_t tot_len;
1155 struct iovec iovstack[UIO_FASTIOV];
1156 struct iovec *iov=iovstack, *vector;
1157 ssize_t ret;
1158 int seg;
1159 io_fn_t fn;
1160 iov_fn_t fnv;
1163 * SuS says "The readv() function *may* fail if the iovcnt argument
1164 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1165 * traditionally returned zero for zero segments, so...
1167 ret = 0;
1168 if (nr_segs == 0)
1169 goto out;
1172 * First get the "struct iovec" from user memory and
1173 * verify all the pointers
1175 ret = -EINVAL;
1176 if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
1177 goto out;
1178 if (!file->f_op)
1179 goto out;
1180 if (nr_segs > UIO_FASTIOV) {
1181 ret = -ENOMEM;
1182 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
1183 if (!iov)
1184 goto out;
1186 ret = -EFAULT;
1187 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
1188 goto out;
1191 * Single unix specification:
1192 * We should -EINVAL if an element length is not >= 0 and fitting an
1193 * ssize_t. The total length is fitting an ssize_t
1195 * Be careful here because iov_len is a size_t not an ssize_t
1197 tot_len = 0;
1198 vector = iov;
1199 ret = -EINVAL;
1200 for (seg = 0 ; seg < nr_segs; seg++) {
1201 compat_ssize_t tmp = tot_len;
1202 compat_ssize_t len;
1203 compat_uptr_t buf;
1205 if (__get_user(len, &uvector->iov_len) ||
1206 __get_user(buf, &uvector->iov_base)) {
1207 ret = -EFAULT;
1208 goto out;
1210 if (len < 0) /* size_t not fitting an compat_ssize_t .. */
1211 goto out;
1212 tot_len += len;
1213 if (tot_len < tmp) /* maths overflow on the compat_ssize_t */
1214 goto out;
1215 vector->iov_base = compat_ptr(buf);
1216 vector->iov_len = (compat_size_t) len;
1217 uvector++;
1218 vector++;
1220 if (tot_len == 0) {
1221 ret = 0;
1222 goto out;
1225 ret = rw_verify_area(type, file, pos, tot_len);
1226 if (ret < 0)
1227 goto out;
1229 ret = security_file_permission(file, type == READ ? MAY_READ:MAY_WRITE);
1230 if (ret)
1231 goto out;
1233 fnv = NULL;
1234 if (type == READ) {
1235 fn = file->f_op->read;
1236 fnv = file->f_op->aio_read;
1237 } else {
1238 fn = (io_fn_t)file->f_op->write;
1239 fnv = file->f_op->aio_write;
1242 if (fnv)
1243 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
1244 pos, fnv);
1245 else
1246 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
1248 out:
1249 if (iov != iovstack)
1250 kfree(iov);
1251 if ((ret + (type == READ)) > 0) {
1252 struct dentry *dentry = file->f_dentry;
1253 if (type == READ)
1254 fsnotify_access(dentry);
1255 else
1256 fsnotify_modify(dentry);
1258 return ret;
1261 asmlinkage ssize_t
1262 compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec, unsigned long vlen)
1264 struct file *file;
1265 ssize_t ret = -EBADF;
1267 file = fget(fd);
1268 if (!file)
1269 return -EBADF;
1271 if (!(file->f_mode & FMODE_READ))
1272 goto out;
1274 ret = -EINVAL;
1275 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
1276 goto out;
1278 ret = compat_do_readv_writev(READ, file, vec, vlen, &file->f_pos);
1280 out:
1281 fput(file);
1282 return ret;
1285 asmlinkage ssize_t
1286 compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec, unsigned long vlen)
1288 struct file *file;
1289 ssize_t ret = -EBADF;
1291 file = fget(fd);
1292 if (!file)
1293 return -EBADF;
1294 if (!(file->f_mode & FMODE_WRITE))
1295 goto out;
1297 ret = -EINVAL;
1298 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
1299 goto out;
1301 ret = compat_do_readv_writev(WRITE, file, vec, vlen, &file->f_pos);
1303 out:
1304 fput(file);
1305 return ret;
1308 asmlinkage long
1309 compat_sys_vmsplice(int fd, const struct compat_iovec __user *iov32,
1310 unsigned int nr_segs, unsigned int flags)
1312 unsigned i;
1313 struct iovec *iov;
1314 if (nr_segs > UIO_MAXIOV)
1315 return -EINVAL;
1316 iov = compat_alloc_user_space(nr_segs * sizeof(struct iovec));
1317 for (i = 0; i < nr_segs; i++) {
1318 struct compat_iovec v;
1319 if (get_user(v.iov_base, &iov32[i].iov_base) ||
1320 get_user(v.iov_len, &iov32[i].iov_len) ||
1321 put_user(compat_ptr(v.iov_base), &iov[i].iov_base) ||
1322 put_user(v.iov_len, &iov[i].iov_len))
1323 return -EFAULT;
1325 return sys_vmsplice(fd, iov, nr_segs, flags);
1329 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1330 * O_LARGEFILE flag.
1332 asmlinkage long
1333 compat_sys_open(const char __user *filename, int flags, int mode)
1335 return do_sys_open(AT_FDCWD, filename, flags, mode);
1339 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1340 * O_LARGEFILE flag.
1342 asmlinkage long
1343 compat_sys_openat(unsigned int dfd, const char __user *filename, int flags, int mode)
1345 return do_sys_open(dfd, filename, flags, mode);
1349 * compat_count() counts the number of arguments/envelopes. It is basically
1350 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1351 * and envp pointers.
1353 static int compat_count(compat_uptr_t __user *argv, int max)
1355 int i = 0;
1357 if (argv != NULL) {
1358 for (;;) {
1359 compat_uptr_t p;
1361 if (get_user(p, argv))
1362 return -EFAULT;
1363 if (!p)
1364 break;
1365 argv++;
1366 if(++i > max)
1367 return -E2BIG;
1370 return i;
1374 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1375 * except that it works with 32 bit argv and envp pointers.
1377 static int compat_copy_strings(int argc, compat_uptr_t __user *argv,
1378 struct linux_binprm *bprm)
1380 struct page *kmapped_page = NULL;
1381 char *kaddr = NULL;
1382 int ret;
1384 while (argc-- > 0) {
1385 compat_uptr_t str;
1386 int len;
1387 unsigned long pos;
1389 if (get_user(str, argv+argc) ||
1390 !(len = strnlen_user(compat_ptr(str), bprm->p))) {
1391 ret = -EFAULT;
1392 goto out;
1395 if (bprm->p < len) {
1396 ret = -E2BIG;
1397 goto out;
1400 bprm->p -= len;
1401 /* XXX: add architecture specific overflow check here. */
1402 pos = bprm->p;
1404 while (len > 0) {
1405 int i, new, err;
1406 int offset, bytes_to_copy;
1407 struct page *page;
1409 offset = pos % PAGE_SIZE;
1410 i = pos/PAGE_SIZE;
1411 page = bprm->page[i];
1412 new = 0;
1413 if (!page) {
1414 page = alloc_page(GFP_HIGHUSER);
1415 bprm->page[i] = page;
1416 if (!page) {
1417 ret = -ENOMEM;
1418 goto out;
1420 new = 1;
1423 if (page != kmapped_page) {
1424 if (kmapped_page)
1425 kunmap(kmapped_page);
1426 kmapped_page = page;
1427 kaddr = kmap(kmapped_page);
1429 if (new && offset)
1430 memset(kaddr, 0, offset);
1431 bytes_to_copy = PAGE_SIZE - offset;
1432 if (bytes_to_copy > len) {
1433 bytes_to_copy = len;
1434 if (new)
1435 memset(kaddr+offset+len, 0,
1436 PAGE_SIZE-offset-len);
1438 err = copy_from_user(kaddr+offset, compat_ptr(str),
1439 bytes_to_copy);
1440 if (err) {
1441 ret = -EFAULT;
1442 goto out;
1445 pos += bytes_to_copy;
1446 str += bytes_to_copy;
1447 len -= bytes_to_copy;
1450 ret = 0;
1451 out:
1452 if (kmapped_page)
1453 kunmap(kmapped_page);
1454 return ret;
1457 #ifdef CONFIG_MMU
1459 #define free_arg_pages(bprm) do { } while (0)
1461 #else
1463 static inline void free_arg_pages(struct linux_binprm *bprm)
1465 int i;
1467 for (i = 0; i < MAX_ARG_PAGES; i++) {
1468 if (bprm->page[i])
1469 __free_page(bprm->page[i]);
1470 bprm->page[i] = NULL;
1474 #endif /* CONFIG_MMU */
1477 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1478 * that it processes 32 bit argv and envp pointers.
1480 int compat_do_execve(char * filename,
1481 compat_uptr_t __user *argv,
1482 compat_uptr_t __user *envp,
1483 struct pt_regs * regs)
1485 struct linux_binprm *bprm;
1486 struct file *file;
1487 int retval;
1488 int i;
1490 retval = -ENOMEM;
1491 bprm = kzalloc(sizeof(*bprm), GFP_KERNEL);
1492 if (!bprm)
1493 goto out_ret;
1495 file = open_exec(filename);
1496 retval = PTR_ERR(file);
1497 if (IS_ERR(file))
1498 goto out_kfree;
1500 sched_exec();
1502 bprm->p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
1503 bprm->file = file;
1504 bprm->filename = filename;
1505 bprm->interp = filename;
1506 bprm->mm = mm_alloc();
1507 retval = -ENOMEM;
1508 if (!bprm->mm)
1509 goto out_file;
1511 retval = init_new_context(current, bprm->mm);
1512 if (retval < 0)
1513 goto out_mm;
1515 bprm->argc = compat_count(argv, bprm->p / sizeof(compat_uptr_t));
1516 if ((retval = bprm->argc) < 0)
1517 goto out_mm;
1519 bprm->envc = compat_count(envp, bprm->p / sizeof(compat_uptr_t));
1520 if ((retval = bprm->envc) < 0)
1521 goto out_mm;
1523 retval = security_bprm_alloc(bprm);
1524 if (retval)
1525 goto out;
1527 retval = prepare_binprm(bprm);
1528 if (retval < 0)
1529 goto out;
1531 retval = copy_strings_kernel(1, &bprm->filename, bprm);
1532 if (retval < 0)
1533 goto out;
1535 bprm->exec = bprm->p;
1536 retval = compat_copy_strings(bprm->envc, envp, bprm);
1537 if (retval < 0)
1538 goto out;
1540 retval = compat_copy_strings(bprm->argc, argv, bprm);
1541 if (retval < 0)
1542 goto out;
1544 retval = search_binary_handler(bprm, regs);
1545 if (retval >= 0) {
1546 free_arg_pages(bprm);
1548 /* execve success */
1549 security_bprm_free(bprm);
1550 acct_update_integrals(current);
1551 kfree(bprm);
1552 return retval;
1555 out:
1556 /* Something went wrong, return the inode and free the argument pages*/
1557 for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
1558 struct page * page = bprm->page[i];
1559 if (page)
1560 __free_page(page);
1563 if (bprm->security)
1564 security_bprm_free(bprm);
1566 out_mm:
1567 if (bprm->mm)
1568 mmdrop(bprm->mm);
1570 out_file:
1571 if (bprm->file) {
1572 allow_write_access(bprm->file);
1573 fput(bprm->file);
1576 out_kfree:
1577 kfree(bprm);
1579 out_ret:
1580 return retval;
1583 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1585 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1588 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1589 * 64-bit unsigned longs.
1591 static
1592 int compat_get_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
1593 unsigned long *fdset)
1595 nr = ROUND_UP(nr, __COMPAT_NFDBITS);
1596 if (ufdset) {
1597 unsigned long odd;
1599 if (!access_ok(VERIFY_WRITE, ufdset, nr*sizeof(compat_ulong_t)))
1600 return -EFAULT;
1602 odd = nr & 1UL;
1603 nr &= ~1UL;
1604 while (nr) {
1605 unsigned long h, l;
1606 __get_user(l, ufdset);
1607 __get_user(h, ufdset+1);
1608 ufdset += 2;
1609 *fdset++ = h << 32 | l;
1610 nr -= 2;
1612 if (odd)
1613 __get_user(*fdset, ufdset);
1614 } else {
1615 /* Tricky, must clear full unsigned long in the
1616 * kernel fdset at the end, this makes sure that
1617 * actually happens.
1619 memset(fdset, 0, ((nr + 1) & ~1)*sizeof(compat_ulong_t));
1621 return 0;
1624 static
1625 void compat_set_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
1626 unsigned long *fdset)
1628 unsigned long odd;
1629 nr = ROUND_UP(nr, __COMPAT_NFDBITS);
1631 if (!ufdset)
1632 return;
1634 odd = nr & 1UL;
1635 nr &= ~1UL;
1636 while (nr) {
1637 unsigned long h, l;
1638 l = *fdset++;
1639 h = l >> 32;
1640 __put_user(l, ufdset);
1641 __put_user(h, ufdset+1);
1642 ufdset += 2;
1643 nr -= 2;
1645 if (odd)
1646 __put_user(*fdset, ufdset);
1651 * This is a virtual copy of sys_select from fs/select.c and probably
1652 * should be compared to it from time to time
1656 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1657 * like to be certain this leads to no problems. So I return
1658 * EINTR just for safety.
1660 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1661 * I'm trying ERESTARTNOHAND which restart only when you want to.
1663 #define MAX_SELECT_SECONDS \
1664 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1666 int compat_core_sys_select(int n, compat_ulong_t __user *inp,
1667 compat_ulong_t __user *outp, compat_ulong_t __user *exp, s64 *timeout)
1669 fd_set_bits fds;
1670 char *bits;
1671 int size, max_fdset, ret = -EINVAL;
1672 struct fdtable *fdt;
1674 if (n < 0)
1675 goto out_nofds;
1677 /* max_fdset can increase, so grab it once to avoid race */
1678 rcu_read_lock();
1679 fdt = files_fdtable(current->files);
1680 max_fdset = fdt->max_fdset;
1681 rcu_read_unlock();
1682 if (n > max_fdset)
1683 n = max_fdset;
1686 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1687 * since we used fdset we need to allocate memory in units of
1688 * long-words.
1690 ret = -ENOMEM;
1691 size = FDS_BYTES(n);
1692 bits = kmalloc(6 * size, GFP_KERNEL);
1693 if (!bits)
1694 goto out_nofds;
1695 fds.in = (unsigned long *) bits;
1696 fds.out = (unsigned long *) (bits + size);
1697 fds.ex = (unsigned long *) (bits + 2*size);
1698 fds.res_in = (unsigned long *) (bits + 3*size);
1699 fds.res_out = (unsigned long *) (bits + 4*size);
1700 fds.res_ex = (unsigned long *) (bits + 5*size);
1702 if ((ret = compat_get_fd_set(n, inp, fds.in)) ||
1703 (ret = compat_get_fd_set(n, outp, fds.out)) ||
1704 (ret = compat_get_fd_set(n, exp, fds.ex)))
1705 goto out;
1706 zero_fd_set(n, fds.res_in);
1707 zero_fd_set(n, fds.res_out);
1708 zero_fd_set(n, fds.res_ex);
1710 ret = do_select(n, &fds, timeout);
1712 if (ret < 0)
1713 goto out;
1714 if (!ret) {
1715 ret = -ERESTARTNOHAND;
1716 if (signal_pending(current))
1717 goto out;
1718 ret = 0;
1721 compat_set_fd_set(n, inp, fds.res_in);
1722 compat_set_fd_set(n, outp, fds.res_out);
1723 compat_set_fd_set(n, exp, fds.res_ex);
1725 out:
1726 kfree(bits);
1727 out_nofds:
1728 return ret;
1731 asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
1732 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1733 struct compat_timeval __user *tvp)
1735 s64 timeout = -1;
1736 struct compat_timeval tv;
1737 int ret;
1739 if (tvp) {
1740 if (copy_from_user(&tv, tvp, sizeof(tv)))
1741 return -EFAULT;
1743 if (tv.tv_sec < 0 || tv.tv_usec < 0)
1744 return -EINVAL;
1746 /* Cast to u64 to make GCC stop complaining */
1747 if ((u64)tv.tv_sec >= (u64)MAX_INT64_SECONDS)
1748 timeout = -1; /* infinite */
1749 else {
1750 timeout = ROUND_UP(tv.tv_usec, 1000000/HZ);
1751 timeout += tv.tv_sec * HZ;
1755 ret = compat_core_sys_select(n, inp, outp, exp, &timeout);
1757 if (tvp) {
1758 struct compat_timeval rtv;
1760 if (current->personality & STICKY_TIMEOUTS)
1761 goto sticky;
1762 rtv.tv_usec = jiffies_to_usecs(do_div((*(u64*)&timeout), HZ));
1763 rtv.tv_sec = timeout;
1764 if (compat_timeval_compare(&rtv, &tv) >= 0)
1765 rtv = tv;
1766 if (copy_to_user(tvp, &rtv, sizeof(rtv))) {
1767 sticky:
1769 * If an application puts its timeval in read-only
1770 * memory, we don't want the Linux-specific update to
1771 * the timeval to cause a fault after the select has
1772 * completed successfully. However, because we're not
1773 * updating the timeval, we can't restart the system
1774 * call.
1776 if (ret == -ERESTARTNOHAND)
1777 ret = -EINTR;
1781 return ret;
1784 #ifdef TIF_RESTORE_SIGMASK
1785 asmlinkage long compat_sys_pselect7(int n, compat_ulong_t __user *inp,
1786 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1787 struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask,
1788 compat_size_t sigsetsize)
1790 compat_sigset_t ss32;
1791 sigset_t ksigmask, sigsaved;
1792 s64 timeout = MAX_SCHEDULE_TIMEOUT;
1793 struct compat_timespec ts;
1794 int ret;
1796 if (tsp) {
1797 if (copy_from_user(&ts, tsp, sizeof(ts)))
1798 return -EFAULT;
1800 if (ts.tv_sec < 0 || ts.tv_nsec < 0)
1801 return -EINVAL;
1804 if (sigmask) {
1805 if (sigsetsize != sizeof(compat_sigset_t))
1806 return -EINVAL;
1807 if (copy_from_user(&ss32, sigmask, sizeof(ss32)))
1808 return -EFAULT;
1809 sigset_from_compat(&ksigmask, &ss32);
1811 sigdelsetmask(&ksigmask, sigmask(SIGKILL)|sigmask(SIGSTOP));
1812 sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
1815 do {
1816 if (tsp) {
1817 if ((unsigned long)ts.tv_sec < MAX_SELECT_SECONDS) {
1818 timeout = ROUND_UP(ts.tv_nsec, 1000000000/HZ);
1819 timeout += ts.tv_sec * (unsigned long)HZ;
1820 ts.tv_sec = 0;
1821 ts.tv_nsec = 0;
1822 } else {
1823 ts.tv_sec -= MAX_SELECT_SECONDS;
1824 timeout = MAX_SELECT_SECONDS * HZ;
1828 ret = compat_core_sys_select(n, inp, outp, exp, &timeout);
1830 } while (!ret && !timeout && tsp && (ts.tv_sec || ts.tv_nsec));
1832 if (ret == 0 && tsp && !(current->personality & STICKY_TIMEOUTS)) {
1833 struct compat_timespec rts;
1835 rts.tv_sec = timeout / HZ;
1836 rts.tv_nsec = (timeout % HZ) * (NSEC_PER_SEC/HZ);
1837 if (rts.tv_nsec >= NSEC_PER_SEC) {
1838 rts.tv_sec++;
1839 rts.tv_nsec -= NSEC_PER_SEC;
1841 if (compat_timespec_compare(&rts, &ts) >= 0)
1842 rts = ts;
1843 if (copy_to_user(tsp, &rts, sizeof(rts)))
1844 ret = -EFAULT;
1847 if (ret == -ERESTARTNOHAND) {
1849 * Don't restore the signal mask yet. Let do_signal() deliver
1850 * the signal on the way back to userspace, before the signal
1851 * mask is restored.
1853 if (sigmask) {
1854 memcpy(&current->saved_sigmask, &sigsaved,
1855 sizeof(sigsaved));
1856 set_thread_flag(TIF_RESTORE_SIGMASK);
1858 } else if (sigmask)
1859 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
1861 return ret;
1864 asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp,
1865 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1866 struct compat_timespec __user *tsp, void __user *sig)
1868 compat_size_t sigsetsize = 0;
1869 compat_uptr_t up = 0;
1871 if (sig) {
1872 if (!access_ok(VERIFY_READ, sig,
1873 sizeof(compat_uptr_t)+sizeof(compat_size_t)) ||
1874 __get_user(up, (compat_uptr_t __user *)sig) ||
1875 __get_user(sigsetsize,
1876 (compat_size_t __user *)(sig+sizeof(up))))
1877 return -EFAULT;
1879 return compat_sys_pselect7(n, inp, outp, exp, tsp, compat_ptr(up),
1880 sigsetsize);
1883 asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
1884 unsigned int nfds, struct compat_timespec __user *tsp,
1885 const compat_sigset_t __user *sigmask, compat_size_t sigsetsize)
1887 compat_sigset_t ss32;
1888 sigset_t ksigmask, sigsaved;
1889 struct compat_timespec ts;
1890 s64 timeout = -1;
1891 int ret;
1893 if (tsp) {
1894 if (copy_from_user(&ts, tsp, sizeof(ts)))
1895 return -EFAULT;
1897 /* We assume that ts.tv_sec is always lower than
1898 the number of seconds that can be expressed in
1899 an s64. Otherwise the compiler bitches at us */
1900 timeout = ROUND_UP(ts.tv_nsec, 1000000000/HZ);
1901 timeout += ts.tv_sec * HZ;
1904 if (sigmask) {
1905 if (sigsetsize != sizeof(compat_sigset_t))
1906 return -EINVAL;
1907 if (copy_from_user(&ss32, sigmask, sizeof(ss32)))
1908 return -EFAULT;
1909 sigset_from_compat(&ksigmask, &ss32);
1911 sigdelsetmask(&ksigmask, sigmask(SIGKILL)|sigmask(SIGSTOP));
1912 sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
1915 ret = do_sys_poll(ufds, nfds, &timeout);
1917 /* We can restart this syscall, usually */
1918 if (ret == -EINTR) {
1920 * Don't restore the signal mask yet. Let do_signal() deliver
1921 * the signal on the way back to userspace, before the signal
1922 * mask is restored.
1924 if (sigmask) {
1925 memcpy(&current->saved_sigmask, &sigsaved,
1926 sizeof(sigsaved));
1927 set_thread_flag(TIF_RESTORE_SIGMASK);
1929 ret = -ERESTARTNOHAND;
1930 } else if (sigmask)
1931 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
1933 if (tsp && timeout >= 0) {
1934 struct compat_timespec rts;
1936 if (current->personality & STICKY_TIMEOUTS)
1937 goto sticky;
1938 /* Yes, we know it's actually an s64, but it's also positive. */
1939 rts.tv_nsec = jiffies_to_usecs(do_div((*(u64*)&timeout), HZ)) *
1940 1000;
1941 rts.tv_sec = timeout;
1942 if (compat_timespec_compare(&rts, &ts) >= 0)
1943 rts = ts;
1944 if (copy_to_user(tsp, &rts, sizeof(rts))) {
1945 sticky:
1947 * If an application puts its timeval in read-only
1948 * memory, we don't want the Linux-specific update to
1949 * the timeval to cause a fault after the select has
1950 * completed successfully. However, because we're not
1951 * updating the timeval, we can't restart the system
1952 * call.
1954 if (ret == -ERESTARTNOHAND && timeout >= 0)
1955 ret = -EINTR;
1959 return ret;
1961 #endif /* TIF_RESTORE_SIGMASK */
1963 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1964 /* Stuff for NFS server syscalls... */
1965 struct compat_nfsctl_svc {
1966 u16 svc32_port;
1967 s32 svc32_nthreads;
1970 struct compat_nfsctl_client {
1971 s8 cl32_ident[NFSCLNT_IDMAX+1];
1972 s32 cl32_naddr;
1973 struct in_addr cl32_addrlist[NFSCLNT_ADDRMAX];
1974 s32 cl32_fhkeytype;
1975 s32 cl32_fhkeylen;
1976 u8 cl32_fhkey[NFSCLNT_KEYMAX];
1979 struct compat_nfsctl_export {
1980 char ex32_client[NFSCLNT_IDMAX+1];
1981 char ex32_path[NFS_MAXPATHLEN+1];
1982 compat_dev_t ex32_dev;
1983 compat_ino_t ex32_ino;
1984 compat_int_t ex32_flags;
1985 __compat_uid_t ex32_anon_uid;
1986 __compat_gid_t ex32_anon_gid;
1989 struct compat_nfsctl_fdparm {
1990 struct sockaddr gd32_addr;
1991 s8 gd32_path[NFS_MAXPATHLEN+1];
1992 compat_int_t gd32_version;
1995 struct compat_nfsctl_fsparm {
1996 struct sockaddr gd32_addr;
1997 s8 gd32_path[NFS_MAXPATHLEN+1];
1998 compat_int_t gd32_maxlen;
2001 struct compat_nfsctl_arg {
2002 compat_int_t ca32_version; /* safeguard */
2003 union {
2004 struct compat_nfsctl_svc u32_svc;
2005 struct compat_nfsctl_client u32_client;
2006 struct compat_nfsctl_export u32_export;
2007 struct compat_nfsctl_fdparm u32_getfd;
2008 struct compat_nfsctl_fsparm u32_getfs;
2009 } u;
2010 #define ca32_svc u.u32_svc
2011 #define ca32_client u.u32_client
2012 #define ca32_export u.u32_export
2013 #define ca32_getfd u.u32_getfd
2014 #define ca32_getfs u.u32_getfs
2017 union compat_nfsctl_res {
2018 __u8 cr32_getfh[NFS_FHSIZE];
2019 struct knfsd_fh cr32_getfs;
2022 static int compat_nfs_svc_trans(struct nfsctl_arg *karg,
2023 struct compat_nfsctl_arg __user *arg)
2025 if (!access_ok(VERIFY_READ, &arg->ca32_svc, sizeof(arg->ca32_svc)) ||
2026 get_user(karg->ca_version, &arg->ca32_version) ||
2027 __get_user(karg->ca_svc.svc_port, &arg->ca32_svc.svc32_port) ||
2028 __get_user(karg->ca_svc.svc_nthreads,
2029 &arg->ca32_svc.svc32_nthreads))
2030 return -EFAULT;
2031 return 0;
2034 static int compat_nfs_clnt_trans(struct nfsctl_arg *karg,
2035 struct compat_nfsctl_arg __user *arg)
2037 if (!access_ok(VERIFY_READ, &arg->ca32_client,
2038 sizeof(arg->ca32_client)) ||
2039 get_user(karg->ca_version, &arg->ca32_version) ||
2040 __copy_from_user(&karg->ca_client.cl_ident[0],
2041 &arg->ca32_client.cl32_ident[0],
2042 NFSCLNT_IDMAX) ||
2043 __get_user(karg->ca_client.cl_naddr,
2044 &arg->ca32_client.cl32_naddr) ||
2045 __copy_from_user(&karg->ca_client.cl_addrlist[0],
2046 &arg->ca32_client.cl32_addrlist[0],
2047 (sizeof(struct in_addr) * NFSCLNT_ADDRMAX)) ||
2048 __get_user(karg->ca_client.cl_fhkeytype,
2049 &arg->ca32_client.cl32_fhkeytype) ||
2050 __get_user(karg->ca_client.cl_fhkeylen,
2051 &arg->ca32_client.cl32_fhkeylen) ||
2052 __copy_from_user(&karg->ca_client.cl_fhkey[0],
2053 &arg->ca32_client.cl32_fhkey[0],
2054 NFSCLNT_KEYMAX))
2055 return -EFAULT;
2057 return 0;
2060 static int compat_nfs_exp_trans(struct nfsctl_arg *karg,
2061 struct compat_nfsctl_arg __user *arg)
2063 if (!access_ok(VERIFY_READ, &arg->ca32_export,
2064 sizeof(arg->ca32_export)) ||
2065 get_user(karg->ca_version, &arg->ca32_version) ||
2066 __copy_from_user(&karg->ca_export.ex_client[0],
2067 &arg->ca32_export.ex32_client[0],
2068 NFSCLNT_IDMAX) ||
2069 __copy_from_user(&karg->ca_export.ex_path[0],
2070 &arg->ca32_export.ex32_path[0],
2071 NFS_MAXPATHLEN) ||
2072 __get_user(karg->ca_export.ex_dev,
2073 &arg->ca32_export.ex32_dev) ||
2074 __get_user(karg->ca_export.ex_ino,
2075 &arg->ca32_export.ex32_ino) ||
2076 __get_user(karg->ca_export.ex_flags,
2077 &arg->ca32_export.ex32_flags) ||
2078 __get_user(karg->ca_export.ex_anon_uid,
2079 &arg->ca32_export.ex32_anon_uid) ||
2080 __get_user(karg->ca_export.ex_anon_gid,
2081 &arg->ca32_export.ex32_anon_gid))
2082 return -EFAULT;
2083 SET_UID(karg->ca_export.ex_anon_uid, karg->ca_export.ex_anon_uid);
2084 SET_GID(karg->ca_export.ex_anon_gid, karg->ca_export.ex_anon_gid);
2086 return 0;
2089 static int compat_nfs_getfd_trans(struct nfsctl_arg *karg,
2090 struct compat_nfsctl_arg __user *arg)
2092 if (!access_ok(VERIFY_READ, &arg->ca32_getfd,
2093 sizeof(arg->ca32_getfd)) ||
2094 get_user(karg->ca_version, &arg->ca32_version) ||
2095 __copy_from_user(&karg->ca_getfd.gd_addr,
2096 &arg->ca32_getfd.gd32_addr,
2097 (sizeof(struct sockaddr))) ||
2098 __copy_from_user(&karg->ca_getfd.gd_path,
2099 &arg->ca32_getfd.gd32_path,
2100 (NFS_MAXPATHLEN+1)) ||
2101 __get_user(karg->ca_getfd.gd_version,
2102 &arg->ca32_getfd.gd32_version))
2103 return -EFAULT;
2105 return 0;
2108 static int compat_nfs_getfs_trans(struct nfsctl_arg *karg,
2109 struct compat_nfsctl_arg __user *arg)
2111 if (!access_ok(VERIFY_READ,&arg->ca32_getfs,sizeof(arg->ca32_getfs)) ||
2112 get_user(karg->ca_version, &arg->ca32_version) ||
2113 __copy_from_user(&karg->ca_getfs.gd_addr,
2114 &arg->ca32_getfs.gd32_addr,
2115 (sizeof(struct sockaddr))) ||
2116 __copy_from_user(&karg->ca_getfs.gd_path,
2117 &arg->ca32_getfs.gd32_path,
2118 (NFS_MAXPATHLEN+1)) ||
2119 __get_user(karg->ca_getfs.gd_maxlen,
2120 &arg->ca32_getfs.gd32_maxlen))
2121 return -EFAULT;
2123 return 0;
2126 /* This really doesn't need translations, we are only passing
2127 * back a union which contains opaque nfs file handle data.
2129 static int compat_nfs_getfh_res_trans(union nfsctl_res *kres,
2130 union compat_nfsctl_res __user *res)
2132 int err;
2134 err = copy_to_user(res, kres, sizeof(*res));
2136 return (err) ? -EFAULT : 0;
2139 asmlinkage long compat_sys_nfsservctl(int cmd,
2140 struct compat_nfsctl_arg __user *arg,
2141 union compat_nfsctl_res __user *res)
2143 struct nfsctl_arg *karg;
2144 union nfsctl_res *kres;
2145 mm_segment_t oldfs;
2146 int err;
2148 karg = kmalloc(sizeof(*karg), GFP_USER);
2149 kres = kmalloc(sizeof(*kres), GFP_USER);
2150 if(!karg || !kres) {
2151 err = -ENOMEM;
2152 goto done;
2155 switch(cmd) {
2156 case NFSCTL_SVC:
2157 err = compat_nfs_svc_trans(karg, arg);
2158 break;
2160 case NFSCTL_ADDCLIENT:
2161 err = compat_nfs_clnt_trans(karg, arg);
2162 break;
2164 case NFSCTL_DELCLIENT:
2165 err = compat_nfs_clnt_trans(karg, arg);
2166 break;
2168 case NFSCTL_EXPORT:
2169 case NFSCTL_UNEXPORT:
2170 err = compat_nfs_exp_trans(karg, arg);
2171 break;
2173 case NFSCTL_GETFD:
2174 err = compat_nfs_getfd_trans(karg, arg);
2175 break;
2177 case NFSCTL_GETFS:
2178 err = compat_nfs_getfs_trans(karg, arg);
2179 break;
2181 default:
2182 err = -EINVAL;
2183 break;
2186 if (err)
2187 goto done;
2189 oldfs = get_fs();
2190 set_fs(KERNEL_DS);
2191 /* The __user pointer casts are valid because of the set_fs() */
2192 err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres);
2193 set_fs(oldfs);
2195 if (err)
2196 goto done;
2198 if((cmd == NFSCTL_GETFD) ||
2199 (cmd == NFSCTL_GETFS))
2200 err = compat_nfs_getfh_res_trans(kres, res);
2202 done:
2203 kfree(karg);
2204 kfree(kres);
2205 return err;
2207 #else /* !NFSD */
2208 long asmlinkage compat_sys_nfsservctl(int cmd, void *notused, void *notused2)
2210 return sys_ni_syscall();
2212 #endif