]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - fs/compat.c
netfilter: nft_ct: add helper set support
[mirror_ubuntu-artful-kernel.git] / fs / compat.c
1 /*
2 * linux/fs/compat.c
3 *
4 * Kernel compatibililty routines for e.g. 32 bit syscall support
5 * on 64 bit kernels.
6 *
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@ucw.cz)
12 *
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.
16 */
17
18 #include <linux/stddef.h>
19 #include <linux/kernel.h>
20 #include <linux/linkage.h>
21 #include <linux/compat.h>
22 #include <linux/errno.h>
23 #include <linux/time.h>
24 #include <linux/cred.h>
25 #include <linux/fs.h>
26 #include <linux/fcntl.h>
27 #include <linux/namei.h>
28 #include <linux/file.h>
29 #include <linux/fdtable.h>
30 #include <linux/vfs.h>
31 #include <linux/ioctl.h>
32 #include <linux/init.h>
33 #include <linux/ncp_mount.h>
34 #include <linux/nfs4_mount.h>
35 #include <linux/syscalls.h>
36 #include <linux/ctype.h>
37 #include <linux/dirent.h>
38 #include <linux/fsnotify.h>
39 #include <linux/highuid.h>
40 #include <linux/personality.h>
41 #include <linux/rwsem.h>
42 #include <linux/tsacct_kern.h>
43 #include <linux/security.h>
44 #include <linux/highmem.h>
45 #include <linux/signal.h>
46 #include <linux/poll.h>
47 #include <linux/mm.h>
48 #include <linux/fs_struct.h>
49 #include <linux/slab.h>
50 #include <linux/pagemap.h>
51 #include <linux/aio.h>
52
53 #include <linux/uaccess.h>
54 #include <asm/mmu_context.h>
55 #include <asm/ioctls.h>
56 #include "internal.h"
57
58 /*
59 * Not all architectures have sys_utime, so implement this in terms
60 * of sys_utimes.
61 */
62 COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename,
63 struct compat_utimbuf __user *, t)
64 {
65 struct timespec tv[2];
66
67 if (t) {
68 if (get_user(tv[0].tv_sec, &t->actime) ||
69 get_user(tv[1].tv_sec, &t->modtime))
70 return -EFAULT;
71 tv[0].tv_nsec = 0;
72 tv[1].tv_nsec = 0;
73 }
74 return do_utimes(AT_FDCWD, filename, t ? tv : NULL, 0);
75 }
76
77 COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct compat_timespec __user *, t, int, flags)
78 {
79 struct timespec tv[2];
80
81 if (t) {
82 if (compat_get_timespec(&tv[0], &t[0]) ||
83 compat_get_timespec(&tv[1], &t[1]))
84 return -EFAULT;
85
86 if (tv[0].tv_nsec == UTIME_OMIT && tv[1].tv_nsec == UTIME_OMIT)
87 return 0;
88 }
89 return do_utimes(dfd, filename, t ? tv : NULL, flags);
90 }
91
92 COMPAT_SYSCALL_DEFINE3(futimesat, unsigned int, dfd, const char __user *, filename, struct compat_timeval __user *, t)
93 {
94 struct timespec tv[2];
95
96 if (t) {
97 if (get_user(tv[0].tv_sec, &t[0].tv_sec) ||
98 get_user(tv[0].tv_nsec, &t[0].tv_usec) ||
99 get_user(tv[1].tv_sec, &t[1].tv_sec) ||
100 get_user(tv[1].tv_nsec, &t[1].tv_usec))
101 return -EFAULT;
102 if (tv[0].tv_nsec >= 1000000 || tv[0].tv_nsec < 0 ||
103 tv[1].tv_nsec >= 1000000 || tv[1].tv_nsec < 0)
104 return -EINVAL;
105 tv[0].tv_nsec *= 1000;
106 tv[1].tv_nsec *= 1000;
107 }
108 return do_utimes(dfd, filename, t ? tv : NULL, 0);
109 }
110
111 COMPAT_SYSCALL_DEFINE2(utimes, const char __user *, filename, struct compat_timeval __user *, t)
112 {
113 return compat_sys_futimesat(AT_FDCWD, filename, t);
114 }
115
116 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
117 {
118 struct compat_stat tmp;
119
120 if (!old_valid_dev(stat->dev) || !old_valid_dev(stat->rdev))
121 return -EOVERFLOW;
122
123 memset(&tmp, 0, sizeof(tmp));
124 tmp.st_dev = old_encode_dev(stat->dev);
125 tmp.st_ino = stat->ino;
126 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
127 return -EOVERFLOW;
128 tmp.st_mode = stat->mode;
129 tmp.st_nlink = stat->nlink;
130 if (tmp.st_nlink != stat->nlink)
131 return -EOVERFLOW;
132 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
133 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
134 tmp.st_rdev = old_encode_dev(stat->rdev);
135 if ((u64) stat->size > MAX_NON_LFS)
136 return -EOVERFLOW;
137 tmp.st_size = stat->size;
138 tmp.st_atime = stat->atime.tv_sec;
139 tmp.st_atime_nsec = stat->atime.tv_nsec;
140 tmp.st_mtime = stat->mtime.tv_sec;
141 tmp.st_mtime_nsec = stat->mtime.tv_nsec;
142 tmp.st_ctime = stat->ctime.tv_sec;
143 tmp.st_ctime_nsec = stat->ctime.tv_nsec;
144 tmp.st_blocks = stat->blocks;
145 tmp.st_blksize = stat->blksize;
146 return copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0;
147 }
148
149 COMPAT_SYSCALL_DEFINE2(newstat, const char __user *, filename,
150 struct compat_stat __user *, statbuf)
151 {
152 struct kstat stat;
153 int error;
154
155 error = vfs_stat(filename, &stat);
156 if (error)
157 return error;
158 return cp_compat_stat(&stat, statbuf);
159 }
160
161 COMPAT_SYSCALL_DEFINE2(newlstat, const char __user *, filename,
162 struct compat_stat __user *, statbuf)
163 {
164 struct kstat stat;
165 int error;
166
167 error = vfs_lstat(filename, &stat);
168 if (error)
169 return error;
170 return cp_compat_stat(&stat, statbuf);
171 }
172
173 #ifndef __ARCH_WANT_STAT64
174 COMPAT_SYSCALL_DEFINE4(newfstatat, unsigned int, dfd,
175 const char __user *, filename,
176 struct compat_stat __user *, statbuf, int, flag)
177 {
178 struct kstat stat;
179 int error;
180
181 error = vfs_fstatat(dfd, filename, &stat, flag);
182 if (error)
183 return error;
184 return cp_compat_stat(&stat, statbuf);
185 }
186 #endif
187
188 COMPAT_SYSCALL_DEFINE2(newfstat, unsigned int, fd,
189 struct compat_stat __user *, statbuf)
190 {
191 struct kstat stat;
192 int error = vfs_fstat(fd, &stat);
193
194 if (!error)
195 error = cp_compat_stat(&stat, statbuf);
196 return error;
197 }
198
199 static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf)
200 {
201
202 if (sizeof ubuf->f_blocks == 4) {
203 if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail |
204 kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
205 return -EOVERFLOW;
206 /* f_files and f_ffree may be -1; it's okay
207 * to stuff that into 32 bits */
208 if (kbuf->f_files != 0xffffffffffffffffULL
209 && (kbuf->f_files & 0xffffffff00000000ULL))
210 return -EOVERFLOW;
211 if (kbuf->f_ffree != 0xffffffffffffffffULL
212 && (kbuf->f_ffree & 0xffffffff00000000ULL))
213 return -EOVERFLOW;
214 }
215 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
216 __put_user(kbuf->f_type, &ubuf->f_type) ||
217 __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
218 __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
219 __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
220 __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
221 __put_user(kbuf->f_files, &ubuf->f_files) ||
222 __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
223 __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
224 __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
225 __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
226 __put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
227 __put_user(kbuf->f_flags, &ubuf->f_flags) ||
228 __clear_user(ubuf->f_spare, sizeof(ubuf->f_spare)))
229 return -EFAULT;
230 return 0;
231 }
232
233 /*
234 * The following statfs calls are copies of code from fs/statfs.c and
235 * should be checked against those from time to time
236 */
237 COMPAT_SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct compat_statfs __user *, buf)
238 {
239 struct kstatfs tmp;
240 int error = user_statfs(pathname, &tmp);
241 if (!error)
242 error = put_compat_statfs(buf, &tmp);
243 return error;
244 }
245
246 COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *, buf)
247 {
248 struct kstatfs tmp;
249 int error = fd_statfs(fd, &tmp);
250 if (!error)
251 error = put_compat_statfs(buf, &tmp);
252 return error;
253 }
254
255 static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
256 {
257 if (sizeof(ubuf->f_bsize) == 4) {
258 if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen |
259 kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL)
260 return -EOVERFLOW;
261 /* f_files and f_ffree may be -1; it's okay
262 * to stuff that into 32 bits */
263 if (kbuf->f_files != 0xffffffffffffffffULL
264 && (kbuf->f_files & 0xffffffff00000000ULL))
265 return -EOVERFLOW;
266 if (kbuf->f_ffree != 0xffffffffffffffffULL
267 && (kbuf->f_ffree & 0xffffffff00000000ULL))
268 return -EOVERFLOW;
269 }
270 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
271 __put_user(kbuf->f_type, &ubuf->f_type) ||
272 __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
273 __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
274 __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
275 __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
276 __put_user(kbuf->f_files, &ubuf->f_files) ||
277 __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
278 __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
279 __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
280 __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
281 __put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
282 __put_user(kbuf->f_flags, &ubuf->f_flags) ||
283 __clear_user(ubuf->f_spare, sizeof(ubuf->f_spare)))
284 return -EFAULT;
285 return 0;
286 }
287
288 COMPAT_SYSCALL_DEFINE3(statfs64, const char __user *, pathname, compat_size_t, sz, struct compat_statfs64 __user *, buf)
289 {
290 struct kstatfs tmp;
291 int error;
292
293 if (sz != sizeof(*buf))
294 return -EINVAL;
295
296 error = user_statfs(pathname, &tmp);
297 if (!error)
298 error = put_compat_statfs64(buf, &tmp);
299 return error;
300 }
301
302 COMPAT_SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, compat_size_t, sz, struct compat_statfs64 __user *, buf)
303 {
304 struct kstatfs tmp;
305 int error;
306
307 if (sz != sizeof(*buf))
308 return -EINVAL;
309
310 error = fd_statfs(fd, &tmp);
311 if (!error)
312 error = put_compat_statfs64(buf, &tmp);
313 return error;
314 }
315
316 /*
317 * This is a copy of sys_ustat, just dealing with a structure layout.
318 * Given how simple this syscall is that apporach is more maintainable
319 * than the various conversion hacks.
320 */
321 COMPAT_SYSCALL_DEFINE2(ustat, unsigned, dev, struct compat_ustat __user *, u)
322 {
323 struct compat_ustat tmp;
324 struct kstatfs sbuf;
325 int err = vfs_ustat(new_decode_dev(dev), &sbuf);
326 if (err)
327 return err;
328
329 memset(&tmp, 0, sizeof(struct compat_ustat));
330 tmp.f_tfree = sbuf.f_bfree;
331 tmp.f_tinode = sbuf.f_ffree;
332 if (copy_to_user(u, &tmp, sizeof(struct compat_ustat)))
333 return -EFAULT;
334 return 0;
335 }
336
337 static int get_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
338 {
339 if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
340 __get_user(kfl->l_type, &ufl->l_type) ||
341 __get_user(kfl->l_whence, &ufl->l_whence) ||
342 __get_user(kfl->l_start, &ufl->l_start) ||
343 __get_user(kfl->l_len, &ufl->l_len) ||
344 __get_user(kfl->l_pid, &ufl->l_pid))
345 return -EFAULT;
346 return 0;
347 }
348
349 static int put_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
350 {
351 if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
352 __put_user(kfl->l_type, &ufl->l_type) ||
353 __put_user(kfl->l_whence, &ufl->l_whence) ||
354 __put_user(kfl->l_start, &ufl->l_start) ||
355 __put_user(kfl->l_len, &ufl->l_len) ||
356 __put_user(kfl->l_pid, &ufl->l_pid))
357 return -EFAULT;
358 return 0;
359 }
360
361 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
362 static int get_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl)
363 {
364 if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
365 __get_user(kfl->l_type, &ufl->l_type) ||
366 __get_user(kfl->l_whence, &ufl->l_whence) ||
367 __get_user(kfl->l_start, &ufl->l_start) ||
368 __get_user(kfl->l_len, &ufl->l_len) ||
369 __get_user(kfl->l_pid, &ufl->l_pid))
370 return -EFAULT;
371 return 0;
372 }
373 #endif
374
375 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
376 static int put_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl)
377 {
378 if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
379 __put_user(kfl->l_type, &ufl->l_type) ||
380 __put_user(kfl->l_whence, &ufl->l_whence) ||
381 __put_user(kfl->l_start, &ufl->l_start) ||
382 __put_user(kfl->l_len, &ufl->l_len) ||
383 __put_user(kfl->l_pid, &ufl->l_pid))
384 return -EFAULT;
385 return 0;
386 }
387 #endif
388
389 static unsigned int
390 convert_fcntl_cmd(unsigned int cmd)
391 {
392 switch (cmd) {
393 case F_GETLK64:
394 return F_GETLK;
395 case F_SETLK64:
396 return F_SETLK;
397 case F_SETLKW64:
398 return F_SETLKW;
399 }
400
401 return cmd;
402 }
403
404 COMPAT_SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
405 compat_ulong_t, arg)
406 {
407 mm_segment_t old_fs;
408 struct flock f;
409 long ret;
410 unsigned int conv_cmd;
411
412 switch (cmd) {
413 case F_GETLK:
414 case F_SETLK:
415 case F_SETLKW:
416 ret = get_compat_flock(&f, compat_ptr(arg));
417 if (ret != 0)
418 break;
419 old_fs = get_fs();
420 set_fs(KERNEL_DS);
421 ret = sys_fcntl(fd, cmd, (unsigned long)&f);
422 set_fs(old_fs);
423 if (cmd == F_GETLK && ret == 0) {
424 /* GETLK was successful and we need to return the data...
425 * but it needs to fit in the compat structure.
426 * l_start shouldn't be too big, unless the original
427 * start + end is greater than COMPAT_OFF_T_MAX, in which
428 * case the app was asking for trouble, so we return
429 * -EOVERFLOW in that case.
430 * l_len could be too big, in which case we just truncate it,
431 * and only allow the app to see that part of the conflicting
432 * lock that might make sense to it anyway
433 */
434
435 if (f.l_start > COMPAT_OFF_T_MAX)
436 ret = -EOVERFLOW;
437 if (f.l_len > COMPAT_OFF_T_MAX)
438 f.l_len = COMPAT_OFF_T_MAX;
439 if (ret == 0)
440 ret = put_compat_flock(&f, compat_ptr(arg));
441 }
442 break;
443
444 case F_GETLK64:
445 case F_SETLK64:
446 case F_SETLKW64:
447 case F_OFD_GETLK:
448 case F_OFD_SETLK:
449 case F_OFD_SETLKW:
450 ret = get_compat_flock64(&f, compat_ptr(arg));
451 if (ret != 0)
452 break;
453 old_fs = get_fs();
454 set_fs(KERNEL_DS);
455 conv_cmd = convert_fcntl_cmd(cmd);
456 ret = sys_fcntl(fd, conv_cmd, (unsigned long)&f);
457 set_fs(old_fs);
458 if ((conv_cmd == F_GETLK || conv_cmd == F_OFD_GETLK) && ret == 0) {
459 /* need to return lock information - see above for commentary */
460 if (f.l_start > COMPAT_LOFF_T_MAX)
461 ret = -EOVERFLOW;
462 if (f.l_len > COMPAT_LOFF_T_MAX)
463 f.l_len = COMPAT_LOFF_T_MAX;
464 if (ret == 0)
465 ret = put_compat_flock64(&f, compat_ptr(arg));
466 }
467 break;
468
469 default:
470 ret = sys_fcntl(fd, cmd, arg);
471 break;
472 }
473 return ret;
474 }
475
476 COMPAT_SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd,
477 compat_ulong_t, arg)
478 {
479 switch (cmd) {
480 case F_GETLK64:
481 case F_SETLK64:
482 case F_SETLKW64:
483 case F_OFD_GETLK:
484 case F_OFD_SETLK:
485 case F_OFD_SETLKW:
486 return -EINVAL;
487 }
488 return compat_sys_fcntl64(fd, cmd, arg);
489 }
490
491 /* A write operation does a read from user space and vice versa */
492 #define vrfy_dir(type) ((type) == READ ? VERIFY_WRITE : VERIFY_READ)
493
494 ssize_t compat_rw_copy_check_uvector(int type,
495 const struct compat_iovec __user *uvector, unsigned long nr_segs,
496 unsigned long fast_segs, struct iovec *fast_pointer,
497 struct iovec **ret_pointer)
498 {
499 compat_ssize_t tot_len;
500 struct iovec *iov = *ret_pointer = fast_pointer;
501 ssize_t ret = 0;
502 int seg;
503
504 /*
505 * SuS says "The readv() function *may* fail if the iovcnt argument
506 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
507 * traditionally returned zero for zero segments, so...
508 */
509 if (nr_segs == 0)
510 goto out;
511
512 ret = -EINVAL;
513 if (nr_segs > UIO_MAXIOV)
514 goto out;
515 if (nr_segs > fast_segs) {
516 ret = -ENOMEM;
517 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
518 if (iov == NULL)
519 goto out;
520 }
521 *ret_pointer = iov;
522
523 ret = -EFAULT;
524 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
525 goto out;
526
527 /*
528 * Single unix specification:
529 * We should -EINVAL if an element length is not >= 0 and fitting an
530 * ssize_t.
531 *
532 * In Linux, the total length is limited to MAX_RW_COUNT, there is
533 * no overflow possibility.
534 */
535 tot_len = 0;
536 ret = -EINVAL;
537 for (seg = 0; seg < nr_segs; seg++) {
538 compat_uptr_t buf;
539 compat_ssize_t len;
540
541 if (__get_user(len, &uvector->iov_len) ||
542 __get_user(buf, &uvector->iov_base)) {
543 ret = -EFAULT;
544 goto out;
545 }
546 if (len < 0) /* size_t not fitting in compat_ssize_t .. */
547 goto out;
548 if (type >= 0 &&
549 !access_ok(vrfy_dir(type), compat_ptr(buf), len)) {
550 ret = -EFAULT;
551 goto out;
552 }
553 if (len > MAX_RW_COUNT - tot_len)
554 len = MAX_RW_COUNT - tot_len;
555 tot_len += len;
556 iov->iov_base = compat_ptr(buf);
557 iov->iov_len = (compat_size_t) len;
558 uvector++;
559 iov++;
560 }
561 ret = tot_len;
562
563 out:
564 return ret;
565 }
566
567 struct compat_ncp_mount_data {
568 compat_int_t version;
569 compat_uint_t ncp_fd;
570 __compat_uid_t mounted_uid;
571 compat_pid_t wdog_pid;
572 unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
573 compat_uint_t time_out;
574 compat_uint_t retry_count;
575 compat_uint_t flags;
576 __compat_uid_t uid;
577 __compat_gid_t gid;
578 compat_mode_t file_mode;
579 compat_mode_t dir_mode;
580 };
581
582 struct compat_ncp_mount_data_v4 {
583 compat_int_t version;
584 compat_ulong_t flags;
585 compat_ulong_t mounted_uid;
586 compat_long_t wdog_pid;
587 compat_uint_t ncp_fd;
588 compat_uint_t time_out;
589 compat_uint_t retry_count;
590 compat_ulong_t uid;
591 compat_ulong_t gid;
592 compat_ulong_t file_mode;
593 compat_ulong_t dir_mode;
594 };
595
596 static void *do_ncp_super_data_conv(void *raw_data)
597 {
598 int version = *(unsigned int *)raw_data;
599
600 if (version == 3) {
601 struct compat_ncp_mount_data *c_n = raw_data;
602 struct ncp_mount_data *n = raw_data;
603
604 n->dir_mode = c_n->dir_mode;
605 n->file_mode = c_n->file_mode;
606 n->gid = c_n->gid;
607 n->uid = c_n->uid;
608 memmove (n->mounted_vol, c_n->mounted_vol, (sizeof (c_n->mounted_vol) + 3 * sizeof (unsigned int)));
609 n->wdog_pid = c_n->wdog_pid;
610 n->mounted_uid = c_n->mounted_uid;
611 } else if (version == 4) {
612 struct compat_ncp_mount_data_v4 *c_n = raw_data;
613 struct ncp_mount_data_v4 *n = raw_data;
614
615 n->dir_mode = c_n->dir_mode;
616 n->file_mode = c_n->file_mode;
617 n->gid = c_n->gid;
618 n->uid = c_n->uid;
619 n->retry_count = c_n->retry_count;
620 n->time_out = c_n->time_out;
621 n->ncp_fd = c_n->ncp_fd;
622 n->wdog_pid = c_n->wdog_pid;
623 n->mounted_uid = c_n->mounted_uid;
624 n->flags = c_n->flags;
625 } else if (version != 5) {
626 return NULL;
627 }
628
629 return raw_data;
630 }
631
632
633 struct compat_nfs_string {
634 compat_uint_t len;
635 compat_uptr_t data;
636 };
637
638 static inline void compat_nfs_string(struct nfs_string *dst,
639 struct compat_nfs_string *src)
640 {
641 dst->data = compat_ptr(src->data);
642 dst->len = src->len;
643 }
644
645 struct compat_nfs4_mount_data_v1 {
646 compat_int_t version;
647 compat_int_t flags;
648 compat_int_t rsize;
649 compat_int_t wsize;
650 compat_int_t timeo;
651 compat_int_t retrans;
652 compat_int_t acregmin;
653 compat_int_t acregmax;
654 compat_int_t acdirmin;
655 compat_int_t acdirmax;
656 struct compat_nfs_string client_addr;
657 struct compat_nfs_string mnt_path;
658 struct compat_nfs_string hostname;
659 compat_uint_t host_addrlen;
660 compat_uptr_t host_addr;
661 compat_int_t proto;
662 compat_int_t auth_flavourlen;
663 compat_uptr_t auth_flavours;
664 };
665
666 static int do_nfs4_super_data_conv(void *raw_data)
667 {
668 int version = *(compat_uint_t *) raw_data;
669
670 if (version == 1) {
671 struct compat_nfs4_mount_data_v1 *raw = raw_data;
672 struct nfs4_mount_data *real = raw_data;
673
674 /* copy the fields backwards */
675 real->auth_flavours = compat_ptr(raw->auth_flavours);
676 real->auth_flavourlen = raw->auth_flavourlen;
677 real->proto = raw->proto;
678 real->host_addr = compat_ptr(raw->host_addr);
679 real->host_addrlen = raw->host_addrlen;
680 compat_nfs_string(&real->hostname, &raw->hostname);
681 compat_nfs_string(&real->mnt_path, &raw->mnt_path);
682 compat_nfs_string(&real->client_addr, &raw->client_addr);
683 real->acdirmax = raw->acdirmax;
684 real->acdirmin = raw->acdirmin;
685 real->acregmax = raw->acregmax;
686 real->acregmin = raw->acregmin;
687 real->retrans = raw->retrans;
688 real->timeo = raw->timeo;
689 real->wsize = raw->wsize;
690 real->rsize = raw->rsize;
691 real->flags = raw->flags;
692 real->version = raw->version;
693 }
694
695 return 0;
696 }
697
698 #define NCPFS_NAME "ncpfs"
699 #define NFS4_NAME "nfs4"
700
701 COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
702 const char __user *, dir_name,
703 const char __user *, type, compat_ulong_t, flags,
704 const void __user *, data)
705 {
706 char *kernel_type;
707 void *options;
708 char *kernel_dev;
709 int retval;
710
711 kernel_type = copy_mount_string(type);
712 retval = PTR_ERR(kernel_type);
713 if (IS_ERR(kernel_type))
714 goto out;
715
716 kernel_dev = copy_mount_string(dev_name);
717 retval = PTR_ERR(kernel_dev);
718 if (IS_ERR(kernel_dev))
719 goto out1;
720
721 options = copy_mount_options(data);
722 retval = PTR_ERR(options);
723 if (IS_ERR(options))
724 goto out2;
725
726 if (kernel_type && options) {
727 if (!strcmp(kernel_type, NCPFS_NAME)) {
728 do_ncp_super_data_conv(options);
729 } else if (!strcmp(kernel_type, NFS4_NAME)) {
730 retval = -EINVAL;
731 if (do_nfs4_super_data_conv(options))
732 goto out3;
733 }
734 }
735
736 retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
737
738 out3:
739 kfree(options);
740 out2:
741 kfree(kernel_dev);
742 out1:
743 kfree(kernel_type);
744 out:
745 return retval;
746 }
747
748 struct compat_old_linux_dirent {
749 compat_ulong_t d_ino;
750 compat_ulong_t d_offset;
751 unsigned short d_namlen;
752 char d_name[1];
753 };
754
755 struct compat_readdir_callback {
756 struct dir_context ctx;
757 struct compat_old_linux_dirent __user *dirent;
758 int result;
759 };
760
761 static int compat_fillonedir(struct dir_context *ctx, const char *name,
762 int namlen, loff_t offset, u64 ino,
763 unsigned int d_type)
764 {
765 struct compat_readdir_callback *buf =
766 container_of(ctx, struct compat_readdir_callback, ctx);
767 struct compat_old_linux_dirent __user *dirent;
768 compat_ulong_t d_ino;
769
770 if (buf->result)
771 return -EINVAL;
772 d_ino = ino;
773 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) {
774 buf->result = -EOVERFLOW;
775 return -EOVERFLOW;
776 }
777 buf->result++;
778 dirent = buf->dirent;
779 if (!access_ok(VERIFY_WRITE, dirent,
780 (unsigned long)(dirent->d_name + namlen + 1) -
781 (unsigned long)dirent))
782 goto efault;
783 if ( __put_user(d_ino, &dirent->d_ino) ||
784 __put_user(offset, &dirent->d_offset) ||
785 __put_user(namlen, &dirent->d_namlen) ||
786 __copy_to_user(dirent->d_name, name, namlen) ||
787 __put_user(0, dirent->d_name + namlen))
788 goto efault;
789 return 0;
790 efault:
791 buf->result = -EFAULT;
792 return -EFAULT;
793 }
794
795 COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
796 struct compat_old_linux_dirent __user *, dirent, unsigned int, count)
797 {
798 int error;
799 struct fd f = fdget_pos(fd);
800 struct compat_readdir_callback buf = {
801 .ctx.actor = compat_fillonedir,
802 .dirent = dirent
803 };
804
805 if (!f.file)
806 return -EBADF;
807
808 error = iterate_dir(f.file, &buf.ctx);
809 if (buf.result)
810 error = buf.result;
811
812 fdput_pos(f);
813 return error;
814 }
815
816 struct compat_linux_dirent {
817 compat_ulong_t d_ino;
818 compat_ulong_t d_off;
819 unsigned short d_reclen;
820 char d_name[1];
821 };
822
823 struct compat_getdents_callback {
824 struct dir_context ctx;
825 struct compat_linux_dirent __user *current_dir;
826 struct compat_linux_dirent __user *previous;
827 int count;
828 int error;
829 };
830
831 static int compat_filldir(struct dir_context *ctx, const char *name, int namlen,
832 loff_t offset, u64 ino, unsigned int d_type)
833 {
834 struct compat_linux_dirent __user * dirent;
835 struct compat_getdents_callback *buf =
836 container_of(ctx, struct compat_getdents_callback, ctx);
837 compat_ulong_t d_ino;
838 int reclen = ALIGN(offsetof(struct compat_linux_dirent, d_name) +
839 namlen + 2, sizeof(compat_long_t));
840
841 buf->error = -EINVAL; /* only used if we fail.. */
842 if (reclen > buf->count)
843 return -EINVAL;
844 d_ino = ino;
845 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) {
846 buf->error = -EOVERFLOW;
847 return -EOVERFLOW;
848 }
849 dirent = buf->previous;
850 if (dirent) {
851 if (signal_pending(current))
852 return -EINTR;
853 if (__put_user(offset, &dirent->d_off))
854 goto efault;
855 }
856 dirent = buf->current_dir;
857 if (__put_user(d_ino, &dirent->d_ino))
858 goto efault;
859 if (__put_user(reclen, &dirent->d_reclen))
860 goto efault;
861 if (copy_to_user(dirent->d_name, name, namlen))
862 goto efault;
863 if (__put_user(0, dirent->d_name + namlen))
864 goto efault;
865 if (__put_user(d_type, (char __user *) dirent + reclen - 1))
866 goto efault;
867 buf->previous = dirent;
868 dirent = (void __user *)dirent + reclen;
869 buf->current_dir = dirent;
870 buf->count -= reclen;
871 return 0;
872 efault:
873 buf->error = -EFAULT;
874 return -EFAULT;
875 }
876
877 COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
878 struct compat_linux_dirent __user *, dirent, unsigned int, count)
879 {
880 struct fd f;
881 struct compat_linux_dirent __user * lastdirent;
882 struct compat_getdents_callback buf = {
883 .ctx.actor = compat_filldir,
884 .current_dir = dirent,
885 .count = count
886 };
887 int error;
888
889 if (!access_ok(VERIFY_WRITE, dirent, count))
890 return -EFAULT;
891
892 f = fdget_pos(fd);
893 if (!f.file)
894 return -EBADF;
895
896 error = iterate_dir(f.file, &buf.ctx);
897 if (error >= 0)
898 error = buf.error;
899 lastdirent = buf.previous;
900 if (lastdirent) {
901 if (put_user(buf.ctx.pos, &lastdirent->d_off))
902 error = -EFAULT;
903 else
904 error = count - buf.count;
905 }
906 fdput_pos(f);
907 return error;
908 }
909
910 #ifdef __ARCH_WANT_COMPAT_SYS_GETDENTS64
911
912 struct compat_getdents_callback64 {
913 struct dir_context ctx;
914 struct linux_dirent64 __user *current_dir;
915 struct linux_dirent64 __user *previous;
916 int count;
917 int error;
918 };
919
920 static int compat_filldir64(struct dir_context *ctx, const char *name,
921 int namlen, loff_t offset, u64 ino,
922 unsigned int d_type)
923 {
924 struct linux_dirent64 __user *dirent;
925 struct compat_getdents_callback64 *buf =
926 container_of(ctx, struct compat_getdents_callback64, ctx);
927 int reclen = ALIGN(offsetof(struct linux_dirent64, d_name) + namlen + 1,
928 sizeof(u64));
929 u64 off;
930
931 buf->error = -EINVAL; /* only used if we fail.. */
932 if (reclen > buf->count)
933 return -EINVAL;
934 dirent = buf->previous;
935
936 if (dirent) {
937 if (signal_pending(current))
938 return -EINTR;
939 if (__put_user_unaligned(offset, &dirent->d_off))
940 goto efault;
941 }
942 dirent = buf->current_dir;
943 if (__put_user_unaligned(ino, &dirent->d_ino))
944 goto efault;
945 off = 0;
946 if (__put_user_unaligned(off, &dirent->d_off))
947 goto efault;
948 if (__put_user(reclen, &dirent->d_reclen))
949 goto efault;
950 if (__put_user(d_type, &dirent->d_type))
951 goto efault;
952 if (copy_to_user(dirent->d_name, name, namlen))
953 goto efault;
954 if (__put_user(0, dirent->d_name + namlen))
955 goto efault;
956 buf->previous = dirent;
957 dirent = (void __user *)dirent + reclen;
958 buf->current_dir = dirent;
959 buf->count -= reclen;
960 return 0;
961 efault:
962 buf->error = -EFAULT;
963 return -EFAULT;
964 }
965
966 COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
967 struct linux_dirent64 __user *, dirent, unsigned int, count)
968 {
969 struct fd f;
970 struct linux_dirent64 __user * lastdirent;
971 struct compat_getdents_callback64 buf = {
972 .ctx.actor = compat_filldir64,
973 .current_dir = dirent,
974 .count = count
975 };
976 int error;
977
978 if (!access_ok(VERIFY_WRITE, dirent, count))
979 return -EFAULT;
980
981 f = fdget_pos(fd);
982 if (!f.file)
983 return -EBADF;
984
985 error = iterate_dir(f.file, &buf.ctx);
986 if (error >= 0)
987 error = buf.error;
988 lastdirent = buf.previous;
989 if (lastdirent) {
990 typeof(lastdirent->d_off) d_off = buf.ctx.pos;
991 if (__put_user_unaligned(d_off, &lastdirent->d_off))
992 error = -EFAULT;
993 else
994 error = count - buf.count;
995 }
996 fdput_pos(f);
997 return error;
998 }
999 #endif /* __ARCH_WANT_COMPAT_SYS_GETDENTS64 */
1000
1001 /*
1002 * Exactly like fs/open.c:sys_open(), except that it doesn't set the
1003 * O_LARGEFILE flag.
1004 */
1005 COMPAT_SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode)
1006 {
1007 return do_sys_open(AT_FDCWD, filename, flags, mode);
1008 }
1009
1010 /*
1011 * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
1012 * O_LARGEFILE flag.
1013 */
1014 COMPAT_SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, flags, umode_t, mode)
1015 {
1016 return do_sys_open(dfd, filename, flags, mode);
1017 }
1018
1019 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1020
1021 static int poll_select_copy_remaining(struct timespec *end_time, void __user *p,
1022 int timeval, int ret)
1023 {
1024 struct timespec ts;
1025
1026 if (!p)
1027 return ret;
1028
1029 if (current->personality & STICKY_TIMEOUTS)
1030 goto sticky;
1031
1032 /* No update for zero timeout */
1033 if (!end_time->tv_sec && !end_time->tv_nsec)
1034 return ret;
1035
1036 ktime_get_ts(&ts);
1037 ts = timespec_sub(*end_time, ts);
1038 if (ts.tv_sec < 0)
1039 ts.tv_sec = ts.tv_nsec = 0;
1040
1041 if (timeval) {
1042 struct compat_timeval rtv;
1043
1044 rtv.tv_sec = ts.tv_sec;
1045 rtv.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
1046
1047 if (!copy_to_user(p, &rtv, sizeof(rtv)))
1048 return ret;
1049 } else {
1050 struct compat_timespec rts;
1051
1052 rts.tv_sec = ts.tv_sec;
1053 rts.tv_nsec = ts.tv_nsec;
1054
1055 if (!copy_to_user(p, &rts, sizeof(rts)))
1056 return ret;
1057 }
1058 /*
1059 * If an application puts its timeval in read-only memory, we
1060 * don't want the Linux-specific update to the timeval to
1061 * cause a fault after the select has completed
1062 * successfully. However, because we're not updating the
1063 * timeval, we can't restart the system call.
1064 */
1065
1066 sticky:
1067 if (ret == -ERESTARTNOHAND)
1068 ret = -EINTR;
1069 return ret;
1070 }
1071
1072 /*
1073 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1074 * 64-bit unsigned longs.
1075 */
1076 static
1077 int compat_get_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
1078 unsigned long *fdset)
1079 {
1080 nr = DIV_ROUND_UP(nr, __COMPAT_NFDBITS);
1081 if (ufdset) {
1082 unsigned long odd;
1083
1084 if (!access_ok(VERIFY_WRITE, ufdset, nr*sizeof(compat_ulong_t)))
1085 return -EFAULT;
1086
1087 odd = nr & 1UL;
1088 nr &= ~1UL;
1089 while (nr) {
1090 unsigned long h, l;
1091 if (__get_user(l, ufdset) || __get_user(h, ufdset+1))
1092 return -EFAULT;
1093 ufdset += 2;
1094 *fdset++ = h << 32 | l;
1095 nr -= 2;
1096 }
1097 if (odd && __get_user(*fdset, ufdset))
1098 return -EFAULT;
1099 } else {
1100 /* Tricky, must clear full unsigned long in the
1101 * kernel fdset at the end, this makes sure that
1102 * actually happens.
1103 */
1104 memset(fdset, 0, ((nr + 1) & ~1)*sizeof(compat_ulong_t));
1105 }
1106 return 0;
1107 }
1108
1109 static
1110 int compat_set_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
1111 unsigned long *fdset)
1112 {
1113 unsigned long odd;
1114 nr = DIV_ROUND_UP(nr, __COMPAT_NFDBITS);
1115
1116 if (!ufdset)
1117 return 0;
1118
1119 odd = nr & 1UL;
1120 nr &= ~1UL;
1121 while (nr) {
1122 unsigned long h, l;
1123 l = *fdset++;
1124 h = l >> 32;
1125 if (__put_user(l, ufdset) || __put_user(h, ufdset+1))
1126 return -EFAULT;
1127 ufdset += 2;
1128 nr -= 2;
1129 }
1130 if (odd && __put_user(*fdset, ufdset))
1131 return -EFAULT;
1132 return 0;
1133 }
1134
1135
1136 /*
1137 * This is a virtual copy of sys_select from fs/select.c and probably
1138 * should be compared to it from time to time
1139 */
1140
1141 /*
1142 * We can actually return ERESTARTSYS instead of EINTR, but I'd
1143 * like to be certain this leads to no problems. So I return
1144 * EINTR just for safety.
1145 *
1146 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1147 * I'm trying ERESTARTNOHAND which restart only when you want to.
1148 */
1149 int compat_core_sys_select(int n, compat_ulong_t __user *inp,
1150 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1151 struct timespec *end_time)
1152 {
1153 fd_set_bits fds;
1154 void *bits;
1155 int size, max_fds, ret = -EINVAL;
1156 struct fdtable *fdt;
1157 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
1158
1159 if (n < 0)
1160 goto out_nofds;
1161
1162 /* max_fds can increase, so grab it once to avoid race */
1163 rcu_read_lock();
1164 fdt = files_fdtable(current->files);
1165 max_fds = fdt->max_fds;
1166 rcu_read_unlock();
1167 if (n > max_fds)
1168 n = max_fds;
1169
1170 /*
1171 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1172 * since we used fdset we need to allocate memory in units of
1173 * long-words.
1174 */
1175 size = FDS_BYTES(n);
1176 bits = stack_fds;
1177 if (size > sizeof(stack_fds) / 6) {
1178 bits = kmalloc(6 * size, GFP_KERNEL);
1179 ret = -ENOMEM;
1180 if (!bits)
1181 goto out_nofds;
1182 }
1183 fds.in = (unsigned long *) bits;
1184 fds.out = (unsigned long *) (bits + size);
1185 fds.ex = (unsigned long *) (bits + 2*size);
1186 fds.res_in = (unsigned long *) (bits + 3*size);
1187 fds.res_out = (unsigned long *) (bits + 4*size);
1188 fds.res_ex = (unsigned long *) (bits + 5*size);
1189
1190 if ((ret = compat_get_fd_set(n, inp, fds.in)) ||
1191 (ret = compat_get_fd_set(n, outp, fds.out)) ||
1192 (ret = compat_get_fd_set(n, exp, fds.ex)))
1193 goto out;
1194 zero_fd_set(n, fds.res_in);
1195 zero_fd_set(n, fds.res_out);
1196 zero_fd_set(n, fds.res_ex);
1197
1198 ret = do_select(n, &fds, end_time);
1199
1200 if (ret < 0)
1201 goto out;
1202 if (!ret) {
1203 ret = -ERESTARTNOHAND;
1204 if (signal_pending(current))
1205 goto out;
1206 ret = 0;
1207 }
1208
1209 if (compat_set_fd_set(n, inp, fds.res_in) ||
1210 compat_set_fd_set(n, outp, fds.res_out) ||
1211 compat_set_fd_set(n, exp, fds.res_ex))
1212 ret = -EFAULT;
1213 out:
1214 if (bits != stack_fds)
1215 kfree(bits);
1216 out_nofds:
1217 return ret;
1218 }
1219
1220 COMPAT_SYSCALL_DEFINE5(select, int, n, compat_ulong_t __user *, inp,
1221 compat_ulong_t __user *, outp, compat_ulong_t __user *, exp,
1222 struct compat_timeval __user *, tvp)
1223 {
1224 struct timespec end_time, *to = NULL;
1225 struct compat_timeval tv;
1226 int ret;
1227
1228 if (tvp) {
1229 if (copy_from_user(&tv, tvp, sizeof(tv)))
1230 return -EFAULT;
1231
1232 to = &end_time;
1233 if (poll_select_set_timeout(to,
1234 tv.tv_sec + (tv.tv_usec / USEC_PER_SEC),
1235 (tv.tv_usec % USEC_PER_SEC) * NSEC_PER_USEC))
1236 return -EINVAL;
1237 }
1238
1239 ret = compat_core_sys_select(n, inp, outp, exp, to);
1240 ret = poll_select_copy_remaining(&end_time, tvp, 1, ret);
1241
1242 return ret;
1243 }
1244
1245 struct compat_sel_arg_struct {
1246 compat_ulong_t n;
1247 compat_uptr_t inp;
1248 compat_uptr_t outp;
1249 compat_uptr_t exp;
1250 compat_uptr_t tvp;
1251 };
1252
1253 COMPAT_SYSCALL_DEFINE1(old_select, struct compat_sel_arg_struct __user *, arg)
1254 {
1255 struct compat_sel_arg_struct a;
1256
1257 if (copy_from_user(&a, arg, sizeof(a)))
1258 return -EFAULT;
1259 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
1260 compat_ptr(a.exp), compat_ptr(a.tvp));
1261 }
1262
1263 static long do_compat_pselect(int n, compat_ulong_t __user *inp,
1264 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1265 struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask,
1266 compat_size_t sigsetsize)
1267 {
1268 compat_sigset_t ss32;
1269 sigset_t ksigmask, sigsaved;
1270 struct compat_timespec ts;
1271 struct timespec end_time, *to = NULL;
1272 int ret;
1273
1274 if (tsp) {
1275 if (copy_from_user(&ts, tsp, sizeof(ts)))
1276 return -EFAULT;
1277
1278 to = &end_time;
1279 if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec))
1280 return -EINVAL;
1281 }
1282
1283 if (sigmask) {
1284 if (sigsetsize != sizeof(compat_sigset_t))
1285 return -EINVAL;
1286 if (copy_from_user(&ss32, sigmask, sizeof(ss32)))
1287 return -EFAULT;
1288 sigset_from_compat(&ksigmask, &ss32);
1289
1290 sigdelsetmask(&ksigmask, sigmask(SIGKILL)|sigmask(SIGSTOP));
1291 sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
1292 }
1293
1294 ret = compat_core_sys_select(n, inp, outp, exp, to);
1295 ret = poll_select_copy_remaining(&end_time, tsp, 0, ret);
1296
1297 if (ret == -ERESTARTNOHAND) {
1298 /*
1299 * Don't restore the signal mask yet. Let do_signal() deliver
1300 * the signal on the way back to userspace, before the signal
1301 * mask is restored.
1302 */
1303 if (sigmask) {
1304 memcpy(&current->saved_sigmask, &sigsaved,
1305 sizeof(sigsaved));
1306 set_restore_sigmask();
1307 }
1308 } else if (sigmask)
1309 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
1310
1311 return ret;
1312 }
1313
1314 COMPAT_SYSCALL_DEFINE6(pselect6, int, n, compat_ulong_t __user *, inp,
1315 compat_ulong_t __user *, outp, compat_ulong_t __user *, exp,
1316 struct compat_timespec __user *, tsp, void __user *, sig)
1317 {
1318 compat_size_t sigsetsize = 0;
1319 compat_uptr_t up = 0;
1320
1321 if (sig) {
1322 if (!access_ok(VERIFY_READ, sig,
1323 sizeof(compat_uptr_t)+sizeof(compat_size_t)) ||
1324 __get_user(up, (compat_uptr_t __user *)sig) ||
1325 __get_user(sigsetsize,
1326 (compat_size_t __user *)(sig+sizeof(up))))
1327 return -EFAULT;
1328 }
1329 return do_compat_pselect(n, inp, outp, exp, tsp, compat_ptr(up),
1330 sigsetsize);
1331 }
1332
1333 COMPAT_SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds,
1334 unsigned int, nfds, struct compat_timespec __user *, tsp,
1335 const compat_sigset_t __user *, sigmask, compat_size_t, sigsetsize)
1336 {
1337 compat_sigset_t ss32;
1338 sigset_t ksigmask, sigsaved;
1339 struct compat_timespec ts;
1340 struct timespec end_time, *to = NULL;
1341 int ret;
1342
1343 if (tsp) {
1344 if (copy_from_user(&ts, tsp, sizeof(ts)))
1345 return -EFAULT;
1346
1347 to = &end_time;
1348 if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec))
1349 return -EINVAL;
1350 }
1351
1352 if (sigmask) {
1353 if (sigsetsize != sizeof(compat_sigset_t))
1354 return -EINVAL;
1355 if (copy_from_user(&ss32, sigmask, sizeof(ss32)))
1356 return -EFAULT;
1357 sigset_from_compat(&ksigmask, &ss32);
1358
1359 sigdelsetmask(&ksigmask, sigmask(SIGKILL)|sigmask(SIGSTOP));
1360 sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
1361 }
1362
1363 ret = do_sys_poll(ufds, nfds, to);
1364
1365 /* We can restart this syscall, usually */
1366 if (ret == -EINTR) {
1367 /*
1368 * Don't restore the signal mask yet. Let do_signal() deliver
1369 * the signal on the way back to userspace, before the signal
1370 * mask is restored.
1371 */
1372 if (sigmask) {
1373 memcpy(&current->saved_sigmask, &sigsaved,
1374 sizeof(sigsaved));
1375 set_restore_sigmask();
1376 }
1377 ret = -ERESTARTNOHAND;
1378 } else if (sigmask)
1379 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
1380
1381 ret = poll_select_copy_remaining(&end_time, tsp, 0, ret);
1382
1383 return ret;
1384 }
1385
1386 #ifdef CONFIG_FHANDLE
1387 /*
1388 * Exactly like fs/open.c:sys_open_by_handle_at(), except that it
1389 * doesn't set the O_LARGEFILE flag.
1390 */
1391 COMPAT_SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
1392 struct file_handle __user *, handle, int, flags)
1393 {
1394 return do_handle_open(mountdirfd, handle, flags);
1395 }
1396 #endif