[PATCH] AF_PACKET: Fix BPF handling.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / compat.c
blob7c8dd28b0cb1b7fa6a92ca6379e904d5c88e916e
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 int compat_printk(const char *fmt, ...)
61 va_list ap;
62 int ret;
63 if (!compat_log)
64 return 0;
65 va_start(ap, fmt);
66 ret = vprintk(fmt, ap);
67 va_end(ap);
68 return ret;
71 #include "read_write.h"
74 * Not all architectures have sys_utime, so implement this in terms
75 * of sys_utimes.
77 asmlinkage long compat_sys_utime(char __user *filename, struct compat_utimbuf __user *t)
79 struct timeval tv[2];
81 if (t) {
82 if (get_user(tv[0].tv_sec, &t->actime) ||
83 get_user(tv[1].tv_sec, &t->modtime))
84 return -EFAULT;
85 tv[0].tv_usec = 0;
86 tv[1].tv_usec = 0;
88 return do_utimes(AT_FDCWD, filename, t ? tv : NULL);
91 asmlinkage long compat_sys_futimesat(unsigned int dfd, char __user *filename, struct compat_timeval __user *t)
93 struct timeval tv[2];
95 if (t) {
96 if (get_user(tv[0].tv_sec, &t[0].tv_sec) ||
97 get_user(tv[0].tv_usec, &t[0].tv_usec) ||
98 get_user(tv[1].tv_sec, &t[1].tv_sec) ||
99 get_user(tv[1].tv_usec, &t[1].tv_usec))
100 return -EFAULT;
102 return do_utimes(dfd, filename, t ? tv : NULL);
105 asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval __user *t)
107 return compat_sys_futimesat(AT_FDCWD, filename, t);
110 asmlinkage long compat_sys_newstat(char __user * filename,
111 struct compat_stat __user *statbuf)
113 struct kstat stat;
114 int error = vfs_stat_fd(AT_FDCWD, filename, &stat);
116 if (!error)
117 error = cp_compat_stat(&stat, statbuf);
118 return error;
121 asmlinkage long compat_sys_newlstat(char __user * filename,
122 struct compat_stat __user *statbuf)
124 struct kstat stat;
125 int error = vfs_lstat_fd(AT_FDCWD, filename, &stat);
127 if (!error)
128 error = cp_compat_stat(&stat, statbuf);
129 return error;
132 #ifndef __ARCH_WANT_STAT64
133 asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user *filename,
134 struct compat_stat __user *statbuf, int flag)
136 struct kstat stat;
137 int error = -EINVAL;
139 if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
140 goto out;
142 if (flag & AT_SYMLINK_NOFOLLOW)
143 error = vfs_lstat_fd(dfd, filename, &stat);
144 else
145 error = vfs_stat_fd(dfd, filename, &stat);
147 if (!error)
148 error = cp_compat_stat(&stat, statbuf);
150 out:
151 return error;
153 #endif
155 asmlinkage long compat_sys_newfstat(unsigned int fd,
156 struct compat_stat __user * statbuf)
158 struct kstat stat;
159 int error = vfs_fstat(fd, &stat);
161 if (!error)
162 error = cp_compat_stat(&stat, statbuf);
163 return error;
166 static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf)
169 if (sizeof ubuf->f_blocks == 4) {
170 if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail) &
171 0xffffffff00000000ULL)
172 return -EOVERFLOW;
173 /* f_files and f_ffree may be -1; it's okay
174 * to stuff that into 32 bits */
175 if (kbuf->f_files != 0xffffffffffffffffULL
176 && (kbuf->f_files & 0xffffffff00000000ULL))
177 return -EOVERFLOW;
178 if (kbuf->f_ffree != 0xffffffffffffffffULL
179 && (kbuf->f_ffree & 0xffffffff00000000ULL))
180 return -EOVERFLOW;
182 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
183 __put_user(kbuf->f_type, &ubuf->f_type) ||
184 __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
185 __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
186 __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
187 __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
188 __put_user(kbuf->f_files, &ubuf->f_files) ||
189 __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
190 __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
191 __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
192 __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
193 __put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
194 __put_user(0, &ubuf->f_spare[0]) ||
195 __put_user(0, &ubuf->f_spare[1]) ||
196 __put_user(0, &ubuf->f_spare[2]) ||
197 __put_user(0, &ubuf->f_spare[3]) ||
198 __put_user(0, &ubuf->f_spare[4]))
199 return -EFAULT;
200 return 0;
204 * The following statfs calls are copies of code from fs/open.c and
205 * should be checked against those from time to time
207 asmlinkage long compat_sys_statfs(const char __user *path, struct compat_statfs __user *buf)
209 struct nameidata nd;
210 int error;
212 error = user_path_walk(path, &nd);
213 if (!error) {
214 struct kstatfs tmp;
215 error = vfs_statfs(nd.dentry, &tmp);
216 if (!error)
217 error = put_compat_statfs(buf, &tmp);
218 path_release(&nd);
220 return error;
223 asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs __user *buf)
225 struct file * file;
226 struct kstatfs tmp;
227 int error;
229 error = -EBADF;
230 file = fget(fd);
231 if (!file)
232 goto out;
233 error = vfs_statfs(file->f_dentry, &tmp);
234 if (!error)
235 error = put_compat_statfs(buf, &tmp);
236 fput(file);
237 out:
238 return error;
241 static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
243 if (sizeof ubuf->f_blocks == 4) {
244 if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail) &
245 0xffffffff00000000ULL)
246 return -EOVERFLOW;
247 /* f_files and f_ffree may be -1; it's okay
248 * to stuff that into 32 bits */
249 if (kbuf->f_files != 0xffffffffffffffffULL
250 && (kbuf->f_files & 0xffffffff00000000ULL))
251 return -EOVERFLOW;
252 if (kbuf->f_ffree != 0xffffffffffffffffULL
253 && (kbuf->f_ffree & 0xffffffff00000000ULL))
254 return -EOVERFLOW;
256 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
257 __put_user(kbuf->f_type, &ubuf->f_type) ||
258 __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
259 __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
260 __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
261 __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
262 __put_user(kbuf->f_files, &ubuf->f_files) ||
263 __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
264 __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
265 __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
266 __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
267 __put_user(kbuf->f_frsize, &ubuf->f_frsize))
268 return -EFAULT;
269 return 0;
272 asmlinkage long compat_sys_statfs64(const char __user *path, compat_size_t sz, struct compat_statfs64 __user *buf)
274 struct nameidata nd;
275 int error;
277 if (sz != sizeof(*buf))
278 return -EINVAL;
280 error = user_path_walk(path, &nd);
281 if (!error) {
282 struct kstatfs tmp;
283 error = vfs_statfs(nd.dentry, &tmp);
284 if (!error)
285 error = put_compat_statfs64(buf, &tmp);
286 path_release(&nd);
288 return error;
291 asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user *buf)
293 struct file * file;
294 struct kstatfs tmp;
295 int error;
297 if (sz != sizeof(*buf))
298 return -EINVAL;
300 error = -EBADF;
301 file = fget(fd);
302 if (!file)
303 goto out;
304 error = vfs_statfs(file->f_dentry, &tmp);
305 if (!error)
306 error = put_compat_statfs64(buf, &tmp);
307 fput(file);
308 out:
309 return error;
312 /* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */
314 #define IOCTL_HASHSIZE 256
315 static struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE];
317 static inline unsigned long ioctl32_hash(unsigned long cmd)
319 return (((cmd >> 6) ^ (cmd >> 4) ^ cmd)) % IOCTL_HASHSIZE;
322 static void ioctl32_insert_translation(struct ioctl_trans *trans)
324 unsigned long hash;
325 struct ioctl_trans *t;
327 hash = ioctl32_hash (trans->cmd);
328 if (!ioctl32_hash_table[hash])
329 ioctl32_hash_table[hash] = trans;
330 else {
331 t = ioctl32_hash_table[hash];
332 while (t->next)
333 t = t->next;
334 trans->next = NULL;
335 t->next = trans;
339 static int __init init_sys32_ioctl(void)
341 int i;
343 for (i = 0; i < ioctl_table_size; i++) {
344 if (ioctl_start[i].next != 0) {
345 printk("ioctl translation %d bad\n",i);
346 return -1;
349 ioctl32_insert_translation(&ioctl_start[i]);
351 return 0;
354 __initcall(init_sys32_ioctl);
356 static void compat_ioctl_error(struct file *filp, unsigned int fd,
357 unsigned int cmd, unsigned long arg)
359 char buf[10];
360 char *fn = "?";
361 char *path;
363 /* find the name of the device. */
364 path = (char *)__get_free_page(GFP_KERNEL);
365 if (path) {
366 fn = d_path(filp->f_dentry, filp->f_vfsmnt, path, PAGE_SIZE);
367 if (IS_ERR(fn))
368 fn = "?";
371 sprintf(buf,"'%c'", (cmd>>24) & 0x3f);
372 if (!isprint(buf[1]))
373 sprintf(buf, "%02x", buf[1]);
374 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
375 "cmd(%08x){%s} arg(%08x) on %s\n",
376 current->comm, current->pid,
377 (int)fd, (unsigned int)cmd, buf,
378 (unsigned int)arg, fn);
380 if (path)
381 free_page((unsigned long)path);
384 asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
385 unsigned long arg)
387 struct file *filp;
388 int error = -EBADF;
389 struct ioctl_trans *t;
390 int fput_needed;
392 filp = fget_light(fd, &fput_needed);
393 if (!filp)
394 goto out;
396 /* RED-PEN how should LSM module know it's handling 32bit? */
397 error = security_file_ioctl(filp, cmd, arg);
398 if (error)
399 goto out_fput;
402 * To allow the compat_ioctl handlers to be self contained
403 * we need to check the common ioctls here first.
404 * Just handle them with the standard handlers below.
406 switch (cmd) {
407 case FIOCLEX:
408 case FIONCLEX:
409 case FIONBIO:
410 case FIOASYNC:
411 case FIOQSIZE:
412 break;
414 case FIBMAP:
415 case FIGETBSZ:
416 case FIONREAD:
417 if (S_ISREG(filp->f_dentry->d_inode->i_mode))
418 break;
419 /*FALL THROUGH*/
421 default:
422 if (filp->f_op && filp->f_op->compat_ioctl) {
423 error = filp->f_op->compat_ioctl(filp, cmd, arg);
424 if (error != -ENOIOCTLCMD)
425 goto out_fput;
428 if (!filp->f_op ||
429 (!filp->f_op->ioctl && !filp->f_op->unlocked_ioctl))
430 goto do_ioctl;
431 break;
434 for (t = ioctl32_hash_table[ioctl32_hash(cmd)]; t; t = t->next) {
435 if (t->cmd == cmd)
436 goto found_handler;
439 if (S_ISSOCK(filp->f_dentry->d_inode->i_mode) &&
440 cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
441 error = siocdevprivate_ioctl(fd, cmd, arg);
442 } else {
443 static int count;
445 if (++count <= 50)
446 compat_ioctl_error(filp, fd, cmd, arg);
447 error = -EINVAL;
450 goto out_fput;
452 found_handler:
453 if (t->handler) {
454 lock_kernel();
455 error = t->handler(fd, cmd, arg, filp);
456 unlock_kernel();
457 goto out_fput;
460 do_ioctl:
461 error = vfs_ioctl(filp, fd, cmd, arg);
462 out_fput:
463 fput_light(filp, fput_needed);
464 out:
465 return error;
468 static int get_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
470 if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
471 __get_user(kfl->l_type, &ufl->l_type) ||
472 __get_user(kfl->l_whence, &ufl->l_whence) ||
473 __get_user(kfl->l_start, &ufl->l_start) ||
474 __get_user(kfl->l_len, &ufl->l_len) ||
475 __get_user(kfl->l_pid, &ufl->l_pid))
476 return -EFAULT;
477 return 0;
480 static int put_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
482 if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
483 __put_user(kfl->l_type, &ufl->l_type) ||
484 __put_user(kfl->l_whence, &ufl->l_whence) ||
485 __put_user(kfl->l_start, &ufl->l_start) ||
486 __put_user(kfl->l_len, &ufl->l_len) ||
487 __put_user(kfl->l_pid, &ufl->l_pid))
488 return -EFAULT;
489 return 0;
492 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
493 static int get_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl)
495 if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
496 __get_user(kfl->l_type, &ufl->l_type) ||
497 __get_user(kfl->l_whence, &ufl->l_whence) ||
498 __get_user(kfl->l_start, &ufl->l_start) ||
499 __get_user(kfl->l_len, &ufl->l_len) ||
500 __get_user(kfl->l_pid, &ufl->l_pid))
501 return -EFAULT;
502 return 0;
504 #endif
506 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
507 static int put_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl)
509 if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
510 __put_user(kfl->l_type, &ufl->l_type) ||
511 __put_user(kfl->l_whence, &ufl->l_whence) ||
512 __put_user(kfl->l_start, &ufl->l_start) ||
513 __put_user(kfl->l_len, &ufl->l_len) ||
514 __put_user(kfl->l_pid, &ufl->l_pid))
515 return -EFAULT;
516 return 0;
518 #endif
520 asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
521 unsigned long arg)
523 mm_segment_t old_fs;
524 struct flock f;
525 long ret;
527 switch (cmd) {
528 case F_GETLK:
529 case F_SETLK:
530 case F_SETLKW:
531 ret = get_compat_flock(&f, compat_ptr(arg));
532 if (ret != 0)
533 break;
534 old_fs = get_fs();
535 set_fs(KERNEL_DS);
536 ret = sys_fcntl(fd, cmd, (unsigned long)&f);
537 set_fs(old_fs);
538 if (cmd == F_GETLK && ret == 0) {
539 /* GETLK was successfule and we need to return the data...
540 * but it needs to fit in the compat structure.
541 * l_start shouldn't be too big, unless the original
542 * start + end is greater than COMPAT_OFF_T_MAX, in which
543 * case the app was asking for trouble, so we return
544 * -EOVERFLOW in that case.
545 * l_len could be too big, in which case we just truncate it,
546 * and only allow the app to see that part of the conflicting
547 * lock that might make sense to it anyway
550 if (f.l_start > COMPAT_OFF_T_MAX)
551 ret = -EOVERFLOW;
552 if (f.l_len > COMPAT_OFF_T_MAX)
553 f.l_len = COMPAT_OFF_T_MAX;
554 if (ret == 0)
555 ret = put_compat_flock(&f, compat_ptr(arg));
557 break;
559 case F_GETLK64:
560 case F_SETLK64:
561 case F_SETLKW64:
562 ret = get_compat_flock64(&f, compat_ptr(arg));
563 if (ret != 0)
564 break;
565 old_fs = get_fs();
566 set_fs(KERNEL_DS);
567 ret = sys_fcntl(fd, (cmd == F_GETLK64) ? F_GETLK :
568 ((cmd == F_SETLK64) ? F_SETLK : F_SETLKW),
569 (unsigned long)&f);
570 set_fs(old_fs);
571 if (cmd == F_GETLK64 && ret == 0) {
572 /* need to return lock information - see above for commentary */
573 if (f.l_start > COMPAT_LOFF_T_MAX)
574 ret = -EOVERFLOW;
575 if (f.l_len > COMPAT_LOFF_T_MAX)
576 f.l_len = COMPAT_LOFF_T_MAX;
577 if (ret == 0)
578 ret = put_compat_flock64(&f, compat_ptr(arg));
580 break;
582 default:
583 ret = sys_fcntl(fd, cmd, arg);
584 break;
586 return ret;
589 asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
590 unsigned long arg)
592 if ((cmd == F_GETLK64) || (cmd == F_SETLK64) || (cmd == F_SETLKW64))
593 return -EINVAL;
594 return compat_sys_fcntl64(fd, cmd, arg);
597 asmlinkage long
598 compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
600 long ret;
601 aio_context_t ctx64;
603 mm_segment_t oldfs = get_fs();
604 if (unlikely(get_user(ctx64, ctx32p)))
605 return -EFAULT;
607 set_fs(KERNEL_DS);
608 /* The __user pointer cast is valid because of the set_fs() */
609 ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
610 set_fs(oldfs);
611 /* truncating is ok because it's a user address */
612 if (!ret)
613 ret = put_user((u32) ctx64, ctx32p);
614 return ret;
617 asmlinkage long
618 compat_sys_io_getevents(aio_context_t ctx_id,
619 unsigned long min_nr,
620 unsigned long nr,
621 struct io_event __user *events,
622 struct compat_timespec __user *timeout)
624 long ret;
625 struct timespec t;
626 struct timespec __user *ut = NULL;
628 ret = -EFAULT;
629 if (unlikely(!access_ok(VERIFY_WRITE, events,
630 nr * sizeof(struct io_event))))
631 goto out;
632 if (timeout) {
633 if (get_compat_timespec(&t, timeout))
634 goto out;
636 ut = compat_alloc_user_space(sizeof(*ut));
637 if (copy_to_user(ut, &t, sizeof(t)) )
638 goto out;
640 ret = sys_io_getevents(ctx_id, min_nr, nr, events, ut);
641 out:
642 return ret;
645 static inline long
646 copy_iocb(long nr, u32 __user *ptr32, struct iocb __user * __user *ptr64)
648 compat_uptr_t uptr;
649 int i;
651 for (i = 0; i < nr; ++i) {
652 if (get_user(uptr, ptr32 + i))
653 return -EFAULT;
654 if (put_user(compat_ptr(uptr), ptr64 + i))
655 return -EFAULT;
657 return 0;
660 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
662 asmlinkage long
663 compat_sys_io_submit(aio_context_t ctx_id, int nr, u32 __user *iocb)
665 struct iocb __user * __user *iocb64;
666 long ret;
668 if (unlikely(nr < 0))
669 return -EINVAL;
671 if (nr > MAX_AIO_SUBMITS)
672 nr = MAX_AIO_SUBMITS;
674 iocb64 = compat_alloc_user_space(nr * sizeof(*iocb64));
675 ret = copy_iocb(nr, iocb, iocb64);
676 if (!ret)
677 ret = sys_io_submit(ctx_id, nr, iocb64);
678 return ret;
681 struct compat_ncp_mount_data {
682 compat_int_t version;
683 compat_uint_t ncp_fd;
684 __compat_uid_t mounted_uid;
685 compat_pid_t wdog_pid;
686 unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
687 compat_uint_t time_out;
688 compat_uint_t retry_count;
689 compat_uint_t flags;
690 __compat_uid_t uid;
691 __compat_gid_t gid;
692 compat_mode_t file_mode;
693 compat_mode_t dir_mode;
696 struct compat_ncp_mount_data_v4 {
697 compat_int_t version;
698 compat_ulong_t flags;
699 compat_ulong_t mounted_uid;
700 compat_long_t wdog_pid;
701 compat_uint_t ncp_fd;
702 compat_uint_t time_out;
703 compat_uint_t retry_count;
704 compat_ulong_t uid;
705 compat_ulong_t gid;
706 compat_ulong_t file_mode;
707 compat_ulong_t dir_mode;
710 static void *do_ncp_super_data_conv(void *raw_data)
712 int version = *(unsigned int *)raw_data;
714 if (version == 3) {
715 struct compat_ncp_mount_data *c_n = raw_data;
716 struct ncp_mount_data *n = raw_data;
718 n->dir_mode = c_n->dir_mode;
719 n->file_mode = c_n->file_mode;
720 n->gid = c_n->gid;
721 n->uid = c_n->uid;
722 memmove (n->mounted_vol, c_n->mounted_vol, (sizeof (c_n->mounted_vol) + 3 * sizeof (unsigned int)));
723 n->wdog_pid = c_n->wdog_pid;
724 n->mounted_uid = c_n->mounted_uid;
725 } else if (version == 4) {
726 struct compat_ncp_mount_data_v4 *c_n = raw_data;
727 struct ncp_mount_data_v4 *n = raw_data;
729 n->dir_mode = c_n->dir_mode;
730 n->file_mode = c_n->file_mode;
731 n->gid = c_n->gid;
732 n->uid = c_n->uid;
733 n->retry_count = c_n->retry_count;
734 n->time_out = c_n->time_out;
735 n->ncp_fd = c_n->ncp_fd;
736 n->wdog_pid = c_n->wdog_pid;
737 n->mounted_uid = c_n->mounted_uid;
738 n->flags = c_n->flags;
739 } else if (version != 5) {
740 return NULL;
743 return raw_data;
746 struct compat_smb_mount_data {
747 compat_int_t version;
748 __compat_uid_t mounted_uid;
749 __compat_uid_t uid;
750 __compat_gid_t gid;
751 compat_mode_t file_mode;
752 compat_mode_t dir_mode;
755 static void *do_smb_super_data_conv(void *raw_data)
757 struct smb_mount_data *s = raw_data;
758 struct compat_smb_mount_data *c_s = raw_data;
760 if (c_s->version != SMB_MOUNT_OLDVERSION)
761 goto out;
762 s->dir_mode = c_s->dir_mode;
763 s->file_mode = c_s->file_mode;
764 s->gid = c_s->gid;
765 s->uid = c_s->uid;
766 s->mounted_uid = c_s->mounted_uid;
767 out:
768 return raw_data;
771 struct compat_nfs_string {
772 compat_uint_t len;
773 compat_uptr_t data;
776 static inline void compat_nfs_string(struct nfs_string *dst,
777 struct compat_nfs_string *src)
779 dst->data = compat_ptr(src->data);
780 dst->len = src->len;
783 struct compat_nfs4_mount_data_v1 {
784 compat_int_t version;
785 compat_int_t flags;
786 compat_int_t rsize;
787 compat_int_t wsize;
788 compat_int_t timeo;
789 compat_int_t retrans;
790 compat_int_t acregmin;
791 compat_int_t acregmax;
792 compat_int_t acdirmin;
793 compat_int_t acdirmax;
794 struct compat_nfs_string client_addr;
795 struct compat_nfs_string mnt_path;
796 struct compat_nfs_string hostname;
797 compat_uint_t host_addrlen;
798 compat_uptr_t host_addr;
799 compat_int_t proto;
800 compat_int_t auth_flavourlen;
801 compat_uptr_t auth_flavours;
804 static int do_nfs4_super_data_conv(void *raw_data)
806 int version = *(compat_uint_t *) raw_data;
808 if (version == 1) {
809 struct compat_nfs4_mount_data_v1 *raw = raw_data;
810 struct nfs4_mount_data *real = raw_data;
812 /* copy the fields backwards */
813 real->auth_flavours = compat_ptr(raw->auth_flavours);
814 real->auth_flavourlen = raw->auth_flavourlen;
815 real->proto = raw->proto;
816 real->host_addr = compat_ptr(raw->host_addr);
817 real->host_addrlen = raw->host_addrlen;
818 compat_nfs_string(&real->hostname, &raw->hostname);
819 compat_nfs_string(&real->mnt_path, &raw->mnt_path);
820 compat_nfs_string(&real->client_addr, &raw->client_addr);
821 real->acdirmax = raw->acdirmax;
822 real->acdirmin = raw->acdirmin;
823 real->acregmax = raw->acregmax;
824 real->acregmin = raw->acregmin;
825 real->retrans = raw->retrans;
826 real->timeo = raw->timeo;
827 real->wsize = raw->wsize;
828 real->rsize = raw->rsize;
829 real->flags = raw->flags;
830 real->version = raw->version;
832 else {
833 return -EINVAL;
836 return 0;
839 #define SMBFS_NAME "smbfs"
840 #define NCPFS_NAME "ncpfs"
841 #define NFS4_NAME "nfs4"
843 asmlinkage long compat_sys_mount(char __user * dev_name, char __user * dir_name,
844 char __user * type, unsigned long flags,
845 void __user * data)
847 unsigned long type_page;
848 unsigned long data_page;
849 unsigned long dev_page;
850 char *dir_page;
851 int retval;
853 retval = copy_mount_options (type, &type_page);
854 if (retval < 0)
855 goto out;
857 dir_page = getname(dir_name);
858 retval = PTR_ERR(dir_page);
859 if (IS_ERR(dir_page))
860 goto out1;
862 retval = copy_mount_options (dev_name, &dev_page);
863 if (retval < 0)
864 goto out2;
866 retval = copy_mount_options (data, &data_page);
867 if (retval < 0)
868 goto out3;
870 retval = -EINVAL;
872 if (type_page && data_page) {
873 if (!strcmp((char *)type_page, SMBFS_NAME)) {
874 do_smb_super_data_conv((void *)data_page);
875 } else if (!strcmp((char *)type_page, NCPFS_NAME)) {
876 do_ncp_super_data_conv((void *)data_page);
877 } else if (!strcmp((char *)type_page, NFS4_NAME)) {
878 if (do_nfs4_super_data_conv((void *) data_page))
879 goto out4;
883 lock_kernel();
884 retval = do_mount((char*)dev_page, dir_page, (char*)type_page,
885 flags, (void*)data_page);
886 unlock_kernel();
888 out4:
889 free_page(data_page);
890 out3:
891 free_page(dev_page);
892 out2:
893 putname(dir_page);
894 out1:
895 free_page(type_page);
896 out:
897 return retval;
900 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
901 #define COMPAT_ROUND_UP(x) (((x)+sizeof(compat_long_t)-1) & \
902 ~(sizeof(compat_long_t)-1))
904 struct compat_old_linux_dirent {
905 compat_ulong_t d_ino;
906 compat_ulong_t d_offset;
907 unsigned short d_namlen;
908 char d_name[1];
911 struct compat_readdir_callback {
912 struct compat_old_linux_dirent __user *dirent;
913 int result;
916 static int compat_fillonedir(void *__buf, const char *name, int namlen,
917 loff_t offset, u64 ino, unsigned int d_type)
919 struct compat_readdir_callback *buf = __buf;
920 struct compat_old_linux_dirent __user *dirent;
921 compat_ulong_t d_ino;
923 if (buf->result)
924 return -EINVAL;
925 d_ino = ino;
926 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
927 return -EOVERFLOW;
928 buf->result++;
929 dirent = buf->dirent;
930 if (!access_ok(VERIFY_WRITE, dirent,
931 (unsigned long)(dirent->d_name + namlen + 1) -
932 (unsigned long)dirent))
933 goto efault;
934 if ( __put_user(d_ino, &dirent->d_ino) ||
935 __put_user(offset, &dirent->d_offset) ||
936 __put_user(namlen, &dirent->d_namlen) ||
937 __copy_to_user(dirent->d_name, name, namlen) ||
938 __put_user(0, dirent->d_name + namlen))
939 goto efault;
940 return 0;
941 efault:
942 buf->result = -EFAULT;
943 return -EFAULT;
946 asmlinkage long compat_sys_old_readdir(unsigned int fd,
947 struct compat_old_linux_dirent __user *dirent, unsigned int count)
949 int error;
950 struct file *file;
951 struct compat_readdir_callback buf;
953 error = -EBADF;
954 file = fget(fd);
955 if (!file)
956 goto out;
958 buf.result = 0;
959 buf.dirent = dirent;
961 error = vfs_readdir(file, compat_fillonedir, &buf);
962 if (error >= 0)
963 error = buf.result;
965 fput(file);
966 out:
967 return error;
970 struct compat_linux_dirent {
971 compat_ulong_t d_ino;
972 compat_ulong_t d_off;
973 unsigned short d_reclen;
974 char d_name[1];
977 struct compat_getdents_callback {
978 struct compat_linux_dirent __user *current_dir;
979 struct compat_linux_dirent __user *previous;
980 int count;
981 int error;
984 static int compat_filldir(void *__buf, const char *name, int namlen,
985 loff_t offset, u64 ino, unsigned int d_type)
987 struct compat_linux_dirent __user * dirent;
988 struct compat_getdents_callback *buf = __buf;
989 compat_ulong_t d_ino;
990 int reclen = COMPAT_ROUND_UP(NAME_OFFSET(dirent) + namlen + 2);
992 buf->error = -EINVAL; /* only used if we fail.. */
993 if (reclen > buf->count)
994 return -EINVAL;
995 d_ino = ino;
996 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
997 return -EOVERFLOW;
998 dirent = buf->previous;
999 if (dirent) {
1000 if (__put_user(offset, &dirent->d_off))
1001 goto efault;
1003 dirent = buf->current_dir;
1004 if (__put_user(d_ino, &dirent->d_ino))
1005 goto efault;
1006 if (__put_user(reclen, &dirent->d_reclen))
1007 goto efault;
1008 if (copy_to_user(dirent->d_name, name, namlen))
1009 goto efault;
1010 if (__put_user(0, dirent->d_name + namlen))
1011 goto efault;
1012 if (__put_user(d_type, (char __user *) dirent + reclen - 1))
1013 goto efault;
1014 buf->previous = dirent;
1015 dirent = (void __user *)dirent + reclen;
1016 buf->current_dir = dirent;
1017 buf->count -= reclen;
1018 return 0;
1019 efault:
1020 buf->error = -EFAULT;
1021 return -EFAULT;
1024 asmlinkage long compat_sys_getdents(unsigned int fd,
1025 struct compat_linux_dirent __user *dirent, unsigned int count)
1027 struct file * file;
1028 struct compat_linux_dirent __user * lastdirent;
1029 struct compat_getdents_callback buf;
1030 int error;
1032 error = -EFAULT;
1033 if (!access_ok(VERIFY_WRITE, dirent, count))
1034 goto out;
1036 error = -EBADF;
1037 file = fget(fd);
1038 if (!file)
1039 goto out;
1041 buf.current_dir = dirent;
1042 buf.previous = NULL;
1043 buf.count = count;
1044 buf.error = 0;
1046 error = vfs_readdir(file, compat_filldir, &buf);
1047 if (error < 0)
1048 goto out_putf;
1049 error = buf.error;
1050 lastdirent = buf.previous;
1051 if (lastdirent) {
1052 if (put_user(file->f_pos, &lastdirent->d_off))
1053 error = -EFAULT;
1054 else
1055 error = count - buf.count;
1058 out_putf:
1059 fput(file);
1060 out:
1061 return error;
1064 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
1065 #define COMPAT_ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1067 struct compat_getdents_callback64 {
1068 struct linux_dirent64 __user *current_dir;
1069 struct linux_dirent64 __user *previous;
1070 int count;
1071 int error;
1074 static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t offset,
1075 u64 ino, unsigned int d_type)
1077 struct linux_dirent64 __user *dirent;
1078 struct compat_getdents_callback64 *buf = __buf;
1079 int jj = NAME_OFFSET(dirent);
1080 int reclen = COMPAT_ROUND_UP64(jj + namlen + 1);
1081 u64 off;
1083 buf->error = -EINVAL; /* only used if we fail.. */
1084 if (reclen > buf->count)
1085 return -EINVAL;
1086 dirent = buf->previous;
1088 if (dirent) {
1089 if (__put_user_unaligned(offset, &dirent->d_off))
1090 goto efault;
1092 dirent = buf->current_dir;
1093 if (__put_user_unaligned(ino, &dirent->d_ino))
1094 goto efault;
1095 off = 0;
1096 if (__put_user_unaligned(off, &dirent->d_off))
1097 goto efault;
1098 if (__put_user(reclen, &dirent->d_reclen))
1099 goto efault;
1100 if (__put_user(d_type, &dirent->d_type))
1101 goto efault;
1102 if (copy_to_user(dirent->d_name, name, namlen))
1103 goto efault;
1104 if (__put_user(0, dirent->d_name + namlen))
1105 goto efault;
1106 buf->previous = dirent;
1107 dirent = (void __user *)dirent + reclen;
1108 buf->current_dir = dirent;
1109 buf->count -= reclen;
1110 return 0;
1111 efault:
1112 buf->error = -EFAULT;
1113 return -EFAULT;
1116 asmlinkage long compat_sys_getdents64(unsigned int fd,
1117 struct linux_dirent64 __user * dirent, unsigned int count)
1119 struct file * file;
1120 struct linux_dirent64 __user * lastdirent;
1121 struct compat_getdents_callback64 buf;
1122 int error;
1124 error = -EFAULT;
1125 if (!access_ok(VERIFY_WRITE, dirent, count))
1126 goto out;
1128 error = -EBADF;
1129 file = fget(fd);
1130 if (!file)
1131 goto out;
1133 buf.current_dir = dirent;
1134 buf.previous = NULL;
1135 buf.count = count;
1136 buf.error = 0;
1138 error = vfs_readdir(file, compat_filldir64, &buf);
1139 if (error < 0)
1140 goto out_putf;
1141 error = buf.error;
1142 lastdirent = buf.previous;
1143 if (lastdirent) {
1144 typeof(lastdirent->d_off) d_off = file->f_pos;
1145 __put_user_unaligned(d_off, &lastdirent->d_off);
1146 error = count - buf.count;
1149 out_putf:
1150 fput(file);
1151 out:
1152 return error;
1154 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
1156 static ssize_t compat_do_readv_writev(int type, struct file *file,
1157 const struct compat_iovec __user *uvector,
1158 unsigned long nr_segs, loff_t *pos)
1160 compat_ssize_t tot_len;
1161 struct iovec iovstack[UIO_FASTIOV];
1162 struct iovec *iov=iovstack, *vector;
1163 ssize_t ret;
1164 int seg;
1165 io_fn_t fn;
1166 iov_fn_t fnv;
1169 * SuS says "The readv() function *may* fail if the iovcnt argument
1170 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
1171 * traditionally returned zero for zero segments, so...
1173 ret = 0;
1174 if (nr_segs == 0)
1175 goto out;
1178 * First get the "struct iovec" from user memory and
1179 * verify all the pointers
1181 ret = -EINVAL;
1182 if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
1183 goto out;
1184 if (!file->f_op)
1185 goto out;
1186 if (nr_segs > UIO_FASTIOV) {
1187 ret = -ENOMEM;
1188 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
1189 if (!iov)
1190 goto out;
1192 ret = -EFAULT;
1193 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
1194 goto out;
1197 * Single unix specification:
1198 * We should -EINVAL if an element length is not >= 0 and fitting an
1199 * ssize_t. The total length is fitting an ssize_t
1201 * Be careful here because iov_len is a size_t not an ssize_t
1203 tot_len = 0;
1204 vector = iov;
1205 ret = -EINVAL;
1206 for (seg = 0 ; seg < nr_segs; seg++) {
1207 compat_ssize_t tmp = tot_len;
1208 compat_ssize_t len;
1209 compat_uptr_t buf;
1211 if (__get_user(len, &uvector->iov_len) ||
1212 __get_user(buf, &uvector->iov_base)) {
1213 ret = -EFAULT;
1214 goto out;
1216 if (len < 0) /* size_t not fitting an compat_ssize_t .. */
1217 goto out;
1218 tot_len += len;
1219 if (tot_len < tmp) /* maths overflow on the compat_ssize_t */
1220 goto out;
1221 vector->iov_base = compat_ptr(buf);
1222 vector->iov_len = (compat_size_t) len;
1223 uvector++;
1224 vector++;
1226 if (tot_len == 0) {
1227 ret = 0;
1228 goto out;
1231 ret = rw_verify_area(type, file, pos, tot_len);
1232 if (ret < 0)
1233 goto out;
1235 ret = security_file_permission(file, type == READ ? MAY_READ:MAY_WRITE);
1236 if (ret)
1237 goto out;
1239 fnv = NULL;
1240 if (type == READ) {
1241 fn = file->f_op->read;
1242 fnv = file->f_op->aio_read;
1243 } else {
1244 fn = (io_fn_t)file->f_op->write;
1245 fnv = file->f_op->aio_write;
1248 if (fnv)
1249 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
1250 pos, fnv);
1251 else
1252 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
1254 out:
1255 if (iov != iovstack)
1256 kfree(iov);
1257 if ((ret + (type == READ)) > 0) {
1258 struct dentry *dentry = file->f_dentry;
1259 if (type == READ)
1260 fsnotify_access(dentry);
1261 else
1262 fsnotify_modify(dentry);
1264 return ret;
1267 asmlinkage ssize_t
1268 compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec, unsigned long vlen)
1270 struct file *file;
1271 ssize_t ret = -EBADF;
1273 file = fget(fd);
1274 if (!file)
1275 return -EBADF;
1277 if (!(file->f_mode & FMODE_READ))
1278 goto out;
1280 ret = -EINVAL;
1281 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
1282 goto out;
1284 ret = compat_do_readv_writev(READ, file, vec, vlen, &file->f_pos);
1286 out:
1287 fput(file);
1288 return ret;
1291 asmlinkage ssize_t
1292 compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec, unsigned long vlen)
1294 struct file *file;
1295 ssize_t ret = -EBADF;
1297 file = fget(fd);
1298 if (!file)
1299 return -EBADF;
1300 if (!(file->f_mode & FMODE_WRITE))
1301 goto out;
1303 ret = -EINVAL;
1304 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
1305 goto out;
1307 ret = compat_do_readv_writev(WRITE, file, vec, vlen, &file->f_pos);
1309 out:
1310 fput(file);
1311 return ret;
1314 asmlinkage long
1315 compat_sys_vmsplice(int fd, const struct compat_iovec __user *iov32,
1316 unsigned int nr_segs, unsigned int flags)
1318 unsigned i;
1319 struct iovec __user *iov;
1320 if (nr_segs > UIO_MAXIOV)
1321 return -EINVAL;
1322 iov = compat_alloc_user_space(nr_segs * sizeof(struct iovec));
1323 for (i = 0; i < nr_segs; i++) {
1324 struct compat_iovec v;
1325 if (get_user(v.iov_base, &iov32[i].iov_base) ||
1326 get_user(v.iov_len, &iov32[i].iov_len) ||
1327 put_user(compat_ptr(v.iov_base), &iov[i].iov_base) ||
1328 put_user(v.iov_len, &iov[i].iov_len))
1329 return -EFAULT;
1331 return sys_vmsplice(fd, iov, nr_segs, flags);
1335 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1336 * O_LARGEFILE flag.
1338 asmlinkage long
1339 compat_sys_open(const char __user *filename, int flags, int mode)
1341 return do_sys_open(AT_FDCWD, filename, flags, mode);
1345 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1346 * O_LARGEFILE flag.
1348 asmlinkage long
1349 compat_sys_openat(unsigned int dfd, const char __user *filename, int flags, int mode)
1351 return do_sys_open(dfd, filename, flags, mode);
1355 * compat_count() counts the number of arguments/envelopes. It is basically
1356 * a copy of count() from fs/exec.c, except that it works with 32 bit argv
1357 * and envp pointers.
1359 static int compat_count(compat_uptr_t __user *argv, int max)
1361 int i = 0;
1363 if (argv != NULL) {
1364 for (;;) {
1365 compat_uptr_t p;
1367 if (get_user(p, argv))
1368 return -EFAULT;
1369 if (!p)
1370 break;
1371 argv++;
1372 if(++i > max)
1373 return -E2BIG;
1376 return i;
1380 * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c
1381 * except that it works with 32 bit argv and envp pointers.
1383 static int compat_copy_strings(int argc, compat_uptr_t __user *argv,
1384 struct linux_binprm *bprm)
1386 struct page *kmapped_page = NULL;
1387 char *kaddr = NULL;
1388 int ret;
1390 while (argc-- > 0) {
1391 compat_uptr_t str;
1392 int len;
1393 unsigned long pos;
1395 if (get_user(str, argv+argc) ||
1396 !(len = strnlen_user(compat_ptr(str), bprm->p))) {
1397 ret = -EFAULT;
1398 goto out;
1401 if (bprm->p < len) {
1402 ret = -E2BIG;
1403 goto out;
1406 bprm->p -= len;
1407 /* XXX: add architecture specific overflow check here. */
1408 pos = bprm->p;
1410 while (len > 0) {
1411 int i, new, err;
1412 int offset, bytes_to_copy;
1413 struct page *page;
1415 offset = pos % PAGE_SIZE;
1416 i = pos/PAGE_SIZE;
1417 page = bprm->page[i];
1418 new = 0;
1419 if (!page) {
1420 page = alloc_page(GFP_HIGHUSER);
1421 bprm->page[i] = page;
1422 if (!page) {
1423 ret = -ENOMEM;
1424 goto out;
1426 new = 1;
1429 if (page != kmapped_page) {
1430 if (kmapped_page)
1431 kunmap(kmapped_page);
1432 kmapped_page = page;
1433 kaddr = kmap(kmapped_page);
1435 if (new && offset)
1436 memset(kaddr, 0, offset);
1437 bytes_to_copy = PAGE_SIZE - offset;
1438 if (bytes_to_copy > len) {
1439 bytes_to_copy = len;
1440 if (new)
1441 memset(kaddr+offset+len, 0,
1442 PAGE_SIZE-offset-len);
1444 err = copy_from_user(kaddr+offset, compat_ptr(str),
1445 bytes_to_copy);
1446 if (err) {
1447 ret = -EFAULT;
1448 goto out;
1451 pos += bytes_to_copy;
1452 str += bytes_to_copy;
1453 len -= bytes_to_copy;
1456 ret = 0;
1457 out:
1458 if (kmapped_page)
1459 kunmap(kmapped_page);
1460 return ret;
1463 #ifdef CONFIG_MMU
1465 #define free_arg_pages(bprm) do { } while (0)
1467 #else
1469 static inline void free_arg_pages(struct linux_binprm *bprm)
1471 int i;
1473 for (i = 0; i < MAX_ARG_PAGES; i++) {
1474 if (bprm->page[i])
1475 __free_page(bprm->page[i]);
1476 bprm->page[i] = NULL;
1480 #endif /* CONFIG_MMU */
1483 * compat_do_execve() is mostly a copy of do_execve(), with the exception
1484 * that it processes 32 bit argv and envp pointers.
1486 int compat_do_execve(char * filename,
1487 compat_uptr_t __user *argv,
1488 compat_uptr_t __user *envp,
1489 struct pt_regs * regs)
1491 struct linux_binprm *bprm;
1492 struct file *file;
1493 int retval;
1494 int i;
1496 retval = -ENOMEM;
1497 bprm = kzalloc(sizeof(*bprm), GFP_KERNEL);
1498 if (!bprm)
1499 goto out_ret;
1501 file = open_exec(filename);
1502 retval = PTR_ERR(file);
1503 if (IS_ERR(file))
1504 goto out_kfree;
1506 sched_exec();
1508 bprm->p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
1509 bprm->file = file;
1510 bprm->filename = filename;
1511 bprm->interp = filename;
1512 bprm->mm = mm_alloc();
1513 retval = -ENOMEM;
1514 if (!bprm->mm)
1515 goto out_file;
1517 retval = init_new_context(current, bprm->mm);
1518 if (retval < 0)
1519 goto out_mm;
1521 bprm->argc = compat_count(argv, bprm->p / sizeof(compat_uptr_t));
1522 if ((retval = bprm->argc) < 0)
1523 goto out_mm;
1525 bprm->envc = compat_count(envp, bprm->p / sizeof(compat_uptr_t));
1526 if ((retval = bprm->envc) < 0)
1527 goto out_mm;
1529 retval = security_bprm_alloc(bprm);
1530 if (retval)
1531 goto out;
1533 retval = prepare_binprm(bprm);
1534 if (retval < 0)
1535 goto out;
1537 retval = copy_strings_kernel(1, &bprm->filename, bprm);
1538 if (retval < 0)
1539 goto out;
1541 bprm->exec = bprm->p;
1542 retval = compat_copy_strings(bprm->envc, envp, bprm);
1543 if (retval < 0)
1544 goto out;
1546 retval = compat_copy_strings(bprm->argc, argv, bprm);
1547 if (retval < 0)
1548 goto out;
1550 retval = search_binary_handler(bprm, regs);
1551 if (retval >= 0) {
1552 free_arg_pages(bprm);
1554 /* execve success */
1555 security_bprm_free(bprm);
1556 acct_update_integrals(current);
1557 kfree(bprm);
1558 return retval;
1561 out:
1562 /* Something went wrong, return the inode and free the argument pages*/
1563 for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
1564 struct page * page = bprm->page[i];
1565 if (page)
1566 __free_page(page);
1569 if (bprm->security)
1570 security_bprm_free(bprm);
1572 out_mm:
1573 if (bprm->mm)
1574 mmdrop(bprm->mm);
1576 out_file:
1577 if (bprm->file) {
1578 allow_write_access(bprm->file);
1579 fput(bprm->file);
1582 out_kfree:
1583 kfree(bprm);
1585 out_ret:
1586 return retval;
1589 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1591 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
1594 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1595 * 64-bit unsigned longs.
1597 static
1598 int compat_get_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
1599 unsigned long *fdset)
1601 nr = ROUND_UP(nr, __COMPAT_NFDBITS);
1602 if (ufdset) {
1603 unsigned long odd;
1605 if (!access_ok(VERIFY_WRITE, ufdset, nr*sizeof(compat_ulong_t)))
1606 return -EFAULT;
1608 odd = nr & 1UL;
1609 nr &= ~1UL;
1610 while (nr) {
1611 unsigned long h, l;
1612 __get_user(l, ufdset);
1613 __get_user(h, ufdset+1);
1614 ufdset += 2;
1615 *fdset++ = h << 32 | l;
1616 nr -= 2;
1618 if (odd)
1619 __get_user(*fdset, ufdset);
1620 } else {
1621 /* Tricky, must clear full unsigned long in the
1622 * kernel fdset at the end, this makes sure that
1623 * actually happens.
1625 memset(fdset, 0, ((nr + 1) & ~1)*sizeof(compat_ulong_t));
1627 return 0;
1630 static
1631 void compat_set_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
1632 unsigned long *fdset)
1634 unsigned long odd;
1635 nr = ROUND_UP(nr, __COMPAT_NFDBITS);
1637 if (!ufdset)
1638 return;
1640 odd = nr & 1UL;
1641 nr &= ~1UL;
1642 while (nr) {
1643 unsigned long h, l;
1644 l = *fdset++;
1645 h = l >> 32;
1646 __put_user(l, ufdset);
1647 __put_user(h, ufdset+1);
1648 ufdset += 2;
1649 nr -= 2;
1651 if (odd)
1652 __put_user(*fdset, ufdset);
1657 * This is a virtual copy of sys_select from fs/select.c and probably
1658 * should be compared to it from time to time
1662 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1663 * like to be certain this leads to no problems. So I return
1664 * EINTR just for safety.
1666 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1667 * I'm trying ERESTARTNOHAND which restart only when you want to.
1669 #define MAX_SELECT_SECONDS \
1670 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
1672 int compat_core_sys_select(int n, compat_ulong_t __user *inp,
1673 compat_ulong_t __user *outp, compat_ulong_t __user *exp, s64 *timeout)
1675 fd_set_bits fds;
1676 char *bits;
1677 int size, max_fdset, ret = -EINVAL;
1678 struct fdtable *fdt;
1680 if (n < 0)
1681 goto out_nofds;
1683 /* max_fdset can increase, so grab it once to avoid race */
1684 rcu_read_lock();
1685 fdt = files_fdtable(current->files);
1686 max_fdset = fdt->max_fdset;
1687 rcu_read_unlock();
1688 if (n > max_fdset)
1689 n = max_fdset;
1692 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1693 * since we used fdset we need to allocate memory in units of
1694 * long-words.
1696 ret = -ENOMEM;
1697 size = FDS_BYTES(n);
1698 bits = kmalloc(6 * size, GFP_KERNEL);
1699 if (!bits)
1700 goto out_nofds;
1701 fds.in = (unsigned long *) bits;
1702 fds.out = (unsigned long *) (bits + size);
1703 fds.ex = (unsigned long *) (bits + 2*size);
1704 fds.res_in = (unsigned long *) (bits + 3*size);
1705 fds.res_out = (unsigned long *) (bits + 4*size);
1706 fds.res_ex = (unsigned long *) (bits + 5*size);
1708 if ((ret = compat_get_fd_set(n, inp, fds.in)) ||
1709 (ret = compat_get_fd_set(n, outp, fds.out)) ||
1710 (ret = compat_get_fd_set(n, exp, fds.ex)))
1711 goto out;
1712 zero_fd_set(n, fds.res_in);
1713 zero_fd_set(n, fds.res_out);
1714 zero_fd_set(n, fds.res_ex);
1716 ret = do_select(n, &fds, timeout);
1718 if (ret < 0)
1719 goto out;
1720 if (!ret) {
1721 ret = -ERESTARTNOHAND;
1722 if (signal_pending(current))
1723 goto out;
1724 ret = 0;
1727 compat_set_fd_set(n, inp, fds.res_in);
1728 compat_set_fd_set(n, outp, fds.res_out);
1729 compat_set_fd_set(n, exp, fds.res_ex);
1731 out:
1732 kfree(bits);
1733 out_nofds:
1734 return ret;
1737 asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
1738 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1739 struct compat_timeval __user *tvp)
1741 s64 timeout = -1;
1742 struct compat_timeval tv;
1743 int ret;
1745 if (tvp) {
1746 if (copy_from_user(&tv, tvp, sizeof(tv)))
1747 return -EFAULT;
1749 if (tv.tv_sec < 0 || tv.tv_usec < 0)
1750 return -EINVAL;
1752 /* Cast to u64 to make GCC stop complaining */
1753 if ((u64)tv.tv_sec >= (u64)MAX_INT64_SECONDS)
1754 timeout = -1; /* infinite */
1755 else {
1756 timeout = ROUND_UP(tv.tv_usec, 1000000/HZ);
1757 timeout += tv.tv_sec * HZ;
1761 ret = compat_core_sys_select(n, inp, outp, exp, &timeout);
1763 if (tvp) {
1764 struct compat_timeval rtv;
1766 if (current->personality & STICKY_TIMEOUTS)
1767 goto sticky;
1768 rtv.tv_usec = jiffies_to_usecs(do_div((*(u64*)&timeout), HZ));
1769 rtv.tv_sec = timeout;
1770 if (compat_timeval_compare(&rtv, &tv) >= 0)
1771 rtv = tv;
1772 if (copy_to_user(tvp, &rtv, sizeof(rtv))) {
1773 sticky:
1775 * If an application puts its timeval in read-only
1776 * memory, we don't want the Linux-specific update to
1777 * the timeval to cause a fault after the select has
1778 * completed successfully. However, because we're not
1779 * updating the timeval, we can't restart the system
1780 * call.
1782 if (ret == -ERESTARTNOHAND)
1783 ret = -EINTR;
1787 return ret;
1790 #ifdef TIF_RESTORE_SIGMASK
1791 asmlinkage long compat_sys_pselect7(int n, compat_ulong_t __user *inp,
1792 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1793 struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask,
1794 compat_size_t sigsetsize)
1796 compat_sigset_t ss32;
1797 sigset_t ksigmask, sigsaved;
1798 s64 timeout = MAX_SCHEDULE_TIMEOUT;
1799 struct compat_timespec ts;
1800 int ret;
1802 if (tsp) {
1803 if (copy_from_user(&ts, tsp, sizeof(ts)))
1804 return -EFAULT;
1806 if (ts.tv_sec < 0 || ts.tv_nsec < 0)
1807 return -EINVAL;
1810 if (sigmask) {
1811 if (sigsetsize != sizeof(compat_sigset_t))
1812 return -EINVAL;
1813 if (copy_from_user(&ss32, sigmask, sizeof(ss32)))
1814 return -EFAULT;
1815 sigset_from_compat(&ksigmask, &ss32);
1817 sigdelsetmask(&ksigmask, sigmask(SIGKILL)|sigmask(SIGSTOP));
1818 sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
1821 do {
1822 if (tsp) {
1823 if ((unsigned long)ts.tv_sec < MAX_SELECT_SECONDS) {
1824 timeout = ROUND_UP(ts.tv_nsec, 1000000000/HZ);
1825 timeout += ts.tv_sec * (unsigned long)HZ;
1826 ts.tv_sec = 0;
1827 ts.tv_nsec = 0;
1828 } else {
1829 ts.tv_sec -= MAX_SELECT_SECONDS;
1830 timeout = MAX_SELECT_SECONDS * HZ;
1834 ret = compat_core_sys_select(n, inp, outp, exp, &timeout);
1836 } while (!ret && !timeout && tsp && (ts.tv_sec || ts.tv_nsec));
1838 if (tsp) {
1839 struct compat_timespec rts;
1841 if (current->personality & STICKY_TIMEOUTS)
1842 goto sticky;
1844 rts.tv_sec = timeout / HZ;
1845 rts.tv_nsec = (timeout % HZ) * (NSEC_PER_SEC/HZ);
1846 if (rts.tv_nsec >= NSEC_PER_SEC) {
1847 rts.tv_sec++;
1848 rts.tv_nsec -= NSEC_PER_SEC;
1850 if (compat_timespec_compare(&rts, &ts) >= 0)
1851 rts = ts;
1852 if (copy_to_user(tsp, &rts, sizeof(rts))) {
1853 sticky:
1855 * If an application puts its timeval in read-only
1856 * memory, we don't want the Linux-specific update to
1857 * the timeval to cause a fault after the select has
1858 * completed successfully. However, because we're not
1859 * updating the timeval, we can't restart the system
1860 * call.
1862 if (ret == -ERESTARTNOHAND)
1863 ret = -EINTR;
1867 if (ret == -ERESTARTNOHAND) {
1869 * Don't restore the signal mask yet. Let do_signal() deliver
1870 * the signal on the way back to userspace, before the signal
1871 * mask is restored.
1873 if (sigmask) {
1874 memcpy(&current->saved_sigmask, &sigsaved,
1875 sizeof(sigsaved));
1876 set_thread_flag(TIF_RESTORE_SIGMASK);
1878 } else if (sigmask)
1879 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
1881 return ret;
1884 asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp,
1885 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1886 struct compat_timespec __user *tsp, void __user *sig)
1888 compat_size_t sigsetsize = 0;
1889 compat_uptr_t up = 0;
1891 if (sig) {
1892 if (!access_ok(VERIFY_READ, sig,
1893 sizeof(compat_uptr_t)+sizeof(compat_size_t)) ||
1894 __get_user(up, (compat_uptr_t __user *)sig) ||
1895 __get_user(sigsetsize,
1896 (compat_size_t __user *)(sig+sizeof(up))))
1897 return -EFAULT;
1899 return compat_sys_pselect7(n, inp, outp, exp, tsp, compat_ptr(up),
1900 sigsetsize);
1903 asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
1904 unsigned int nfds, struct compat_timespec __user *tsp,
1905 const compat_sigset_t __user *sigmask, compat_size_t sigsetsize)
1907 compat_sigset_t ss32;
1908 sigset_t ksigmask, sigsaved;
1909 struct compat_timespec ts;
1910 s64 timeout = -1;
1911 int ret;
1913 if (tsp) {
1914 if (copy_from_user(&ts, tsp, sizeof(ts)))
1915 return -EFAULT;
1917 /* We assume that ts.tv_sec is always lower than
1918 the number of seconds that can be expressed in
1919 an s64. Otherwise the compiler bitches at us */
1920 timeout = ROUND_UP(ts.tv_nsec, 1000000000/HZ);
1921 timeout += ts.tv_sec * HZ;
1924 if (sigmask) {
1925 if (sigsetsize != sizeof(compat_sigset_t))
1926 return -EINVAL;
1927 if (copy_from_user(&ss32, sigmask, sizeof(ss32)))
1928 return -EFAULT;
1929 sigset_from_compat(&ksigmask, &ss32);
1931 sigdelsetmask(&ksigmask, sigmask(SIGKILL)|sigmask(SIGSTOP));
1932 sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
1935 ret = do_sys_poll(ufds, nfds, &timeout);
1937 /* We can restart this syscall, usually */
1938 if (ret == -EINTR) {
1940 * Don't restore the signal mask yet. Let do_signal() deliver
1941 * the signal on the way back to userspace, before the signal
1942 * mask is restored.
1944 if (sigmask) {
1945 memcpy(&current->saved_sigmask, &sigsaved,
1946 sizeof(sigsaved));
1947 set_thread_flag(TIF_RESTORE_SIGMASK);
1949 ret = -ERESTARTNOHAND;
1950 } else if (sigmask)
1951 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
1953 if (tsp && timeout >= 0) {
1954 struct compat_timespec rts;
1956 if (current->personality & STICKY_TIMEOUTS)
1957 goto sticky;
1958 /* Yes, we know it's actually an s64, but it's also positive. */
1959 rts.tv_nsec = jiffies_to_usecs(do_div((*(u64*)&timeout), HZ)) *
1960 1000;
1961 rts.tv_sec = timeout;
1962 if (compat_timespec_compare(&rts, &ts) >= 0)
1963 rts = ts;
1964 if (copy_to_user(tsp, &rts, sizeof(rts))) {
1965 sticky:
1967 * If an application puts its timeval in read-only
1968 * memory, we don't want the Linux-specific update to
1969 * the timeval to cause a fault after the select has
1970 * completed successfully. However, because we're not
1971 * updating the timeval, we can't restart the system
1972 * call.
1974 if (ret == -ERESTARTNOHAND && timeout >= 0)
1975 ret = -EINTR;
1979 return ret;
1981 #endif /* TIF_RESTORE_SIGMASK */
1983 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1984 /* Stuff for NFS server syscalls... */
1985 struct compat_nfsctl_svc {
1986 u16 svc32_port;
1987 s32 svc32_nthreads;
1990 struct compat_nfsctl_client {
1991 s8 cl32_ident[NFSCLNT_IDMAX+1];
1992 s32 cl32_naddr;
1993 struct in_addr cl32_addrlist[NFSCLNT_ADDRMAX];
1994 s32 cl32_fhkeytype;
1995 s32 cl32_fhkeylen;
1996 u8 cl32_fhkey[NFSCLNT_KEYMAX];
1999 struct compat_nfsctl_export {
2000 char ex32_client[NFSCLNT_IDMAX+1];
2001 char ex32_path[NFS_MAXPATHLEN+1];
2002 compat_dev_t ex32_dev;
2003 compat_ino_t ex32_ino;
2004 compat_int_t ex32_flags;
2005 __compat_uid_t ex32_anon_uid;
2006 __compat_gid_t ex32_anon_gid;
2009 struct compat_nfsctl_fdparm {
2010 struct sockaddr gd32_addr;
2011 s8 gd32_path[NFS_MAXPATHLEN+1];
2012 compat_int_t gd32_version;
2015 struct compat_nfsctl_fsparm {
2016 struct sockaddr gd32_addr;
2017 s8 gd32_path[NFS_MAXPATHLEN+1];
2018 compat_int_t gd32_maxlen;
2021 struct compat_nfsctl_arg {
2022 compat_int_t ca32_version; /* safeguard */
2023 union {
2024 struct compat_nfsctl_svc u32_svc;
2025 struct compat_nfsctl_client u32_client;
2026 struct compat_nfsctl_export u32_export;
2027 struct compat_nfsctl_fdparm u32_getfd;
2028 struct compat_nfsctl_fsparm u32_getfs;
2029 } u;
2030 #define ca32_svc u.u32_svc
2031 #define ca32_client u.u32_client
2032 #define ca32_export u.u32_export
2033 #define ca32_getfd u.u32_getfd
2034 #define ca32_getfs u.u32_getfs
2037 union compat_nfsctl_res {
2038 __u8 cr32_getfh[NFS_FHSIZE];
2039 struct knfsd_fh cr32_getfs;
2042 static int compat_nfs_svc_trans(struct nfsctl_arg *karg,
2043 struct compat_nfsctl_arg __user *arg)
2045 if (!access_ok(VERIFY_READ, &arg->ca32_svc, sizeof(arg->ca32_svc)) ||
2046 get_user(karg->ca_version, &arg->ca32_version) ||
2047 __get_user(karg->ca_svc.svc_port, &arg->ca32_svc.svc32_port) ||
2048 __get_user(karg->ca_svc.svc_nthreads,
2049 &arg->ca32_svc.svc32_nthreads))
2050 return -EFAULT;
2051 return 0;
2054 static int compat_nfs_clnt_trans(struct nfsctl_arg *karg,
2055 struct compat_nfsctl_arg __user *arg)
2057 if (!access_ok(VERIFY_READ, &arg->ca32_client,
2058 sizeof(arg->ca32_client)) ||
2059 get_user(karg->ca_version, &arg->ca32_version) ||
2060 __copy_from_user(&karg->ca_client.cl_ident[0],
2061 &arg->ca32_client.cl32_ident[0],
2062 NFSCLNT_IDMAX) ||
2063 __get_user(karg->ca_client.cl_naddr,
2064 &arg->ca32_client.cl32_naddr) ||
2065 __copy_from_user(&karg->ca_client.cl_addrlist[0],
2066 &arg->ca32_client.cl32_addrlist[0],
2067 (sizeof(struct in_addr) * NFSCLNT_ADDRMAX)) ||
2068 __get_user(karg->ca_client.cl_fhkeytype,
2069 &arg->ca32_client.cl32_fhkeytype) ||
2070 __get_user(karg->ca_client.cl_fhkeylen,
2071 &arg->ca32_client.cl32_fhkeylen) ||
2072 __copy_from_user(&karg->ca_client.cl_fhkey[0],
2073 &arg->ca32_client.cl32_fhkey[0],
2074 NFSCLNT_KEYMAX))
2075 return -EFAULT;
2077 return 0;
2080 static int compat_nfs_exp_trans(struct nfsctl_arg *karg,
2081 struct compat_nfsctl_arg __user *arg)
2083 if (!access_ok(VERIFY_READ, &arg->ca32_export,
2084 sizeof(arg->ca32_export)) ||
2085 get_user(karg->ca_version, &arg->ca32_version) ||
2086 __copy_from_user(&karg->ca_export.ex_client[0],
2087 &arg->ca32_export.ex32_client[0],
2088 NFSCLNT_IDMAX) ||
2089 __copy_from_user(&karg->ca_export.ex_path[0],
2090 &arg->ca32_export.ex32_path[0],
2091 NFS_MAXPATHLEN) ||
2092 __get_user(karg->ca_export.ex_dev,
2093 &arg->ca32_export.ex32_dev) ||
2094 __get_user(karg->ca_export.ex_ino,
2095 &arg->ca32_export.ex32_ino) ||
2096 __get_user(karg->ca_export.ex_flags,
2097 &arg->ca32_export.ex32_flags) ||
2098 __get_user(karg->ca_export.ex_anon_uid,
2099 &arg->ca32_export.ex32_anon_uid) ||
2100 __get_user(karg->ca_export.ex_anon_gid,
2101 &arg->ca32_export.ex32_anon_gid))
2102 return -EFAULT;
2103 SET_UID(karg->ca_export.ex_anon_uid, karg->ca_export.ex_anon_uid);
2104 SET_GID(karg->ca_export.ex_anon_gid, karg->ca_export.ex_anon_gid);
2106 return 0;
2109 static int compat_nfs_getfd_trans(struct nfsctl_arg *karg,
2110 struct compat_nfsctl_arg __user *arg)
2112 if (!access_ok(VERIFY_READ, &arg->ca32_getfd,
2113 sizeof(arg->ca32_getfd)) ||
2114 get_user(karg->ca_version, &arg->ca32_version) ||
2115 __copy_from_user(&karg->ca_getfd.gd_addr,
2116 &arg->ca32_getfd.gd32_addr,
2117 (sizeof(struct sockaddr))) ||
2118 __copy_from_user(&karg->ca_getfd.gd_path,
2119 &arg->ca32_getfd.gd32_path,
2120 (NFS_MAXPATHLEN+1)) ||
2121 __get_user(karg->ca_getfd.gd_version,
2122 &arg->ca32_getfd.gd32_version))
2123 return -EFAULT;
2125 return 0;
2128 static int compat_nfs_getfs_trans(struct nfsctl_arg *karg,
2129 struct compat_nfsctl_arg __user *arg)
2131 if (!access_ok(VERIFY_READ,&arg->ca32_getfs,sizeof(arg->ca32_getfs)) ||
2132 get_user(karg->ca_version, &arg->ca32_version) ||
2133 __copy_from_user(&karg->ca_getfs.gd_addr,
2134 &arg->ca32_getfs.gd32_addr,
2135 (sizeof(struct sockaddr))) ||
2136 __copy_from_user(&karg->ca_getfs.gd_path,
2137 &arg->ca32_getfs.gd32_path,
2138 (NFS_MAXPATHLEN+1)) ||
2139 __get_user(karg->ca_getfs.gd_maxlen,
2140 &arg->ca32_getfs.gd32_maxlen))
2141 return -EFAULT;
2143 return 0;
2146 /* This really doesn't need translations, we are only passing
2147 * back a union which contains opaque nfs file handle data.
2149 static int compat_nfs_getfh_res_trans(union nfsctl_res *kres,
2150 union compat_nfsctl_res __user *res)
2152 int err;
2154 err = copy_to_user(res, kres, sizeof(*res));
2156 return (err) ? -EFAULT : 0;
2159 asmlinkage long compat_sys_nfsservctl(int cmd,
2160 struct compat_nfsctl_arg __user *arg,
2161 union compat_nfsctl_res __user *res)
2163 struct nfsctl_arg *karg;
2164 union nfsctl_res *kres;
2165 mm_segment_t oldfs;
2166 int err;
2168 karg = kmalloc(sizeof(*karg), GFP_USER);
2169 kres = kmalloc(sizeof(*kres), GFP_USER);
2170 if(!karg || !kres) {
2171 err = -ENOMEM;
2172 goto done;
2175 switch(cmd) {
2176 case NFSCTL_SVC:
2177 err = compat_nfs_svc_trans(karg, arg);
2178 break;
2180 case NFSCTL_ADDCLIENT:
2181 err = compat_nfs_clnt_trans(karg, arg);
2182 break;
2184 case NFSCTL_DELCLIENT:
2185 err = compat_nfs_clnt_trans(karg, arg);
2186 break;
2188 case NFSCTL_EXPORT:
2189 case NFSCTL_UNEXPORT:
2190 err = compat_nfs_exp_trans(karg, arg);
2191 break;
2193 case NFSCTL_GETFD:
2194 err = compat_nfs_getfd_trans(karg, arg);
2195 break;
2197 case NFSCTL_GETFS:
2198 err = compat_nfs_getfs_trans(karg, arg);
2199 break;
2201 default:
2202 err = -EINVAL;
2203 break;
2206 if (err)
2207 goto done;
2209 oldfs = get_fs();
2210 set_fs(KERNEL_DS);
2211 /* The __user pointer casts are valid because of the set_fs() */
2212 err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres);
2213 set_fs(oldfs);
2215 if (err)
2216 goto done;
2218 if((cmd == NFSCTL_GETFD) ||
2219 (cmd == NFSCTL_GETFS))
2220 err = compat_nfs_getfh_res_trans(kres, res);
2222 done:
2223 kfree(karg);
2224 kfree(kres);
2225 return err;
2227 #else /* !NFSD */
2228 long asmlinkage compat_sys_nfsservctl(int cmd, void *notused, void *notused2)
2230 return sys_ni_syscall();
2232 #endif