Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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@suse.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 | |
Milind Arun Choudhary | 022a169 | 2007-05-08 00:29:02 -0700 | [diff] [blame] | 18 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/linkage.h> |
| 20 | #include <linux/compat.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/time.h> |
| 23 | #include <linux/fs.h> |
| 24 | #include <linux/fcntl.h> |
| 25 | #include <linux/namei.h> |
| 26 | #include <linux/file.h> |
Al Viro | 9f3acc3 | 2008-04-24 07:44:08 -0400 | [diff] [blame] | 27 | #include <linux/fdtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/vfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/ioctl.h> |
| 30 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/smb.h> |
| 32 | #include <linux/smb_mount.h> |
| 33 | #include <linux/ncp_mount.h> |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 34 | #include <linux/nfs4_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 40 | #include <linux/fsnotify.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Jay Lan | 8f0ab51 | 2006-09-30 23:28:59 -0700 | [diff] [blame] | 47 | #include <linux/tsacct_kern.h> |
Christoph Hellwig | 6272e26 | 2007-05-08 00:29:21 -0700 | [diff] [blame] | 48 | #include <linux/security.h> |
Al Viro | a1f8e7f7 | 2006-10-19 16:08:53 -0400 | [diff] [blame] | 49 | #include <linux/highmem.h> |
Davide Libenzi | 6d18c92 | 2007-05-10 22:23:15 -0700 | [diff] [blame] | 50 | #include <linux/signal.h> |
Al Viro | bd01f84 | 2006-10-19 17:23:57 -0400 | [diff] [blame] | 51 | #include <linux/poll.h> |
David S. Miller | 4a805e8 | 2005-09-14 21:40:00 -0700 | [diff] [blame] | 52 | #include <linux/mm.h> |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 53 | #include <linux/eventpoll.h> |
Al Viro | 498052b | 2009-03-30 07:20:30 -0400 | [diff] [blame^] | 54 | #include <linux/fs_struct.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <asm/uaccess.h> |
| 57 | #include <asm/mmu_context.h> |
| 58 | #include <asm/ioctls.h> |
David Howells | 07f3f05 | 2006-09-30 20:52:18 +0200 | [diff] [blame] | 59 | #include "internal.h" |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 60 | |
Andi Kleen | bebfa10 | 2006-06-26 13:56:52 +0200 | [diff] [blame] | 61 | int compat_log = 1; |
| 62 | |
| 63 | int compat_printk(const char *fmt, ...) |
| 64 | { |
| 65 | va_list ap; |
| 66 | int ret; |
| 67 | if (!compat_log) |
| 68 | return 0; |
| 69 | va_start(ap, fmt); |
| 70 | ret = vprintk(fmt, ap); |
| 71 | va_end(ap); |
| 72 | return ret; |
| 73 | } |
| 74 | |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 75 | #include "read_write.h" |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /* |
| 78 | * Not all architectures have sys_utime, so implement this in terms |
| 79 | * of sys_utimes. |
| 80 | */ |
| 81 | asmlinkage long compat_sys_utime(char __user *filename, struct compat_utimbuf __user *t) |
| 82 | { |
Ulrich Drepper | 1c710c8 | 2007-05-08 00:33:25 -0700 | [diff] [blame] | 83 | struct timespec tv[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | if (t) { |
| 86 | if (get_user(tv[0].tv_sec, &t->actime) || |
| 87 | get_user(tv[1].tv_sec, &t->modtime)) |
| 88 | return -EFAULT; |
Ulrich Drepper | 1c710c8 | 2007-05-08 00:33:25 -0700 | [diff] [blame] | 89 | tv[0].tv_nsec = 0; |
| 90 | tv[1].tv_nsec = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
Ulrich Drepper | 1c710c8 | 2007-05-08 00:33:25 -0700 | [diff] [blame] | 92 | return do_utimes(AT_FDCWD, filename, t ? tv : NULL, 0); |
| 93 | } |
| 94 | |
| 95 | asmlinkage long compat_sys_utimensat(unsigned int dfd, char __user *filename, struct compat_timespec __user *t, int flags) |
| 96 | { |
| 97 | struct timespec tv[2]; |
| 98 | |
| 99 | if (t) { |
| 100 | if (get_compat_timespec(&tv[0], &t[0]) || |
| 101 | get_compat_timespec(&tv[1], &t[1])) |
| 102 | return -EFAULT; |
| 103 | |
| 104 | if ((tv[0].tv_nsec == UTIME_OMIT || tv[0].tv_nsec == UTIME_NOW) |
| 105 | && tv[0].tv_sec != 0) |
| 106 | return -EINVAL; |
| 107 | if ((tv[1].tv_nsec == UTIME_OMIT || tv[1].tv_nsec == UTIME_NOW) |
| 108 | && tv[1].tv_sec != 0) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | if (tv[0].tv_nsec == UTIME_OMIT && tv[1].tv_nsec == UTIME_OMIT) |
| 112 | return 0; |
| 113 | } |
| 114 | return do_utimes(dfd, filename, t ? tv : NULL, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Stephen Rothwell | 9ad11ab | 2006-02-02 16:11:51 +1100 | [diff] [blame] | 117 | asmlinkage long compat_sys_futimesat(unsigned int dfd, char __user *filename, struct compat_timeval __user *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Ulrich Drepper | 1c710c8 | 2007-05-08 00:33:25 -0700 | [diff] [blame] | 119 | struct timespec tv[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Stephen Rothwell | 9ad11ab | 2006-02-02 16:11:51 +1100 | [diff] [blame] | 121 | if (t) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | if (get_user(tv[0].tv_sec, &t[0].tv_sec) || |
Ulrich Drepper | 1c710c8 | 2007-05-08 00:33:25 -0700 | [diff] [blame] | 123 | get_user(tv[0].tv_nsec, &t[0].tv_usec) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | get_user(tv[1].tv_sec, &t[1].tv_sec) || |
Ulrich Drepper | 1c710c8 | 2007-05-08 00:33:25 -0700 | [diff] [blame] | 125 | get_user(tv[1].tv_nsec, &t[1].tv_usec)) |
Stephen Rothwell | 9ad11ab | 2006-02-02 16:11:51 +1100 | [diff] [blame] | 126 | return -EFAULT; |
Ulrich Drepper | 1c710c8 | 2007-05-08 00:33:25 -0700 | [diff] [blame] | 127 | if (tv[0].tv_nsec >= 1000000 || tv[0].tv_nsec < 0 || |
| 128 | tv[1].tv_nsec >= 1000000 || tv[1].tv_nsec < 0) |
| 129 | return -EINVAL; |
| 130 | tv[0].tv_nsec *= 1000; |
| 131 | tv[1].tv_nsec *= 1000; |
Stephen Rothwell | 9ad11ab | 2006-02-02 16:11:51 +1100 | [diff] [blame] | 132 | } |
Ulrich Drepper | 1c710c8 | 2007-05-08 00:33:25 -0700 | [diff] [blame] | 133 | return do_utimes(dfd, filename, t ? tv : NULL, 0); |
Ulrich Drepper | 5590ff0 | 2006-01-18 17:43:53 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval __user *t) |
| 137 | { |
| 138 | return compat_sys_futimesat(AT_FDCWD, filename, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Christoph Hellwig | f7a5000 | 2008-10-15 22:02:05 -0700 | [diff] [blame] | 141 | static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf) |
| 142 | { |
| 143 | compat_ino_t ino = stat->ino; |
| 144 | typeof(ubuf->st_uid) uid = 0; |
| 145 | typeof(ubuf->st_gid) gid = 0; |
| 146 | int err; |
| 147 | |
| 148 | SET_UID(uid, stat->uid); |
| 149 | SET_GID(gid, stat->gid); |
| 150 | |
| 151 | if ((u64) stat->size > MAX_NON_LFS || |
| 152 | !old_valid_dev(stat->dev) || |
| 153 | !old_valid_dev(stat->rdev)) |
| 154 | return -EOVERFLOW; |
| 155 | if (sizeof(ino) < sizeof(stat->ino) && ino != stat->ino) |
| 156 | return -EOVERFLOW; |
| 157 | |
| 158 | if (clear_user(ubuf, sizeof(*ubuf))) |
| 159 | return -EFAULT; |
| 160 | |
| 161 | err = __put_user(old_encode_dev(stat->dev), &ubuf->st_dev); |
| 162 | err |= __put_user(ino, &ubuf->st_ino); |
| 163 | err |= __put_user(stat->mode, &ubuf->st_mode); |
| 164 | err |= __put_user(stat->nlink, &ubuf->st_nlink); |
| 165 | err |= __put_user(uid, &ubuf->st_uid); |
| 166 | err |= __put_user(gid, &ubuf->st_gid); |
| 167 | err |= __put_user(old_encode_dev(stat->rdev), &ubuf->st_rdev); |
| 168 | err |= __put_user(stat->size, &ubuf->st_size); |
| 169 | err |= __put_user(stat->atime.tv_sec, &ubuf->st_atime); |
| 170 | err |= __put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec); |
| 171 | err |= __put_user(stat->mtime.tv_sec, &ubuf->st_mtime); |
| 172 | err |= __put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec); |
| 173 | err |= __put_user(stat->ctime.tv_sec, &ubuf->st_ctime); |
| 174 | err |= __put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec); |
| 175 | err |= __put_user(stat->blksize, &ubuf->st_blksize); |
| 176 | err |= __put_user(stat->blocks, &ubuf->st_blocks); |
| 177 | return err; |
| 178 | } |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | asmlinkage long compat_sys_newstat(char __user * filename, |
| 181 | struct compat_stat __user *statbuf) |
| 182 | { |
| 183 | struct kstat stat; |
Ulrich Drepper | 5590ff0 | 2006-01-18 17:43:53 -0800 | [diff] [blame] | 184 | int error = vfs_stat_fd(AT_FDCWD, filename, &stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | if (!error) |
| 187 | error = cp_compat_stat(&stat, statbuf); |
| 188 | return error; |
| 189 | } |
| 190 | |
| 191 | asmlinkage long compat_sys_newlstat(char __user * filename, |
| 192 | struct compat_stat __user *statbuf) |
| 193 | { |
| 194 | struct kstat stat; |
Ulrich Drepper | 5590ff0 | 2006-01-18 17:43:53 -0800 | [diff] [blame] | 195 | int error = vfs_lstat_fd(AT_FDCWD, filename, &stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | if (!error) |
| 198 | error = cp_compat_stat(&stat, statbuf); |
| 199 | return error; |
| 200 | } |
| 201 | |
Kyle McMartin | 82d821d | 2006-03-24 03:18:20 -0800 | [diff] [blame] | 202 | #ifndef __ARCH_WANT_STAT64 |
Stephen Rothwell | 9ad11ab | 2006-02-02 16:11:51 +1100 | [diff] [blame] | 203 | asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user *filename, |
Ulrich Drepper | 5590ff0 | 2006-01-18 17:43:53 -0800 | [diff] [blame] | 204 | struct compat_stat __user *statbuf, int flag) |
| 205 | { |
| 206 | struct kstat stat; |
| 207 | int error = -EINVAL; |
| 208 | |
| 209 | if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0) |
| 210 | goto out; |
| 211 | |
| 212 | if (flag & AT_SYMLINK_NOFOLLOW) |
| 213 | error = vfs_lstat_fd(dfd, filename, &stat); |
| 214 | else |
| 215 | error = vfs_stat_fd(dfd, filename, &stat); |
| 216 | |
| 217 | if (!error) |
| 218 | error = cp_compat_stat(&stat, statbuf); |
| 219 | |
| 220 | out: |
| 221 | return error; |
| 222 | } |
Kyle McMartin | 82d821d | 2006-03-24 03:18:20 -0800 | [diff] [blame] | 223 | #endif |
Ulrich Drepper | 5590ff0 | 2006-01-18 17:43:53 -0800 | [diff] [blame] | 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | asmlinkage long compat_sys_newfstat(unsigned int fd, |
| 226 | struct compat_stat __user * statbuf) |
| 227 | { |
| 228 | struct kstat stat; |
| 229 | int error = vfs_fstat(fd, &stat); |
| 230 | |
| 231 | if (!error) |
| 232 | error = cp_compat_stat(&stat, statbuf); |
| 233 | return error; |
| 234 | } |
| 235 | |
| 236 | static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf) |
| 237 | { |
| 238 | |
| 239 | if (sizeof ubuf->f_blocks == 4) { |
Jon Tollefson | f4a67cc | 2008-07-23 21:27:55 -0700 | [diff] [blame] | 240 | if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail | |
| 241 | kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return -EOVERFLOW; |
| 243 | /* f_files and f_ffree may be -1; it's okay |
| 244 | * to stuff that into 32 bits */ |
| 245 | if (kbuf->f_files != 0xffffffffffffffffULL |
| 246 | && (kbuf->f_files & 0xffffffff00000000ULL)) |
| 247 | return -EOVERFLOW; |
| 248 | if (kbuf->f_ffree != 0xffffffffffffffffULL |
| 249 | && (kbuf->f_ffree & 0xffffffff00000000ULL)) |
| 250 | return -EOVERFLOW; |
| 251 | } |
| 252 | if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) || |
| 253 | __put_user(kbuf->f_type, &ubuf->f_type) || |
| 254 | __put_user(kbuf->f_bsize, &ubuf->f_bsize) || |
| 255 | __put_user(kbuf->f_blocks, &ubuf->f_blocks) || |
| 256 | __put_user(kbuf->f_bfree, &ubuf->f_bfree) || |
| 257 | __put_user(kbuf->f_bavail, &ubuf->f_bavail) || |
| 258 | __put_user(kbuf->f_files, &ubuf->f_files) || |
| 259 | __put_user(kbuf->f_ffree, &ubuf->f_ffree) || |
| 260 | __put_user(kbuf->f_namelen, &ubuf->f_namelen) || |
| 261 | __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) || |
| 262 | __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) || |
| 263 | __put_user(kbuf->f_frsize, &ubuf->f_frsize) || |
| 264 | __put_user(0, &ubuf->f_spare[0]) || |
| 265 | __put_user(0, &ubuf->f_spare[1]) || |
| 266 | __put_user(0, &ubuf->f_spare[2]) || |
| 267 | __put_user(0, &ubuf->f_spare[3]) || |
| 268 | __put_user(0, &ubuf->f_spare[4])) |
| 269 | return -EFAULT; |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | * The following statfs calls are copies of code from fs/open.c and |
| 275 | * should be checked against those from time to time |
| 276 | */ |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 277 | asmlinkage long compat_sys_statfs(const char __user *pathname, struct compat_statfs __user *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 279 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | int error; |
| 281 | |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 282 | error = user_path(pathname, &path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | if (!error) { |
| 284 | struct kstatfs tmp; |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 285 | error = vfs_statfs(path.dentry, &tmp); |
David Gibson | 86e07ce | 2005-11-21 21:32:23 -0800 | [diff] [blame] | 286 | if (!error) |
| 287 | error = put_compat_statfs(buf, &tmp); |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 288 | path_put(&path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
| 290 | return error; |
| 291 | } |
| 292 | |
| 293 | asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs __user *buf) |
| 294 | { |
| 295 | struct file * file; |
| 296 | struct kstatfs tmp; |
| 297 | int error; |
| 298 | |
| 299 | error = -EBADF; |
| 300 | file = fget(fd); |
| 301 | if (!file) |
| 302 | goto out; |
Josef "Jeff" Sipek | 0f7fc9e | 2006-12-08 02:36:35 -0800 | [diff] [blame] | 303 | error = vfs_statfs(file->f_path.dentry, &tmp); |
David Gibson | 86e07ce | 2005-11-21 21:32:23 -0800 | [diff] [blame] | 304 | if (!error) |
| 305 | error = put_compat_statfs(buf, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | fput(file); |
| 307 | out: |
| 308 | return error; |
| 309 | } |
| 310 | |
| 311 | static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf) |
| 312 | { |
| 313 | if (sizeof ubuf->f_blocks == 4) { |
Jon Tollefson | f4a67cc | 2008-07-23 21:27:55 -0700 | [diff] [blame] | 314 | if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail | |
| 315 | kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | return -EOVERFLOW; |
| 317 | /* f_files and f_ffree may be -1; it's okay |
| 318 | * to stuff that into 32 bits */ |
| 319 | if (kbuf->f_files != 0xffffffffffffffffULL |
| 320 | && (kbuf->f_files & 0xffffffff00000000ULL)) |
| 321 | return -EOVERFLOW; |
| 322 | if (kbuf->f_ffree != 0xffffffffffffffffULL |
| 323 | && (kbuf->f_ffree & 0xffffffff00000000ULL)) |
| 324 | return -EOVERFLOW; |
| 325 | } |
| 326 | if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) || |
| 327 | __put_user(kbuf->f_type, &ubuf->f_type) || |
| 328 | __put_user(kbuf->f_bsize, &ubuf->f_bsize) || |
| 329 | __put_user(kbuf->f_blocks, &ubuf->f_blocks) || |
| 330 | __put_user(kbuf->f_bfree, &ubuf->f_bfree) || |
| 331 | __put_user(kbuf->f_bavail, &ubuf->f_bavail) || |
| 332 | __put_user(kbuf->f_files, &ubuf->f_files) || |
| 333 | __put_user(kbuf->f_ffree, &ubuf->f_ffree) || |
| 334 | __put_user(kbuf->f_namelen, &ubuf->f_namelen) || |
| 335 | __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) || |
| 336 | __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) || |
| 337 | __put_user(kbuf->f_frsize, &ubuf->f_frsize)) |
| 338 | return -EFAULT; |
| 339 | return 0; |
| 340 | } |
| 341 | |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 342 | asmlinkage long compat_sys_statfs64(const char __user *pathname, compat_size_t sz, struct compat_statfs64 __user *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 344 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | int error; |
| 346 | |
| 347 | if (sz != sizeof(*buf)) |
| 348 | return -EINVAL; |
| 349 | |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 350 | error = user_path(pathname, &path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | if (!error) { |
| 352 | struct kstatfs tmp; |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 353 | error = vfs_statfs(path.dentry, &tmp); |
David Gibson | 86e07ce | 2005-11-21 21:32:23 -0800 | [diff] [blame] | 354 | if (!error) |
| 355 | error = put_compat_statfs64(buf, &tmp); |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 356 | path_put(&path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | return error; |
| 359 | } |
| 360 | |
| 361 | asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user *buf) |
| 362 | { |
| 363 | struct file * file; |
| 364 | struct kstatfs tmp; |
| 365 | int error; |
| 366 | |
| 367 | if (sz != sizeof(*buf)) |
| 368 | return -EINVAL; |
| 369 | |
| 370 | error = -EBADF; |
| 371 | file = fget(fd); |
| 372 | if (!file) |
| 373 | goto out; |
Josef "Jeff" Sipek | 0f7fc9e | 2006-12-08 02:36:35 -0800 | [diff] [blame] | 374 | error = vfs_statfs(file->f_path.dentry, &tmp); |
David Gibson | 86e07ce | 2005-11-21 21:32:23 -0800 | [diff] [blame] | 375 | if (!error) |
| 376 | error = put_compat_statfs64(buf, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | fput(file); |
| 378 | out: |
| 379 | return error; |
| 380 | } |
| 381 | |
Christoph Hellwig | 2b1c6bd | 2008-11-28 10:09:09 +0100 | [diff] [blame] | 382 | /* |
| 383 | * This is a copy of sys_ustat, just dealing with a structure layout. |
| 384 | * Given how simple this syscall is that apporach is more maintainable |
| 385 | * than the various conversion hacks. |
| 386 | */ |
| 387 | asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u) |
| 388 | { |
| 389 | struct super_block *sb; |
| 390 | struct compat_ustat tmp; |
| 391 | struct kstatfs sbuf; |
| 392 | int err; |
| 393 | |
| 394 | sb = user_get_super(new_decode_dev(dev)); |
| 395 | if (!sb) |
| 396 | return -EINVAL; |
| 397 | err = vfs_statfs(sb->s_root, &sbuf); |
| 398 | drop_super(sb); |
| 399 | if (err) |
| 400 | return err; |
| 401 | |
| 402 | memset(&tmp, 0, sizeof(struct compat_ustat)); |
| 403 | tmp.f_tfree = sbuf.f_bfree; |
| 404 | tmp.f_tinode = sbuf.f_ffree; |
| 405 | if (copy_to_user(u, &tmp, sizeof(struct compat_ustat))) |
| 406 | return -EFAULT; |
| 407 | return 0; |
| 408 | } |
| 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | static int get_compat_flock(struct flock *kfl, struct compat_flock __user *ufl) |
| 411 | { |
| 412 | if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) || |
| 413 | __get_user(kfl->l_type, &ufl->l_type) || |
| 414 | __get_user(kfl->l_whence, &ufl->l_whence) || |
| 415 | __get_user(kfl->l_start, &ufl->l_start) || |
| 416 | __get_user(kfl->l_len, &ufl->l_len) || |
| 417 | __get_user(kfl->l_pid, &ufl->l_pid)) |
| 418 | return -EFAULT; |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static int put_compat_flock(struct flock *kfl, struct compat_flock __user *ufl) |
| 423 | { |
| 424 | if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) || |
| 425 | __put_user(kfl->l_type, &ufl->l_type) || |
| 426 | __put_user(kfl->l_whence, &ufl->l_whence) || |
| 427 | __put_user(kfl->l_start, &ufl->l_start) || |
| 428 | __put_user(kfl->l_len, &ufl->l_len) || |
| 429 | __put_user(kfl->l_pid, &ufl->l_pid)) |
| 430 | return -EFAULT; |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64 |
| 435 | static int get_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl) |
| 436 | { |
| 437 | if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) || |
| 438 | __get_user(kfl->l_type, &ufl->l_type) || |
| 439 | __get_user(kfl->l_whence, &ufl->l_whence) || |
| 440 | __get_user(kfl->l_start, &ufl->l_start) || |
| 441 | __get_user(kfl->l_len, &ufl->l_len) || |
| 442 | __get_user(kfl->l_pid, &ufl->l_pid)) |
| 443 | return -EFAULT; |
| 444 | return 0; |
| 445 | } |
| 446 | #endif |
| 447 | |
| 448 | #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64 |
| 449 | static int put_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl) |
| 450 | { |
| 451 | if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) || |
| 452 | __put_user(kfl->l_type, &ufl->l_type) || |
| 453 | __put_user(kfl->l_whence, &ufl->l_whence) || |
| 454 | __put_user(kfl->l_start, &ufl->l_start) || |
| 455 | __put_user(kfl->l_len, &ufl->l_len) || |
| 456 | __put_user(kfl->l_pid, &ufl->l_pid)) |
| 457 | return -EFAULT; |
| 458 | return 0; |
| 459 | } |
| 460 | #endif |
| 461 | |
| 462 | asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd, |
| 463 | unsigned long arg) |
| 464 | { |
| 465 | mm_segment_t old_fs; |
| 466 | struct flock f; |
| 467 | long ret; |
| 468 | |
| 469 | switch (cmd) { |
| 470 | case F_GETLK: |
| 471 | case F_SETLK: |
| 472 | case F_SETLKW: |
| 473 | ret = get_compat_flock(&f, compat_ptr(arg)); |
| 474 | if (ret != 0) |
| 475 | break; |
| 476 | old_fs = get_fs(); |
| 477 | set_fs(KERNEL_DS); |
| 478 | ret = sys_fcntl(fd, cmd, (unsigned long)&f); |
| 479 | set_fs(old_fs); |
| 480 | if (cmd == F_GETLK && ret == 0) { |
NeilBrown | 2520f14 | 2006-01-08 01:02:40 -0800 | [diff] [blame] | 481 | /* GETLK was successfule and we need to return the data... |
| 482 | * but it needs to fit in the compat structure. |
| 483 | * l_start shouldn't be too big, unless the original |
| 484 | * start + end is greater than COMPAT_OFF_T_MAX, in which |
| 485 | * case the app was asking for trouble, so we return |
| 486 | * -EOVERFLOW in that case. |
| 487 | * l_len could be too big, in which case we just truncate it, |
| 488 | * and only allow the app to see that part of the conflicting |
| 489 | * lock that might make sense to it anyway |
| 490 | */ |
| 491 | |
| 492 | if (f.l_start > COMPAT_OFF_T_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | ret = -EOVERFLOW; |
NeilBrown | 2520f14 | 2006-01-08 01:02:40 -0800 | [diff] [blame] | 494 | if (f.l_len > COMPAT_OFF_T_MAX) |
| 495 | f.l_len = COMPAT_OFF_T_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | if (ret == 0) |
| 497 | ret = put_compat_flock(&f, compat_ptr(arg)); |
| 498 | } |
| 499 | break; |
| 500 | |
| 501 | case F_GETLK64: |
| 502 | case F_SETLK64: |
| 503 | case F_SETLKW64: |
| 504 | ret = get_compat_flock64(&f, compat_ptr(arg)); |
| 505 | if (ret != 0) |
| 506 | break; |
| 507 | old_fs = get_fs(); |
| 508 | set_fs(KERNEL_DS); |
| 509 | ret = sys_fcntl(fd, (cmd == F_GETLK64) ? F_GETLK : |
| 510 | ((cmd == F_SETLK64) ? F_SETLK : F_SETLKW), |
| 511 | (unsigned long)&f); |
| 512 | set_fs(old_fs); |
| 513 | if (cmd == F_GETLK64 && ret == 0) { |
NeilBrown | 2520f14 | 2006-01-08 01:02:40 -0800 | [diff] [blame] | 514 | /* need to return lock information - see above for commentary */ |
| 515 | if (f.l_start > COMPAT_LOFF_T_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | ret = -EOVERFLOW; |
NeilBrown | 2520f14 | 2006-01-08 01:02:40 -0800 | [diff] [blame] | 517 | if (f.l_len > COMPAT_LOFF_T_MAX) |
| 518 | f.l_len = COMPAT_LOFF_T_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (ret == 0) |
| 520 | ret = put_compat_flock64(&f, compat_ptr(arg)); |
| 521 | } |
| 522 | break; |
| 523 | |
| 524 | default: |
| 525 | ret = sys_fcntl(fd, cmd, arg); |
| 526 | break; |
| 527 | } |
| 528 | return ret; |
| 529 | } |
| 530 | |
| 531 | asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd, |
| 532 | unsigned long arg) |
| 533 | { |
| 534 | if ((cmd == F_GETLK64) || (cmd == F_SETLK64) || (cmd == F_SETLKW64)) |
| 535 | return -EINVAL; |
| 536 | return compat_sys_fcntl64(fd, cmd, arg); |
| 537 | } |
| 538 | |
| 539 | asmlinkage long |
| 540 | compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p) |
| 541 | { |
| 542 | long ret; |
| 543 | aio_context_t ctx64; |
| 544 | |
| 545 | mm_segment_t oldfs = get_fs(); |
| 546 | if (unlikely(get_user(ctx64, ctx32p))) |
| 547 | return -EFAULT; |
| 548 | |
| 549 | set_fs(KERNEL_DS); |
| 550 | /* The __user pointer cast is valid because of the set_fs() */ |
| 551 | ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64); |
| 552 | set_fs(oldfs); |
| 553 | /* truncating is ok because it's a user address */ |
| 554 | if (!ret) |
| 555 | ret = put_user((u32) ctx64, ctx32p); |
| 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | asmlinkage long |
| 560 | compat_sys_io_getevents(aio_context_t ctx_id, |
| 561 | unsigned long min_nr, |
| 562 | unsigned long nr, |
| 563 | struct io_event __user *events, |
| 564 | struct compat_timespec __user *timeout) |
| 565 | { |
| 566 | long ret; |
| 567 | struct timespec t; |
| 568 | struct timespec __user *ut = NULL; |
| 569 | |
| 570 | ret = -EFAULT; |
| 571 | if (unlikely(!access_ok(VERIFY_WRITE, events, |
| 572 | nr * sizeof(struct io_event)))) |
| 573 | goto out; |
| 574 | if (timeout) { |
| 575 | if (get_compat_timespec(&t, timeout)) |
| 576 | goto out; |
| 577 | |
| 578 | ut = compat_alloc_user_space(sizeof(*ut)); |
| 579 | if (copy_to_user(ut, &t, sizeof(t)) ) |
| 580 | goto out; |
| 581 | } |
| 582 | ret = sys_io_getevents(ctx_id, min_nr, nr, events, ut); |
| 583 | out: |
| 584 | return ret; |
| 585 | } |
| 586 | |
| 587 | static inline long |
| 588 | copy_iocb(long nr, u32 __user *ptr32, struct iocb __user * __user *ptr64) |
| 589 | { |
| 590 | compat_uptr_t uptr; |
| 591 | int i; |
| 592 | |
| 593 | for (i = 0; i < nr; ++i) { |
| 594 | if (get_user(uptr, ptr32 + i)) |
| 595 | return -EFAULT; |
| 596 | if (put_user(compat_ptr(uptr), ptr64 + i)) |
| 597 | return -EFAULT; |
| 598 | } |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *)) |
| 603 | |
| 604 | asmlinkage long |
| 605 | compat_sys_io_submit(aio_context_t ctx_id, int nr, u32 __user *iocb) |
| 606 | { |
| 607 | struct iocb __user * __user *iocb64; |
| 608 | long ret; |
| 609 | |
| 610 | if (unlikely(nr < 0)) |
| 611 | return -EINVAL; |
| 612 | |
| 613 | if (nr > MAX_AIO_SUBMITS) |
| 614 | nr = MAX_AIO_SUBMITS; |
| 615 | |
| 616 | iocb64 = compat_alloc_user_space(nr * sizeof(*iocb64)); |
| 617 | ret = copy_iocb(nr, iocb, iocb64); |
| 618 | if (!ret) |
| 619 | ret = sys_io_submit(ctx_id, nr, iocb64); |
| 620 | return ret; |
| 621 | } |
| 622 | |
| 623 | struct compat_ncp_mount_data { |
| 624 | compat_int_t version; |
| 625 | compat_uint_t ncp_fd; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 626 | __compat_uid_t mounted_uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | compat_pid_t wdog_pid; |
| 628 | unsigned char mounted_vol[NCP_VOLNAME_LEN + 1]; |
| 629 | compat_uint_t time_out; |
| 630 | compat_uint_t retry_count; |
| 631 | compat_uint_t flags; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 632 | __compat_uid_t uid; |
| 633 | __compat_gid_t gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | compat_mode_t file_mode; |
| 635 | compat_mode_t dir_mode; |
| 636 | }; |
| 637 | |
| 638 | struct compat_ncp_mount_data_v4 { |
| 639 | compat_int_t version; |
| 640 | compat_ulong_t flags; |
| 641 | compat_ulong_t mounted_uid; |
| 642 | compat_long_t wdog_pid; |
| 643 | compat_uint_t ncp_fd; |
| 644 | compat_uint_t time_out; |
| 645 | compat_uint_t retry_count; |
| 646 | compat_ulong_t uid; |
| 647 | compat_ulong_t gid; |
| 648 | compat_ulong_t file_mode; |
| 649 | compat_ulong_t dir_mode; |
| 650 | }; |
| 651 | |
| 652 | static void *do_ncp_super_data_conv(void *raw_data) |
| 653 | { |
| 654 | int version = *(unsigned int *)raw_data; |
| 655 | |
| 656 | if (version == 3) { |
| 657 | struct compat_ncp_mount_data *c_n = raw_data; |
| 658 | struct ncp_mount_data *n = raw_data; |
| 659 | |
| 660 | n->dir_mode = c_n->dir_mode; |
| 661 | n->file_mode = c_n->file_mode; |
| 662 | n->gid = c_n->gid; |
| 663 | n->uid = c_n->uid; |
| 664 | memmove (n->mounted_vol, c_n->mounted_vol, (sizeof (c_n->mounted_vol) + 3 * sizeof (unsigned int))); |
| 665 | n->wdog_pid = c_n->wdog_pid; |
| 666 | n->mounted_uid = c_n->mounted_uid; |
| 667 | } else if (version == 4) { |
| 668 | struct compat_ncp_mount_data_v4 *c_n = raw_data; |
| 669 | struct ncp_mount_data_v4 *n = raw_data; |
| 670 | |
| 671 | n->dir_mode = c_n->dir_mode; |
| 672 | n->file_mode = c_n->file_mode; |
| 673 | n->gid = c_n->gid; |
| 674 | n->uid = c_n->uid; |
| 675 | n->retry_count = c_n->retry_count; |
| 676 | n->time_out = c_n->time_out; |
| 677 | n->ncp_fd = c_n->ncp_fd; |
| 678 | n->wdog_pid = c_n->wdog_pid; |
| 679 | n->mounted_uid = c_n->mounted_uid; |
| 680 | n->flags = c_n->flags; |
| 681 | } else if (version != 5) { |
| 682 | return NULL; |
| 683 | } |
| 684 | |
| 685 | return raw_data; |
| 686 | } |
| 687 | |
| 688 | struct compat_smb_mount_data { |
| 689 | compat_int_t version; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 690 | __compat_uid_t mounted_uid; |
| 691 | __compat_uid_t uid; |
| 692 | __compat_gid_t gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | compat_mode_t file_mode; |
| 694 | compat_mode_t dir_mode; |
| 695 | }; |
| 696 | |
| 697 | static void *do_smb_super_data_conv(void *raw_data) |
| 698 | { |
| 699 | struct smb_mount_data *s = raw_data; |
| 700 | struct compat_smb_mount_data *c_s = raw_data; |
| 701 | |
| 702 | if (c_s->version != SMB_MOUNT_OLDVERSION) |
| 703 | goto out; |
| 704 | s->dir_mode = c_s->dir_mode; |
| 705 | s->file_mode = c_s->file_mode; |
| 706 | s->gid = c_s->gid; |
| 707 | s->uid = c_s->uid; |
| 708 | s->mounted_uid = c_s->mounted_uid; |
| 709 | out: |
| 710 | return raw_data; |
| 711 | } |
| 712 | |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 713 | struct compat_nfs_string { |
| 714 | compat_uint_t len; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 715 | compat_uptr_t data; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 716 | }; |
| 717 | |
| 718 | static inline void compat_nfs_string(struct nfs_string *dst, |
| 719 | struct compat_nfs_string *src) |
| 720 | { |
| 721 | dst->data = compat_ptr(src->data); |
| 722 | dst->len = src->len; |
| 723 | } |
| 724 | |
| 725 | struct compat_nfs4_mount_data_v1 { |
| 726 | compat_int_t version; |
| 727 | compat_int_t flags; |
| 728 | compat_int_t rsize; |
| 729 | compat_int_t wsize; |
| 730 | compat_int_t timeo; |
| 731 | compat_int_t retrans; |
| 732 | compat_int_t acregmin; |
| 733 | compat_int_t acregmax; |
| 734 | compat_int_t acdirmin; |
| 735 | compat_int_t acdirmax; |
| 736 | struct compat_nfs_string client_addr; |
| 737 | struct compat_nfs_string mnt_path; |
| 738 | struct compat_nfs_string hostname; |
| 739 | compat_uint_t host_addrlen; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 740 | compat_uptr_t host_addr; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 741 | compat_int_t proto; |
| 742 | compat_int_t auth_flavourlen; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 743 | compat_uptr_t auth_flavours; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 744 | }; |
| 745 | |
| 746 | static int do_nfs4_super_data_conv(void *raw_data) |
| 747 | { |
| 748 | int version = *(compat_uint_t *) raw_data; |
| 749 | |
| 750 | if (version == 1) { |
| 751 | struct compat_nfs4_mount_data_v1 *raw = raw_data; |
| 752 | struct nfs4_mount_data *real = raw_data; |
| 753 | |
| 754 | /* copy the fields backwards */ |
| 755 | real->auth_flavours = compat_ptr(raw->auth_flavours); |
| 756 | real->auth_flavourlen = raw->auth_flavourlen; |
| 757 | real->proto = raw->proto; |
| 758 | real->host_addr = compat_ptr(raw->host_addr); |
| 759 | real->host_addrlen = raw->host_addrlen; |
| 760 | compat_nfs_string(&real->hostname, &raw->hostname); |
| 761 | compat_nfs_string(&real->mnt_path, &raw->mnt_path); |
| 762 | compat_nfs_string(&real->client_addr, &raw->client_addr); |
| 763 | real->acdirmax = raw->acdirmax; |
| 764 | real->acdirmin = raw->acdirmin; |
| 765 | real->acregmax = raw->acregmax; |
| 766 | real->acregmin = raw->acregmin; |
| 767 | real->retrans = raw->retrans; |
| 768 | real->timeo = raw->timeo; |
| 769 | real->wsize = raw->wsize; |
| 770 | real->rsize = raw->rsize; |
| 771 | real->flags = raw->flags; |
| 772 | real->version = raw->version; |
| 773 | } |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 774 | |
| 775 | return 0; |
| 776 | } |
| 777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | #define SMBFS_NAME "smbfs" |
| 779 | #define NCPFS_NAME "ncpfs" |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 780 | #define NFS4_NAME "nfs4" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| 782 | asmlinkage long compat_sys_mount(char __user * dev_name, char __user * dir_name, |
| 783 | char __user * type, unsigned long flags, |
| 784 | void __user * data) |
| 785 | { |
| 786 | unsigned long type_page; |
| 787 | unsigned long data_page; |
| 788 | unsigned long dev_page; |
| 789 | char *dir_page; |
| 790 | int retval; |
| 791 | |
| 792 | retval = copy_mount_options (type, &type_page); |
| 793 | if (retval < 0) |
| 794 | goto out; |
| 795 | |
| 796 | dir_page = getname(dir_name); |
| 797 | retval = PTR_ERR(dir_page); |
| 798 | if (IS_ERR(dir_page)) |
| 799 | goto out1; |
| 800 | |
| 801 | retval = copy_mount_options (dev_name, &dev_page); |
| 802 | if (retval < 0) |
| 803 | goto out2; |
| 804 | |
| 805 | retval = copy_mount_options (data, &data_page); |
| 806 | if (retval < 0) |
| 807 | goto out3; |
| 808 | |
| 809 | retval = -EINVAL; |
| 810 | |
Andrey Mirkin | 822191a | 2006-12-06 20:31:35 -0800 | [diff] [blame] | 811 | if (type_page && data_page) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | if (!strcmp((char *)type_page, SMBFS_NAME)) { |
| 813 | do_smb_super_data_conv((void *)data_page); |
| 814 | } else if (!strcmp((char *)type_page, NCPFS_NAME)) { |
| 815 | do_ncp_super_data_conv((void *)data_page); |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 816 | } else if (!strcmp((char *)type_page, NFS4_NAME)) { |
| 817 | if (do_nfs4_super_data_conv((void *) data_page)) |
| 818 | goto out4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | |
| 822 | lock_kernel(); |
| 823 | retval = do_mount((char*)dev_page, dir_page, (char*)type_page, |
| 824 | flags, (void*)data_page); |
| 825 | unlock_kernel(); |
| 826 | |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 827 | out4: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | free_page(data_page); |
| 829 | out3: |
| 830 | free_page(dev_page); |
| 831 | out2: |
| 832 | putname(dir_page); |
| 833 | out1: |
| 834 | free_page(type_page); |
| 835 | out: |
| 836 | return retval; |
| 837 | } |
| 838 | |
| 839 | #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
| 841 | struct compat_old_linux_dirent { |
| 842 | compat_ulong_t d_ino; |
| 843 | compat_ulong_t d_offset; |
| 844 | unsigned short d_namlen; |
| 845 | char d_name[1]; |
| 846 | }; |
| 847 | |
| 848 | struct compat_readdir_callback { |
| 849 | struct compat_old_linux_dirent __user *dirent; |
| 850 | int result; |
| 851 | }; |
| 852 | |
| 853 | static int compat_fillonedir(void *__buf, const char *name, int namlen, |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 854 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | { |
| 856 | struct compat_readdir_callback *buf = __buf; |
| 857 | struct compat_old_linux_dirent __user *dirent; |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 858 | compat_ulong_t d_ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
| 860 | if (buf->result) |
| 861 | return -EINVAL; |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 862 | d_ino = ino; |
Al Viro | 8f3f655 | 2008-08-12 00:28:24 -0400 | [diff] [blame] | 863 | if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) { |
| 864 | buf->result = -EOVERFLOW; |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 865 | return -EOVERFLOW; |
Al Viro | 8f3f655 | 2008-08-12 00:28:24 -0400 | [diff] [blame] | 866 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | buf->result++; |
| 868 | dirent = buf->dirent; |
| 869 | if (!access_ok(VERIFY_WRITE, dirent, |
| 870 | (unsigned long)(dirent->d_name + namlen + 1) - |
| 871 | (unsigned long)dirent)) |
| 872 | goto efault; |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 873 | if ( __put_user(d_ino, &dirent->d_ino) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | __put_user(offset, &dirent->d_offset) || |
| 875 | __put_user(namlen, &dirent->d_namlen) || |
| 876 | __copy_to_user(dirent->d_name, name, namlen) || |
| 877 | __put_user(0, dirent->d_name + namlen)) |
| 878 | goto efault; |
| 879 | return 0; |
| 880 | efault: |
| 881 | buf->result = -EFAULT; |
| 882 | return -EFAULT; |
| 883 | } |
| 884 | |
| 885 | asmlinkage long compat_sys_old_readdir(unsigned int fd, |
| 886 | struct compat_old_linux_dirent __user *dirent, unsigned int count) |
| 887 | { |
| 888 | int error; |
| 889 | struct file *file; |
| 890 | struct compat_readdir_callback buf; |
| 891 | |
| 892 | error = -EBADF; |
| 893 | file = fget(fd); |
| 894 | if (!file) |
| 895 | goto out; |
| 896 | |
| 897 | buf.result = 0; |
| 898 | buf.dirent = dirent; |
| 899 | |
| 900 | error = vfs_readdir(file, compat_fillonedir, &buf); |
Al Viro | 53c9c5c | 2008-08-24 07:29:52 -0400 | [diff] [blame] | 901 | if (buf.result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | error = buf.result; |
| 903 | |
| 904 | fput(file); |
| 905 | out: |
| 906 | return error; |
| 907 | } |
| 908 | |
| 909 | struct compat_linux_dirent { |
| 910 | compat_ulong_t d_ino; |
| 911 | compat_ulong_t d_off; |
| 912 | unsigned short d_reclen; |
| 913 | char d_name[1]; |
| 914 | }; |
| 915 | |
| 916 | struct compat_getdents_callback { |
| 917 | struct compat_linux_dirent __user *current_dir; |
| 918 | struct compat_linux_dirent __user *previous; |
| 919 | int count; |
| 920 | int error; |
| 921 | }; |
| 922 | |
| 923 | static int compat_filldir(void *__buf, const char *name, int namlen, |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 924 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | { |
| 926 | struct compat_linux_dirent __user * dirent; |
| 927 | struct compat_getdents_callback *buf = __buf; |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 928 | compat_ulong_t d_ino; |
Milind Arun Choudhary | 022a169 | 2007-05-08 00:29:02 -0700 | [diff] [blame] | 929 | int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 2, sizeof(compat_long_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | buf->error = -EINVAL; /* only used if we fail.. */ |
| 932 | if (reclen > buf->count) |
| 933 | return -EINVAL; |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 934 | d_ino = ino; |
Al Viro | 8f3f655 | 2008-08-12 00:28:24 -0400 | [diff] [blame] | 935 | if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) { |
| 936 | buf->error = -EOVERFLOW; |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 937 | return -EOVERFLOW; |
Al Viro | 8f3f655 | 2008-08-12 00:28:24 -0400 | [diff] [blame] | 938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | dirent = buf->previous; |
| 940 | if (dirent) { |
| 941 | if (__put_user(offset, &dirent->d_off)) |
| 942 | goto efault; |
| 943 | } |
| 944 | dirent = buf->current_dir; |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 945 | if (__put_user(d_ino, &dirent->d_ino)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | goto efault; |
| 947 | if (__put_user(reclen, &dirent->d_reclen)) |
| 948 | goto efault; |
| 949 | if (copy_to_user(dirent->d_name, name, namlen)) |
| 950 | goto efault; |
| 951 | if (__put_user(0, dirent->d_name + namlen)) |
| 952 | goto efault; |
| 953 | if (__put_user(d_type, (char __user *) dirent + reclen - 1)) |
| 954 | goto efault; |
| 955 | buf->previous = dirent; |
| 956 | dirent = (void __user *)dirent + reclen; |
| 957 | buf->current_dir = dirent; |
| 958 | buf->count -= reclen; |
| 959 | return 0; |
| 960 | efault: |
| 961 | buf->error = -EFAULT; |
| 962 | return -EFAULT; |
| 963 | } |
| 964 | |
| 965 | asmlinkage long compat_sys_getdents(unsigned int fd, |
| 966 | struct compat_linux_dirent __user *dirent, unsigned int count) |
| 967 | { |
| 968 | struct file * file; |
| 969 | struct compat_linux_dirent __user * lastdirent; |
| 970 | struct compat_getdents_callback buf; |
| 971 | int error; |
| 972 | |
| 973 | error = -EFAULT; |
| 974 | if (!access_ok(VERIFY_WRITE, dirent, count)) |
| 975 | goto out; |
| 976 | |
| 977 | error = -EBADF; |
| 978 | file = fget(fd); |
| 979 | if (!file) |
| 980 | goto out; |
| 981 | |
| 982 | buf.current_dir = dirent; |
| 983 | buf.previous = NULL; |
| 984 | buf.count = count; |
| 985 | buf.error = 0; |
| 986 | |
| 987 | error = vfs_readdir(file, compat_filldir, &buf); |
Al Viro | 53c9c5c | 2008-08-24 07:29:52 -0400 | [diff] [blame] | 988 | if (error >= 0) |
| 989 | error = buf.error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | lastdirent = buf.previous; |
| 991 | if (lastdirent) { |
| 992 | if (put_user(file->f_pos, &lastdirent->d_off)) |
| 993 | error = -EFAULT; |
| 994 | else |
| 995 | error = count - buf.count; |
| 996 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | fput(file); |
| 998 | out: |
| 999 | return error; |
| 1000 | } |
| 1001 | |
| 1002 | #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
| 1004 | struct compat_getdents_callback64 { |
| 1005 | struct linux_dirent64 __user *current_dir; |
| 1006 | struct linux_dirent64 __user *previous; |
| 1007 | int count; |
| 1008 | int error; |
| 1009 | }; |
| 1010 | |
| 1011 | static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t offset, |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 1012 | u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | { |
| 1014 | struct linux_dirent64 __user *dirent; |
| 1015 | struct compat_getdents_callback64 *buf = __buf; |
| 1016 | int jj = NAME_OFFSET(dirent); |
Milind Arun Choudhary | 022a169 | 2007-05-08 00:29:02 -0700 | [diff] [blame] | 1017 | int reclen = ALIGN(jj + namlen + 1, sizeof(u64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | u64 off; |
| 1019 | |
| 1020 | buf->error = -EINVAL; /* only used if we fail.. */ |
| 1021 | if (reclen > buf->count) |
| 1022 | return -EINVAL; |
| 1023 | dirent = buf->previous; |
| 1024 | |
| 1025 | if (dirent) { |
| 1026 | if (__put_user_unaligned(offset, &dirent->d_off)) |
| 1027 | goto efault; |
| 1028 | } |
| 1029 | dirent = buf->current_dir; |
| 1030 | if (__put_user_unaligned(ino, &dirent->d_ino)) |
| 1031 | goto efault; |
| 1032 | off = 0; |
| 1033 | if (__put_user_unaligned(off, &dirent->d_off)) |
| 1034 | goto efault; |
| 1035 | if (__put_user(reclen, &dirent->d_reclen)) |
| 1036 | goto efault; |
| 1037 | if (__put_user(d_type, &dirent->d_type)) |
| 1038 | goto efault; |
| 1039 | if (copy_to_user(dirent->d_name, name, namlen)) |
| 1040 | goto efault; |
| 1041 | if (__put_user(0, dirent->d_name + namlen)) |
| 1042 | goto efault; |
| 1043 | buf->previous = dirent; |
| 1044 | dirent = (void __user *)dirent + reclen; |
| 1045 | buf->current_dir = dirent; |
| 1046 | buf->count -= reclen; |
| 1047 | return 0; |
| 1048 | efault: |
| 1049 | buf->error = -EFAULT; |
| 1050 | return -EFAULT; |
| 1051 | } |
| 1052 | |
| 1053 | asmlinkage long compat_sys_getdents64(unsigned int fd, |
| 1054 | struct linux_dirent64 __user * dirent, unsigned int count) |
| 1055 | { |
| 1056 | struct file * file; |
| 1057 | struct linux_dirent64 __user * lastdirent; |
| 1058 | struct compat_getdents_callback64 buf; |
| 1059 | int error; |
| 1060 | |
| 1061 | error = -EFAULT; |
| 1062 | if (!access_ok(VERIFY_WRITE, dirent, count)) |
| 1063 | goto out; |
| 1064 | |
| 1065 | error = -EBADF; |
| 1066 | file = fget(fd); |
| 1067 | if (!file) |
| 1068 | goto out; |
| 1069 | |
| 1070 | buf.current_dir = dirent; |
| 1071 | buf.previous = NULL; |
| 1072 | buf.count = count; |
| 1073 | buf.error = 0; |
| 1074 | |
| 1075 | error = vfs_readdir(file, compat_filldir64, &buf); |
Al Viro | 53c9c5c | 2008-08-24 07:29:52 -0400 | [diff] [blame] | 1076 | if (error >= 0) |
| 1077 | error = buf.error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | lastdirent = buf.previous; |
| 1079 | if (lastdirent) { |
| 1080 | typeof(lastdirent->d_off) d_off = file->f_pos; |
Heiko Carstens | 7116e99 | 2006-12-06 20:36:36 -0800 | [diff] [blame] | 1081 | if (__put_user_unaligned(d_off, &lastdirent->d_off)) |
Al Viro | 53c9c5c | 2008-08-24 07:29:52 -0400 | [diff] [blame] | 1082 | error = -EFAULT; |
| 1083 | else |
| 1084 | error = count - buf.count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | fput(file); |
| 1087 | out: |
| 1088 | return error; |
| 1089 | } |
| 1090 | #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */ |
| 1091 | |
| 1092 | static ssize_t compat_do_readv_writev(int type, struct file *file, |
| 1093 | const struct compat_iovec __user *uvector, |
| 1094 | unsigned long nr_segs, loff_t *pos) |
| 1095 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | compat_ssize_t tot_len; |
| 1097 | struct iovec iovstack[UIO_FASTIOV]; |
| 1098 | struct iovec *iov=iovstack, *vector; |
| 1099 | ssize_t ret; |
| 1100 | int seg; |
| 1101 | io_fn_t fn; |
| 1102 | iov_fn_t fnv; |
| 1103 | |
| 1104 | /* |
| 1105 | * SuS says "The readv() function *may* fail if the iovcnt argument |
| 1106 | * was less than or equal to 0, or greater than {IOV_MAX}. Linux has |
| 1107 | * traditionally returned zero for zero segments, so... |
| 1108 | */ |
| 1109 | ret = 0; |
| 1110 | if (nr_segs == 0) |
| 1111 | goto out; |
| 1112 | |
| 1113 | /* |
| 1114 | * First get the "struct iovec" from user memory and |
| 1115 | * verify all the pointers |
| 1116 | */ |
| 1117 | ret = -EINVAL; |
| 1118 | if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0)) |
| 1119 | goto out; |
| 1120 | if (!file->f_op) |
| 1121 | goto out; |
| 1122 | if (nr_segs > UIO_FASTIOV) { |
| 1123 | ret = -ENOMEM; |
| 1124 | iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL); |
| 1125 | if (!iov) |
| 1126 | goto out; |
| 1127 | } |
| 1128 | ret = -EFAULT; |
| 1129 | if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector))) |
| 1130 | goto out; |
| 1131 | |
| 1132 | /* |
| 1133 | * Single unix specification: |
| 1134 | * We should -EINVAL if an element length is not >= 0 and fitting an |
| 1135 | * ssize_t. The total length is fitting an ssize_t |
| 1136 | * |
| 1137 | * Be careful here because iov_len is a size_t not an ssize_t |
| 1138 | */ |
| 1139 | tot_len = 0; |
| 1140 | vector = iov; |
| 1141 | ret = -EINVAL; |
| 1142 | for (seg = 0 ; seg < nr_segs; seg++) { |
| 1143 | compat_ssize_t tmp = tot_len; |
| 1144 | compat_ssize_t len; |
| 1145 | compat_uptr_t buf; |
| 1146 | |
| 1147 | if (__get_user(len, &uvector->iov_len) || |
| 1148 | __get_user(buf, &uvector->iov_base)) { |
| 1149 | ret = -EFAULT; |
| 1150 | goto out; |
| 1151 | } |
| 1152 | if (len < 0) /* size_t not fitting an compat_ssize_t .. */ |
| 1153 | goto out; |
| 1154 | tot_len += len; |
| 1155 | if (tot_len < tmp) /* maths overflow on the compat_ssize_t */ |
| 1156 | goto out; |
| 1157 | vector->iov_base = compat_ptr(buf); |
| 1158 | vector->iov_len = (compat_size_t) len; |
| 1159 | uvector++; |
| 1160 | vector++; |
| 1161 | } |
| 1162 | if (tot_len == 0) { |
| 1163 | ret = 0; |
| 1164 | goto out; |
| 1165 | } |
| 1166 | |
| 1167 | ret = rw_verify_area(type, file, pos, tot_len); |
Linus Torvalds | e28cc71 | 2006-01-04 16:20:40 -0800 | [diff] [blame] | 1168 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | goto out; |
| 1170 | |
| 1171 | fnv = NULL; |
| 1172 | if (type == READ) { |
| 1173 | fn = file->f_op->read; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 1174 | fnv = file->f_op->aio_read; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | } else { |
| 1176 | fn = (io_fn_t)file->f_op->write; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 1177 | fnv = file->f_op->aio_write; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 1180 | if (fnv) |
| 1181 | ret = do_sync_readv_writev(file, iov, nr_segs, tot_len, |
| 1182 | pos, fnv); |
| 1183 | else |
| 1184 | ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | out: |
| 1187 | if (iov != iovstack) |
| 1188 | kfree(iov); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 1189 | if ((ret + (type == READ)) > 0) { |
Josef "Jeff" Sipek | 0f7fc9e | 2006-12-08 02:36:35 -0800 | [diff] [blame] | 1190 | struct dentry *dentry = file->f_path.dentry; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 1191 | if (type == READ) |
| 1192 | fsnotify_access(dentry); |
| 1193 | else |
| 1194 | fsnotify_modify(dentry); |
| 1195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | return ret; |
| 1197 | } |
| 1198 | |
| 1199 | asmlinkage ssize_t |
| 1200 | compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec, unsigned long vlen) |
| 1201 | { |
| 1202 | struct file *file; |
| 1203 | ssize_t ret = -EBADF; |
| 1204 | |
| 1205 | file = fget(fd); |
| 1206 | if (!file) |
| 1207 | return -EBADF; |
| 1208 | |
| 1209 | if (!(file->f_mode & FMODE_READ)) |
| 1210 | goto out; |
| 1211 | |
| 1212 | ret = -EINVAL; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 1213 | if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | goto out; |
| 1215 | |
| 1216 | ret = compat_do_readv_writev(READ, file, vec, vlen, &file->f_pos); |
| 1217 | |
| 1218 | out: |
Gerd Hoffmann | ca8a5bd | 2009-01-06 14:41:09 -0800 | [diff] [blame] | 1219 | if (ret > 0) |
| 1220 | add_rchar(current, ret); |
| 1221 | inc_syscr(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | fput(file); |
| 1223 | return ret; |
| 1224 | } |
| 1225 | |
| 1226 | asmlinkage ssize_t |
| 1227 | compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec, unsigned long vlen) |
| 1228 | { |
| 1229 | struct file *file; |
| 1230 | ssize_t ret = -EBADF; |
| 1231 | |
| 1232 | file = fget(fd); |
| 1233 | if (!file) |
| 1234 | return -EBADF; |
| 1235 | if (!(file->f_mode & FMODE_WRITE)) |
| 1236 | goto out; |
| 1237 | |
| 1238 | ret = -EINVAL; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 1239 | if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | goto out; |
| 1241 | |
| 1242 | ret = compat_do_readv_writev(WRITE, file, vec, vlen, &file->f_pos); |
| 1243 | |
| 1244 | out: |
Gerd Hoffmann | ca8a5bd | 2009-01-06 14:41:09 -0800 | [diff] [blame] | 1245 | if (ret > 0) |
| 1246 | add_wchar(current, ret); |
| 1247 | inc_syscw(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | fput(file); |
| 1249 | return ret; |
| 1250 | } |
| 1251 | |
Andi Kleen | d261020 | 2006-05-01 12:15:48 -0700 | [diff] [blame] | 1252 | asmlinkage long |
| 1253 | compat_sys_vmsplice(int fd, const struct compat_iovec __user *iov32, |
| 1254 | unsigned int nr_segs, unsigned int flags) |
| 1255 | { |
| 1256 | unsigned i; |
Al Viro | 90cbad6 | 2006-10-10 22:44:17 +0100 | [diff] [blame] | 1257 | struct iovec __user *iov; |
Jens Axboe | 98232d5 | 2006-05-04 09:13:49 +0200 | [diff] [blame] | 1258 | if (nr_segs > UIO_MAXIOV) |
Andi Kleen | d261020 | 2006-05-01 12:15:48 -0700 | [diff] [blame] | 1259 | return -EINVAL; |
| 1260 | iov = compat_alloc_user_space(nr_segs * sizeof(struct iovec)); |
| 1261 | for (i = 0; i < nr_segs; i++) { |
| 1262 | struct compat_iovec v; |
| 1263 | if (get_user(v.iov_base, &iov32[i].iov_base) || |
| 1264 | get_user(v.iov_len, &iov32[i].iov_len) || |
| 1265 | put_user(compat_ptr(v.iov_base), &iov[i].iov_base) || |
| 1266 | put_user(v.iov_len, &iov[i].iov_len)) |
| 1267 | return -EFAULT; |
| 1268 | } |
| 1269 | return sys_vmsplice(fd, iov, nr_segs, flags); |
| 1270 | } |
| 1271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | /* |
Miklos Szeredi | e922efc | 2005-09-06 15:18:25 -0700 | [diff] [blame] | 1273 | * Exactly like fs/open.c:sys_open(), except that it doesn't set the |
| 1274 | * O_LARGEFILE flag. |
| 1275 | */ |
| 1276 | asmlinkage long |
| 1277 | compat_sys_open(const char __user *filename, int flags, int mode) |
| 1278 | { |
Ulrich Drepper | 5590ff0 | 2006-01-18 17:43:53 -0800 | [diff] [blame] | 1279 | return do_sys_open(AT_FDCWD, filename, flags, mode); |
| 1280 | } |
| 1281 | |
| 1282 | /* |
| 1283 | * Exactly like fs/open.c:sys_openat(), except that it doesn't set the |
| 1284 | * O_LARGEFILE flag. |
| 1285 | */ |
| 1286 | asmlinkage long |
Stephen Rothwell | 9ad11ab | 2006-02-02 16:11:51 +1100 | [diff] [blame] | 1287 | compat_sys_openat(unsigned int dfd, const char __user *filename, int flags, int mode) |
Ulrich Drepper | 5590ff0 | 2006-01-18 17:43:53 -0800 | [diff] [blame] | 1288 | { |
| 1289 | return do_sys_open(dfd, filename, flags, mode); |
Miklos Szeredi | e922efc | 2005-09-06 15:18:25 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | * compat_count() counts the number of arguments/envelopes. It is basically |
| 1294 | * a copy of count() from fs/exec.c, except that it works with 32 bit argv |
| 1295 | * and envp pointers. |
| 1296 | */ |
| 1297 | static int compat_count(compat_uptr_t __user *argv, int max) |
| 1298 | { |
| 1299 | int i = 0; |
| 1300 | |
| 1301 | if (argv != NULL) { |
| 1302 | for (;;) { |
| 1303 | compat_uptr_t p; |
| 1304 | |
| 1305 | if (get_user(p, argv)) |
| 1306 | return -EFAULT; |
| 1307 | if (!p) |
| 1308 | break; |
| 1309 | argv++; |
Jason Baron | 362e666 | 2008-10-15 22:01:52 -0700 | [diff] [blame] | 1310 | if (i++ >= max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | return -E2BIG; |
| 1312 | } |
| 1313 | } |
| 1314 | return i; |
| 1315 | } |
| 1316 | |
| 1317 | /* |
| 1318 | * compat_copy_strings() is basically a copy of copy_strings() from fs/exec.c |
| 1319 | * except that it works with 32 bit argv and envp pointers. |
| 1320 | */ |
| 1321 | static int compat_copy_strings(int argc, compat_uptr_t __user *argv, |
| 1322 | struct linux_binprm *bprm) |
| 1323 | { |
| 1324 | struct page *kmapped_page = NULL; |
| 1325 | char *kaddr = NULL; |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1326 | unsigned long kpos = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | int ret; |
| 1328 | |
| 1329 | while (argc-- > 0) { |
| 1330 | compat_uptr_t str; |
| 1331 | int len; |
| 1332 | unsigned long pos; |
| 1333 | |
| 1334 | if (get_user(str, argv+argc) || |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1335 | !(len = strnlen_user(compat_ptr(str), MAX_ARG_STRLEN))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | ret = -EFAULT; |
| 1337 | goto out; |
| 1338 | } |
| 1339 | |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1340 | if (len > MAX_ARG_STRLEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | ret = -E2BIG; |
| 1342 | goto out; |
| 1343 | } |
| 1344 | |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1345 | /* We're going to work our way backwords. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | pos = bprm->p; |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1347 | str += len; |
| 1348 | bprm->p -= len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
| 1350 | while (len > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | int offset, bytes_to_copy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
| 1353 | offset = pos % PAGE_SIZE; |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1354 | if (offset == 0) |
| 1355 | offset = PAGE_SIZE; |
| 1356 | |
| 1357 | bytes_to_copy = offset; |
| 1358 | if (bytes_to_copy > len) |
| 1359 | bytes_to_copy = len; |
| 1360 | |
| 1361 | offset -= bytes_to_copy; |
| 1362 | pos -= bytes_to_copy; |
| 1363 | str -= bytes_to_copy; |
| 1364 | len -= bytes_to_copy; |
| 1365 | |
| 1366 | if (!kmapped_page || kpos != (pos & PAGE_MASK)) { |
| 1367 | struct page *page; |
| 1368 | |
| 1369 | #ifdef CONFIG_STACK_GROWSUP |
| 1370 | ret = expand_stack_downwards(bprm->vma, pos); |
| 1371 | if (ret < 0) { |
| 1372 | /* We've exceed the stack rlimit. */ |
| 1373 | ret = -E2BIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | goto out; |
| 1375 | } |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1376 | #endif |
| 1377 | ret = get_user_pages(current, bprm->mm, pos, |
| 1378 | 1, 1, 1, &page, NULL); |
| 1379 | if (ret <= 0) { |
| 1380 | /* We've exceed the stack rlimit. */ |
| 1381 | ret = -E2BIG; |
| 1382 | goto out; |
| 1383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1385 | if (kmapped_page) { |
| 1386 | flush_kernel_dcache_page(kmapped_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | kunmap(kmapped_page); |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1388 | put_page(kmapped_page); |
| 1389 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | kmapped_page = page; |
| 1391 | kaddr = kmap(kmapped_page); |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1392 | kpos = pos & PAGE_MASK; |
| 1393 | flush_cache_page(bprm->vma, kpos, |
| 1394 | page_to_pfn(kmapped_page)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | } |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1396 | if (copy_from_user(kaddr+offset, compat_ptr(str), |
| 1397 | bytes_to_copy)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | ret = -EFAULT; |
| 1399 | goto out; |
| 1400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | ret = 0; |
| 1404 | out: |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1405 | if (kmapped_page) { |
| 1406 | flush_kernel_dcache_page(kmapped_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | kunmap(kmapped_page); |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1408 | put_page(kmapped_page); |
| 1409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | return ret; |
| 1411 | } |
| 1412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | /* |
| 1414 | * compat_do_execve() is mostly a copy of do_execve(), with the exception |
| 1415 | * that it processes 32 bit argv and envp pointers. |
| 1416 | */ |
| 1417 | int compat_do_execve(char * filename, |
| 1418 | compat_uptr_t __user *argv, |
| 1419 | compat_uptr_t __user *envp, |
| 1420 | struct pt_regs * regs) |
| 1421 | { |
| 1422 | struct linux_binprm *bprm; |
| 1423 | struct file *file; |
Hugh Dickins | 53e9309 | 2009-03-28 23:16:03 +0000 | [diff] [blame] | 1424 | struct files_struct *displaced; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | |
Hugh Dickins | 53e9309 | 2009-03-28 23:16:03 +0000 | [diff] [blame] | 1427 | retval = unshare_files(&displaced); |
| 1428 | if (retval) |
| 1429 | goto out_ret; |
| 1430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | retval = -ENOMEM; |
Oliver Neukum | 11b0b5a | 2006-03-25 03:08:13 -0800 | [diff] [blame] | 1432 | bprm = kzalloc(sizeof(*bprm), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | if (!bprm) |
Hugh Dickins | 53e9309 | 2009-03-28 23:16:03 +0000 | [diff] [blame] | 1434 | goto out_files; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 1436 | retval = mutex_lock_interruptible(¤t->cred_exec_mutex); |
| 1437 | if (retval < 0) |
| 1438 | goto out_free; |
Kentaro Takeda | f9ce1f1 | 2009-02-05 17:18:11 +0900 | [diff] [blame] | 1439 | current->in_execve = 1; |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 1440 | |
| 1441 | retval = -ENOMEM; |
| 1442 | bprm->cred = prepare_exec_creds(); |
| 1443 | if (!bprm->cred) |
| 1444 | goto out_unlock; |
Al Viro | 498052b | 2009-03-30 07:20:30 -0400 | [diff] [blame^] | 1445 | |
| 1446 | retval = check_unsafe_exec(bprm); |
| 1447 | if (retval) |
| 1448 | goto out_unlock; |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 1449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | file = open_exec(filename); |
| 1451 | retval = PTR_ERR(file); |
| 1452 | if (IS_ERR(file)) |
Al Viro | 498052b | 2009-03-30 07:20:30 -0400 | [diff] [blame^] | 1453 | goto out_unmark; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
| 1455 | sched_exec(); |
| 1456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | bprm->file = file; |
| 1458 | bprm->filename = filename; |
| 1459 | bprm->interp = filename; |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1460 | |
| 1461 | retval = bprm_mm_init(bprm); |
| 1462 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | goto out_file; |
| 1464 | |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1465 | bprm->argc = compat_count(argv, MAX_ARG_STRINGS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | if ((retval = bprm->argc) < 0) |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 1467 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1469 | bprm->envc = compat_count(envp, MAX_ARG_STRINGS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | if ((retval = bprm->envc) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | goto out; |
| 1472 | |
| 1473 | retval = prepare_binprm(bprm); |
| 1474 | if (retval < 0) |
| 1475 | goto out; |
| 1476 | |
| 1477 | retval = copy_strings_kernel(1, &bprm->filename, bprm); |
| 1478 | if (retval < 0) |
| 1479 | goto out; |
| 1480 | |
| 1481 | bprm->exec = bprm->p; |
| 1482 | retval = compat_copy_strings(bprm->envc, envp, bprm); |
| 1483 | if (retval < 0) |
| 1484 | goto out; |
| 1485 | |
| 1486 | retval = compat_copy_strings(bprm->argc, argv, bprm); |
| 1487 | if (retval < 0) |
| 1488 | goto out; |
| 1489 | |
| 1490 | retval = search_binary_handler(bprm, regs); |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 1491 | if (retval < 0) |
| 1492 | goto out; |
| 1493 | |
| 1494 | /* execve succeeded */ |
Al Viro | 498052b | 2009-03-30 07:20:30 -0400 | [diff] [blame^] | 1495 | write_lock(¤t->fs->lock); |
| 1496 | current->fs->in_exec = 0; |
| 1497 | write_unlock(¤t->fs->lock); |
Kentaro Takeda | f9ce1f1 | 2009-02-05 17:18:11 +0900 | [diff] [blame] | 1498 | current->in_execve = 0; |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 1499 | mutex_unlock(¤t->cred_exec_mutex); |
| 1500 | acct_update_integrals(current); |
| 1501 | free_bprm(bprm); |
Hugh Dickins | 53e9309 | 2009-03-28 23:16:03 +0000 | [diff] [blame] | 1502 | if (displaced) |
| 1503 | put_files_struct(displaced); |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 1504 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
| 1506 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | if (bprm->mm) |
Ollie Wild | b6a2fea | 2007-07-19 01:48:16 -0700 | [diff] [blame] | 1508 | mmput(bprm->mm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | |
| 1510 | out_file: |
| 1511 | if (bprm->file) { |
| 1512 | allow_write_access(bprm->file); |
| 1513 | fput(bprm->file); |
| 1514 | } |
| 1515 | |
Al Viro | 498052b | 2009-03-30 07:20:30 -0400 | [diff] [blame^] | 1516 | out_unmark: |
| 1517 | write_lock(¤t->fs->lock); |
| 1518 | current->fs->in_exec = 0; |
| 1519 | write_unlock(¤t->fs->lock); |
| 1520 | |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 1521 | out_unlock: |
Kentaro Takeda | f9ce1f1 | 2009-02-05 17:18:11 +0900 | [diff] [blame] | 1522 | current->in_execve = 0; |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 1523 | mutex_unlock(¤t->cred_exec_mutex); |
| 1524 | |
| 1525 | out_free: |
Al Viro | 08a6fac | 2008-05-10 16:38:25 -0400 | [diff] [blame] | 1526 | free_bprm(bprm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | |
Hugh Dickins | 53e9309 | 2009-03-28 23:16:03 +0000 | [diff] [blame] | 1528 | out_files: |
| 1529 | if (displaced) |
| 1530 | reset_files_struct(displaced); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | out_ret: |
| 1532 | return retval; |
| 1533 | } |
| 1534 | |
| 1535 | #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t)) |
| 1536 | |
Thomas Gleixner | b773ad4 | 2008-08-31 08:16:57 -0700 | [diff] [blame] | 1537 | static int poll_select_copy_remaining(struct timespec *end_time, void __user *p, |
| 1538 | int timeval, int ret) |
| 1539 | { |
| 1540 | struct timespec ts; |
| 1541 | |
| 1542 | if (!p) |
| 1543 | return ret; |
| 1544 | |
| 1545 | if (current->personality & STICKY_TIMEOUTS) |
| 1546 | goto sticky; |
| 1547 | |
| 1548 | /* No update for zero timeout */ |
| 1549 | if (!end_time->tv_sec && !end_time->tv_nsec) |
| 1550 | return ret; |
| 1551 | |
| 1552 | ktime_get_ts(&ts); |
| 1553 | ts = timespec_sub(*end_time, ts); |
| 1554 | if (ts.tv_sec < 0) |
| 1555 | ts.tv_sec = ts.tv_nsec = 0; |
| 1556 | |
| 1557 | if (timeval) { |
| 1558 | struct compat_timeval rtv; |
| 1559 | |
| 1560 | rtv.tv_sec = ts.tv_sec; |
| 1561 | rtv.tv_usec = ts.tv_nsec / NSEC_PER_USEC; |
| 1562 | |
| 1563 | if (!copy_to_user(p, &rtv, sizeof(rtv))) |
| 1564 | return ret; |
| 1565 | } else { |
| 1566 | struct compat_timespec rts; |
| 1567 | |
| 1568 | rts.tv_sec = ts.tv_sec; |
| 1569 | rts.tv_nsec = ts.tv_nsec; |
| 1570 | |
| 1571 | if (!copy_to_user(p, &rts, sizeof(rts))) |
| 1572 | return ret; |
| 1573 | } |
| 1574 | /* |
| 1575 | * If an application puts its timeval in read-only memory, we |
| 1576 | * don't want the Linux-specific update to the timeval to |
| 1577 | * cause a fault after the select has completed |
| 1578 | * successfully. However, because we're not updating the |
| 1579 | * timeval, we can't restart the system call. |
| 1580 | */ |
| 1581 | |
| 1582 | sticky: |
| 1583 | if (ret == -ERESTARTNOHAND) |
| 1584 | ret = -EINTR; |
| 1585 | return ret; |
| 1586 | } |
| 1587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | /* |
| 1589 | * Ooo, nasty. We need here to frob 32-bit unsigned longs to |
| 1590 | * 64-bit unsigned longs. |
| 1591 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1592 | static |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | int compat_get_fd_set(unsigned long nr, compat_ulong_t __user *ufdset, |
| 1594 | unsigned long *fdset) |
| 1595 | { |
Milind Arun Choudhary | 022a169 | 2007-05-08 00:29:02 -0700 | [diff] [blame] | 1596 | nr = DIV_ROUND_UP(nr, __COMPAT_NFDBITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | if (ufdset) { |
| 1598 | unsigned long odd; |
| 1599 | |
| 1600 | if (!access_ok(VERIFY_WRITE, ufdset, nr*sizeof(compat_ulong_t))) |
| 1601 | return -EFAULT; |
| 1602 | |
| 1603 | odd = nr & 1UL; |
| 1604 | nr &= ~1UL; |
| 1605 | while (nr) { |
| 1606 | unsigned long h, l; |
Heiko Carstens | 7116e99 | 2006-12-06 20:36:36 -0800 | [diff] [blame] | 1607 | if (__get_user(l, ufdset) || __get_user(h, ufdset+1)) |
| 1608 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | ufdset += 2; |
| 1610 | *fdset++ = h << 32 | l; |
| 1611 | nr -= 2; |
| 1612 | } |
Heiko Carstens | 7116e99 | 2006-12-06 20:36:36 -0800 | [diff] [blame] | 1613 | if (odd && __get_user(*fdset, ufdset)) |
| 1614 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | } else { |
| 1616 | /* Tricky, must clear full unsigned long in the |
| 1617 | * kernel fdset at the end, this makes sure that |
| 1618 | * actually happens. |
| 1619 | */ |
| 1620 | memset(fdset, 0, ((nr + 1) & ~1)*sizeof(compat_ulong_t)); |
| 1621 | } |
| 1622 | return 0; |
| 1623 | } |
| 1624 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1625 | static |
Heiko Carstens | 7116e99 | 2006-12-06 20:36:36 -0800 | [diff] [blame] | 1626 | int compat_set_fd_set(unsigned long nr, compat_ulong_t __user *ufdset, |
| 1627 | unsigned long *fdset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | { |
| 1629 | unsigned long odd; |
Milind Arun Choudhary | 022a169 | 2007-05-08 00:29:02 -0700 | [diff] [blame] | 1630 | nr = DIV_ROUND_UP(nr, __COMPAT_NFDBITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | |
| 1632 | if (!ufdset) |
Heiko Carstens | 7116e99 | 2006-12-06 20:36:36 -0800 | [diff] [blame] | 1633 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | |
| 1635 | odd = nr & 1UL; |
| 1636 | nr &= ~1UL; |
| 1637 | while (nr) { |
| 1638 | unsigned long h, l; |
| 1639 | l = *fdset++; |
| 1640 | h = l >> 32; |
Heiko Carstens | 7116e99 | 2006-12-06 20:36:36 -0800 | [diff] [blame] | 1641 | if (__put_user(l, ufdset) || __put_user(h, ufdset+1)) |
| 1642 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | ufdset += 2; |
| 1644 | nr -= 2; |
| 1645 | } |
Heiko Carstens | 7116e99 | 2006-12-06 20:36:36 -0800 | [diff] [blame] | 1646 | if (odd && __put_user(*fdset, ufdset)) |
| 1647 | return -EFAULT; |
| 1648 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | |
| 1652 | /* |
| 1653 | * This is a virtual copy of sys_select from fs/select.c and probably |
| 1654 | * should be compared to it from time to time |
| 1655 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | |
| 1657 | /* |
| 1658 | * We can actually return ERESTARTSYS instead of EINTR, but I'd |
| 1659 | * like to be certain this leads to no problems. So I return |
| 1660 | * EINTR just for safety. |
| 1661 | * |
| 1662 | * Update: ERESTARTSYS breaks at least the xview clock binary, so |
| 1663 | * I'm trying ERESTARTNOHAND which restart only when you want to. |
| 1664 | */ |
| 1665 | #define MAX_SELECT_SECONDS \ |
| 1666 | ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1) |
| 1667 | |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1668 | int compat_core_sys_select(int n, compat_ulong_t __user *inp, |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1669 | compat_ulong_t __user *outp, compat_ulong_t __user *exp, |
| 1670 | struct timespec *end_time) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | { |
| 1672 | fd_set_bits fds; |
Badari Pulavarty | 6087b2d | 2007-05-23 13:57:45 -0700 | [diff] [blame] | 1673 | void *bits; |
Vadim Lobanov | bbea9f6 | 2006-12-10 02:21:12 -0800 | [diff] [blame] | 1674 | int size, max_fds, ret = -EINVAL; |
Linus Torvalds | a4531ed | 2005-09-09 15:10:52 -0700 | [diff] [blame] | 1675 | struct fdtable *fdt; |
Badari Pulavarty | 6087b2d | 2007-05-23 13:57:45 -0700 | [diff] [blame] | 1676 | long stack_fds[SELECT_STACK_ALLOC/sizeof(long)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | if (n < 0) |
| 1679 | goto out_nofds; |
| 1680 | |
Vadim Lobanov | bbea9f6 | 2006-12-10 02:21:12 -0800 | [diff] [blame] | 1681 | /* max_fds can increase, so grab it once to avoid race */ |
Linus Torvalds | ac5b8b6 | 2005-09-09 15:42:34 -0700 | [diff] [blame] | 1682 | rcu_read_lock(); |
Linus Torvalds | a4531ed | 2005-09-09 15:10:52 -0700 | [diff] [blame] | 1683 | fdt = files_fdtable(current->files); |
Vadim Lobanov | bbea9f6 | 2006-12-10 02:21:12 -0800 | [diff] [blame] | 1684 | max_fds = fdt->max_fds; |
Linus Torvalds | ac5b8b6 | 2005-09-09 15:42:34 -0700 | [diff] [blame] | 1685 | rcu_read_unlock(); |
Vadim Lobanov | bbea9f6 | 2006-12-10 02:21:12 -0800 | [diff] [blame] | 1686 | if (n > max_fds) |
| 1687 | n = max_fds; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | |
| 1689 | /* |
| 1690 | * We need 6 bitmaps (in/out/ex for both incoming and outgoing), |
| 1691 | * since we used fdset we need to allocate memory in units of |
| 1692 | * long-words. |
| 1693 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | size = FDS_BYTES(n); |
Badari Pulavarty | 6087b2d | 2007-05-23 13:57:45 -0700 | [diff] [blame] | 1695 | bits = stack_fds; |
| 1696 | if (size > sizeof(stack_fds) / 6) { |
| 1697 | bits = kmalloc(6 * size, GFP_KERNEL); |
| 1698 | ret = -ENOMEM; |
| 1699 | if (!bits) |
| 1700 | goto out_nofds; |
| 1701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | fds.in = (unsigned long *) bits; |
| 1703 | fds.out = (unsigned long *) (bits + size); |
| 1704 | fds.ex = (unsigned long *) (bits + 2*size); |
| 1705 | fds.res_in = (unsigned long *) (bits + 3*size); |
| 1706 | fds.res_out = (unsigned long *) (bits + 4*size); |
| 1707 | fds.res_ex = (unsigned long *) (bits + 5*size); |
| 1708 | |
| 1709 | if ((ret = compat_get_fd_set(n, inp, fds.in)) || |
| 1710 | (ret = compat_get_fd_set(n, outp, fds.out)) || |
| 1711 | (ret = compat_get_fd_set(n, exp, fds.ex))) |
| 1712 | goto out; |
| 1713 | zero_fd_set(n, fds.res_in); |
| 1714 | zero_fd_set(n, fds.res_out); |
| 1715 | zero_fd_set(n, fds.res_ex); |
| 1716 | |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1717 | ret = do_select(n, &fds, end_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | |
| 1719 | if (ret < 0) |
| 1720 | goto out; |
| 1721 | if (!ret) { |
| 1722 | ret = -ERESTARTNOHAND; |
| 1723 | if (signal_pending(current)) |
| 1724 | goto out; |
| 1725 | ret = 0; |
| 1726 | } |
| 1727 | |
Heiko Carstens | 7116e99 | 2006-12-06 20:36:36 -0800 | [diff] [blame] | 1728 | if (compat_set_fd_set(n, inp, fds.res_in) || |
| 1729 | compat_set_fd_set(n, outp, fds.res_out) || |
| 1730 | compat_set_fd_set(n, exp, fds.res_ex)) |
| 1731 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | out: |
Badari Pulavarty | 6087b2d | 2007-05-23 13:57:45 -0700 | [diff] [blame] | 1733 | if (bits != stack_fds) |
| 1734 | kfree(bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | out_nofds: |
| 1736 | return ret; |
| 1737 | } |
| 1738 | |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1739 | asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp, |
| 1740 | compat_ulong_t __user *outp, compat_ulong_t __user *exp, |
| 1741 | struct compat_timeval __user *tvp) |
| 1742 | { |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1743 | struct timespec end_time, *to = NULL; |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1744 | struct compat_timeval tv; |
| 1745 | int ret; |
| 1746 | |
| 1747 | if (tvp) { |
| 1748 | if (copy_from_user(&tv, tvp, sizeof(tv))) |
| 1749 | return -EFAULT; |
| 1750 | |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1751 | to = &end_time; |
Arjan van de Ven | 4d36a9e | 2008-10-25 12:41:41 -0700 | [diff] [blame] | 1752 | if (poll_select_set_timeout(to, |
| 1753 | tv.tv_sec + (tv.tv_usec / USEC_PER_SEC), |
| 1754 | (tv.tv_usec % USEC_PER_SEC) * NSEC_PER_USEC)) |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1755 | return -EINVAL; |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1756 | } |
| 1757 | |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1758 | ret = compat_core_sys_select(n, inp, outp, exp, to); |
| 1759 | ret = poll_select_copy_remaining(&end_time, tvp, 1, ret); |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1760 | |
| 1761 | return ret; |
| 1762 | } |
| 1763 | |
Roland McGrath | f3de272 | 2008-04-30 00:53:09 -0700 | [diff] [blame] | 1764 | #ifdef HAVE_SET_RESTORE_SIGMASK |
Heiko Carstens | c9da9f2 | 2009-01-14 14:13:57 +0100 | [diff] [blame] | 1765 | static long do_compat_pselect(int n, compat_ulong_t __user *inp, |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1766 | compat_ulong_t __user *outp, compat_ulong_t __user *exp, |
| 1767 | struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask, |
| 1768 | compat_size_t sigsetsize) |
| 1769 | { |
| 1770 | compat_sigset_t ss32; |
| 1771 | sigset_t ksigmask, sigsaved; |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1772 | struct compat_timespec ts; |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1773 | struct timespec end_time, *to = NULL; |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1774 | int ret; |
| 1775 | |
| 1776 | if (tsp) { |
| 1777 | if (copy_from_user(&ts, tsp, sizeof(ts))) |
| 1778 | return -EFAULT; |
| 1779 | |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1780 | to = &end_time; |
| 1781 | if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec)) |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1782 | return -EINVAL; |
| 1783 | } |
| 1784 | |
| 1785 | if (sigmask) { |
| 1786 | if (sigsetsize != sizeof(compat_sigset_t)) |
| 1787 | return -EINVAL; |
| 1788 | if (copy_from_user(&ss32, sigmask, sizeof(ss32))) |
| 1789 | return -EFAULT; |
| 1790 | sigset_from_compat(&ksigmask, &ss32); |
| 1791 | |
| 1792 | sigdelsetmask(&ksigmask, sigmask(SIGKILL)|sigmask(SIGSTOP)); |
| 1793 | sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved); |
| 1794 | } |
| 1795 | |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1796 | ret = compat_core_sys_select(n, inp, outp, exp, to); |
| 1797 | ret = poll_select_copy_remaining(&end_time, tsp, 0, ret); |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1798 | |
| 1799 | if (ret == -ERESTARTNOHAND) { |
| 1800 | /* |
| 1801 | * Don't restore the signal mask yet. Let do_signal() deliver |
| 1802 | * the signal on the way back to userspace, before the signal |
| 1803 | * mask is restored. |
| 1804 | */ |
| 1805 | if (sigmask) { |
| 1806 | memcpy(¤t->saved_sigmask, &sigsaved, |
| 1807 | sizeof(sigsaved)); |
Roland McGrath | 4e4c22c | 2008-04-30 00:53:06 -0700 | [diff] [blame] | 1808 | set_restore_sigmask(); |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1809 | } |
| 1810 | } else if (sigmask) |
| 1811 | sigprocmask(SIG_SETMASK, &sigsaved, NULL); |
| 1812 | |
| 1813 | return ret; |
| 1814 | } |
| 1815 | |
| 1816 | asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp, |
| 1817 | compat_ulong_t __user *outp, compat_ulong_t __user *exp, |
| 1818 | struct compat_timespec __user *tsp, void __user *sig) |
| 1819 | { |
| 1820 | compat_size_t sigsetsize = 0; |
| 1821 | compat_uptr_t up = 0; |
| 1822 | |
| 1823 | if (sig) { |
| 1824 | if (!access_ok(VERIFY_READ, sig, |
| 1825 | sizeof(compat_uptr_t)+sizeof(compat_size_t)) || |
| 1826 | __get_user(up, (compat_uptr_t __user *)sig) || |
| 1827 | __get_user(sigsetsize, |
| 1828 | (compat_size_t __user *)(sig+sizeof(up)))) |
| 1829 | return -EFAULT; |
| 1830 | } |
Heiko Carstens | c9da9f2 | 2009-01-14 14:13:57 +0100 | [diff] [blame] | 1831 | return do_compat_pselect(n, inp, outp, exp, tsp, compat_ptr(up), |
| 1832 | sigsetsize); |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds, |
| 1836 | unsigned int nfds, struct compat_timespec __user *tsp, |
| 1837 | const compat_sigset_t __user *sigmask, compat_size_t sigsetsize) |
| 1838 | { |
| 1839 | compat_sigset_t ss32; |
| 1840 | sigset_t ksigmask, sigsaved; |
| 1841 | struct compat_timespec ts; |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1842 | struct timespec end_time, *to = NULL; |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1843 | int ret; |
| 1844 | |
| 1845 | if (tsp) { |
| 1846 | if (copy_from_user(&ts, tsp, sizeof(ts))) |
| 1847 | return -EFAULT; |
| 1848 | |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1849 | to = &end_time; |
| 1850 | if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec)) |
| 1851 | return -EINVAL; |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | if (sigmask) { |
Alexey Dobriyan | 3835a9b | 2006-05-15 09:44:27 -0700 | [diff] [blame] | 1855 | if (sigsetsize != sizeof(compat_sigset_t)) |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1856 | return -EINVAL; |
| 1857 | if (copy_from_user(&ss32, sigmask, sizeof(ss32))) |
| 1858 | return -EFAULT; |
| 1859 | sigset_from_compat(&ksigmask, &ss32); |
| 1860 | |
| 1861 | sigdelsetmask(&ksigmask, sigmask(SIGKILL)|sigmask(SIGSTOP)); |
| 1862 | sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved); |
| 1863 | } |
| 1864 | |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1865 | ret = do_sys_poll(ufds, nfds, to); |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1866 | |
| 1867 | /* We can restart this syscall, usually */ |
| 1868 | if (ret == -EINTR) { |
| 1869 | /* |
| 1870 | * Don't restore the signal mask yet. Let do_signal() deliver |
| 1871 | * the signal on the way back to userspace, before the signal |
| 1872 | * mask is restored. |
| 1873 | */ |
| 1874 | if (sigmask) { |
| 1875 | memcpy(¤t->saved_sigmask, &sigsaved, |
| 1876 | sizeof(sigsaved)); |
Roland McGrath | 4e4c22c | 2008-04-30 00:53:06 -0700 | [diff] [blame] | 1877 | set_restore_sigmask(); |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1878 | } |
| 1879 | ret = -ERESTARTNOHAND; |
| 1880 | } else if (sigmask) |
| 1881 | sigprocmask(SIG_SETMASK, &sigsaved, NULL); |
| 1882 | |
Arjan van de Ven | 8ff3e8e | 2008-08-31 08:26:40 -0700 | [diff] [blame] | 1883 | ret = poll_select_copy_remaining(&end_time, tsp, 0, ret); |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1884 | |
| 1885 | return ret; |
| 1886 | } |
Roland McGrath | f3de272 | 2008-04-30 00:53:09 -0700 | [diff] [blame] | 1887 | #endif /* HAVE_SET_RESTORE_SIGMASK */ |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 1888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE) |
| 1890 | /* Stuff for NFS server syscalls... */ |
| 1891 | struct compat_nfsctl_svc { |
| 1892 | u16 svc32_port; |
| 1893 | s32 svc32_nthreads; |
| 1894 | }; |
| 1895 | |
| 1896 | struct compat_nfsctl_client { |
| 1897 | s8 cl32_ident[NFSCLNT_IDMAX+1]; |
| 1898 | s32 cl32_naddr; |
| 1899 | struct in_addr cl32_addrlist[NFSCLNT_ADDRMAX]; |
| 1900 | s32 cl32_fhkeytype; |
| 1901 | s32 cl32_fhkeylen; |
| 1902 | u8 cl32_fhkey[NFSCLNT_KEYMAX]; |
| 1903 | }; |
| 1904 | |
| 1905 | struct compat_nfsctl_export { |
| 1906 | char ex32_client[NFSCLNT_IDMAX+1]; |
| 1907 | char ex32_path[NFS_MAXPATHLEN+1]; |
| 1908 | compat_dev_t ex32_dev; |
| 1909 | compat_ino_t ex32_ino; |
| 1910 | compat_int_t ex32_flags; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 1911 | __compat_uid_t ex32_anon_uid; |
| 1912 | __compat_gid_t ex32_anon_gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | }; |
| 1914 | |
| 1915 | struct compat_nfsctl_fdparm { |
| 1916 | struct sockaddr gd32_addr; |
| 1917 | s8 gd32_path[NFS_MAXPATHLEN+1]; |
| 1918 | compat_int_t gd32_version; |
| 1919 | }; |
| 1920 | |
| 1921 | struct compat_nfsctl_fsparm { |
| 1922 | struct sockaddr gd32_addr; |
| 1923 | s8 gd32_path[NFS_MAXPATHLEN+1]; |
| 1924 | compat_int_t gd32_maxlen; |
| 1925 | }; |
| 1926 | |
| 1927 | struct compat_nfsctl_arg { |
| 1928 | compat_int_t ca32_version; /* safeguard */ |
| 1929 | union { |
| 1930 | struct compat_nfsctl_svc u32_svc; |
| 1931 | struct compat_nfsctl_client u32_client; |
| 1932 | struct compat_nfsctl_export u32_export; |
| 1933 | struct compat_nfsctl_fdparm u32_getfd; |
| 1934 | struct compat_nfsctl_fsparm u32_getfs; |
| 1935 | } u; |
| 1936 | #define ca32_svc u.u32_svc |
| 1937 | #define ca32_client u.u32_client |
| 1938 | #define ca32_export u.u32_export |
| 1939 | #define ca32_getfd u.u32_getfd |
| 1940 | #define ca32_getfs u.u32_getfs |
| 1941 | }; |
| 1942 | |
| 1943 | union compat_nfsctl_res { |
| 1944 | __u8 cr32_getfh[NFS_FHSIZE]; |
| 1945 | struct knfsd_fh cr32_getfs; |
| 1946 | }; |
| 1947 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 1948 | static int compat_nfs_svc_trans(struct nfsctl_arg *karg, |
| 1949 | struct compat_nfsctl_arg __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | { |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 1951 | if (!access_ok(VERIFY_READ, &arg->ca32_svc, sizeof(arg->ca32_svc)) || |
| 1952 | get_user(karg->ca_version, &arg->ca32_version) || |
| 1953 | __get_user(karg->ca_svc.svc_port, &arg->ca32_svc.svc32_port) || |
| 1954 | __get_user(karg->ca_svc.svc_nthreads, |
| 1955 | &arg->ca32_svc.svc32_nthreads)) |
| 1956 | return -EFAULT; |
| 1957 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 1960 | static int compat_nfs_clnt_trans(struct nfsctl_arg *karg, |
| 1961 | struct compat_nfsctl_arg __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | { |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 1963 | if (!access_ok(VERIFY_READ, &arg->ca32_client, |
| 1964 | sizeof(arg->ca32_client)) || |
| 1965 | get_user(karg->ca_version, &arg->ca32_version) || |
| 1966 | __copy_from_user(&karg->ca_client.cl_ident[0], |
| 1967 | &arg->ca32_client.cl32_ident[0], |
| 1968 | NFSCLNT_IDMAX) || |
| 1969 | __get_user(karg->ca_client.cl_naddr, |
| 1970 | &arg->ca32_client.cl32_naddr) || |
| 1971 | __copy_from_user(&karg->ca_client.cl_addrlist[0], |
| 1972 | &arg->ca32_client.cl32_addrlist[0], |
| 1973 | (sizeof(struct in_addr) * NFSCLNT_ADDRMAX)) || |
| 1974 | __get_user(karg->ca_client.cl_fhkeytype, |
| 1975 | &arg->ca32_client.cl32_fhkeytype) || |
| 1976 | __get_user(karg->ca_client.cl_fhkeylen, |
| 1977 | &arg->ca32_client.cl32_fhkeylen) || |
| 1978 | __copy_from_user(&karg->ca_client.cl_fhkey[0], |
| 1979 | &arg->ca32_client.cl32_fhkey[0], |
| 1980 | NFSCLNT_KEYMAX)) |
| 1981 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 1983 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 1986 | static int compat_nfs_exp_trans(struct nfsctl_arg *karg, |
| 1987 | struct compat_nfsctl_arg __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | { |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 1989 | if (!access_ok(VERIFY_READ, &arg->ca32_export, |
| 1990 | sizeof(arg->ca32_export)) || |
| 1991 | get_user(karg->ca_version, &arg->ca32_version) || |
| 1992 | __copy_from_user(&karg->ca_export.ex_client[0], |
| 1993 | &arg->ca32_export.ex32_client[0], |
| 1994 | NFSCLNT_IDMAX) || |
| 1995 | __copy_from_user(&karg->ca_export.ex_path[0], |
| 1996 | &arg->ca32_export.ex32_path[0], |
| 1997 | NFS_MAXPATHLEN) || |
| 1998 | __get_user(karg->ca_export.ex_dev, |
| 1999 | &arg->ca32_export.ex32_dev) || |
| 2000 | __get_user(karg->ca_export.ex_ino, |
| 2001 | &arg->ca32_export.ex32_ino) || |
| 2002 | __get_user(karg->ca_export.ex_flags, |
| 2003 | &arg->ca32_export.ex32_flags) || |
| 2004 | __get_user(karg->ca_export.ex_anon_uid, |
| 2005 | &arg->ca32_export.ex32_anon_uid) || |
| 2006 | __get_user(karg->ca_export.ex_anon_gid, |
| 2007 | &arg->ca32_export.ex32_anon_gid)) |
| 2008 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | SET_UID(karg->ca_export.ex_anon_uid, karg->ca_export.ex_anon_uid); |
| 2010 | SET_GID(karg->ca_export.ex_anon_gid, karg->ca_export.ex_anon_gid); |
| 2011 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 2012 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 2015 | static int compat_nfs_getfd_trans(struct nfsctl_arg *karg, |
| 2016 | struct compat_nfsctl_arg __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | { |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 2018 | if (!access_ok(VERIFY_READ, &arg->ca32_getfd, |
| 2019 | sizeof(arg->ca32_getfd)) || |
| 2020 | get_user(karg->ca_version, &arg->ca32_version) || |
| 2021 | __copy_from_user(&karg->ca_getfd.gd_addr, |
| 2022 | &arg->ca32_getfd.gd32_addr, |
| 2023 | (sizeof(struct sockaddr))) || |
| 2024 | __copy_from_user(&karg->ca_getfd.gd_path, |
| 2025 | &arg->ca32_getfd.gd32_path, |
| 2026 | (NFS_MAXPATHLEN+1)) || |
| 2027 | __get_user(karg->ca_getfd.gd_version, |
| 2028 | &arg->ca32_getfd.gd32_version)) |
| 2029 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 2031 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 2034 | static int compat_nfs_getfs_trans(struct nfsctl_arg *karg, |
| 2035 | struct compat_nfsctl_arg __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | { |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 2037 | if (!access_ok(VERIFY_READ,&arg->ca32_getfs,sizeof(arg->ca32_getfs)) || |
| 2038 | get_user(karg->ca_version, &arg->ca32_version) || |
| 2039 | __copy_from_user(&karg->ca_getfs.gd_addr, |
| 2040 | &arg->ca32_getfs.gd32_addr, |
| 2041 | (sizeof(struct sockaddr))) || |
| 2042 | __copy_from_user(&karg->ca_getfs.gd_path, |
| 2043 | &arg->ca32_getfs.gd32_path, |
| 2044 | (NFS_MAXPATHLEN+1)) || |
| 2045 | __get_user(karg->ca_getfs.gd_maxlen, |
| 2046 | &arg->ca32_getfs.gd32_maxlen)) |
| 2047 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 2049 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | /* This really doesn't need translations, we are only passing |
| 2053 | * back a union which contains opaque nfs file handle data. |
| 2054 | */ |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 2055 | static int compat_nfs_getfh_res_trans(union nfsctl_res *kres, |
| 2056 | union compat_nfsctl_res __user *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | { |
| 2058 | int err; |
| 2059 | |
| 2060 | err = copy_to_user(res, kres, sizeof(*res)); |
| 2061 | |
| 2062 | return (err) ? -EFAULT : 0; |
| 2063 | } |
| 2064 | |
Lin Feng Shen | d64b1c8 | 2006-05-20 14:59:49 -0700 | [diff] [blame] | 2065 | asmlinkage long compat_sys_nfsservctl(int cmd, |
| 2066 | struct compat_nfsctl_arg __user *arg, |
| 2067 | union compat_nfsctl_res __user *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | { |
| 2069 | struct nfsctl_arg *karg; |
| 2070 | union nfsctl_res *kres; |
| 2071 | mm_segment_t oldfs; |
| 2072 | int err; |
| 2073 | |
| 2074 | karg = kmalloc(sizeof(*karg), GFP_USER); |
| 2075 | kres = kmalloc(sizeof(*kres), GFP_USER); |
| 2076 | if(!karg || !kres) { |
| 2077 | err = -ENOMEM; |
| 2078 | goto done; |
| 2079 | } |
| 2080 | |
| 2081 | switch(cmd) { |
| 2082 | case NFSCTL_SVC: |
| 2083 | err = compat_nfs_svc_trans(karg, arg); |
| 2084 | break; |
| 2085 | |
| 2086 | case NFSCTL_ADDCLIENT: |
| 2087 | err = compat_nfs_clnt_trans(karg, arg); |
| 2088 | break; |
| 2089 | |
| 2090 | case NFSCTL_DELCLIENT: |
| 2091 | err = compat_nfs_clnt_trans(karg, arg); |
| 2092 | break; |
| 2093 | |
| 2094 | case NFSCTL_EXPORT: |
| 2095 | case NFSCTL_UNEXPORT: |
| 2096 | err = compat_nfs_exp_trans(karg, arg); |
| 2097 | break; |
| 2098 | |
| 2099 | case NFSCTL_GETFD: |
| 2100 | err = compat_nfs_getfd_trans(karg, arg); |
| 2101 | break; |
| 2102 | |
| 2103 | case NFSCTL_GETFS: |
| 2104 | err = compat_nfs_getfs_trans(karg, arg); |
| 2105 | break; |
| 2106 | |
| 2107 | default: |
| 2108 | err = -EINVAL; |
Peter Staubach | 57070d0 | 2006-03-25 03:08:04 -0800 | [diff] [blame] | 2109 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Peter Staubach | 57070d0 | 2006-03-25 03:08:04 -0800 | [diff] [blame] | 2112 | if (err) |
| 2113 | goto done; |
| 2114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | oldfs = get_fs(); |
| 2116 | set_fs(KERNEL_DS); |
| 2117 | /* The __user pointer casts are valid because of the set_fs() */ |
| 2118 | err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres); |
| 2119 | set_fs(oldfs); |
| 2120 | |
| 2121 | if (err) |
| 2122 | goto done; |
| 2123 | |
| 2124 | if((cmd == NFSCTL_GETFD) || |
| 2125 | (cmd == NFSCTL_GETFS)) |
| 2126 | err = compat_nfs_getfh_res_trans(kres, res); |
| 2127 | |
| 2128 | done: |
| 2129 | kfree(karg); |
| 2130 | kfree(kres); |
| 2131 | return err; |
| 2132 | } |
| 2133 | #else /* !NFSD */ |
| 2134 | long asmlinkage compat_sys_nfsservctl(int cmd, void *notused, void *notused2) |
| 2135 | { |
| 2136 | return sys_ni_syscall(); |
| 2137 | } |
| 2138 | #endif |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 2139 | |
| 2140 | #ifdef CONFIG_EPOLL |
| 2141 | |
Roland McGrath | f3de272 | 2008-04-30 00:53:09 -0700 | [diff] [blame] | 2142 | #ifdef HAVE_SET_RESTORE_SIGMASK |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 2143 | asmlinkage long compat_sys_epoll_pwait(int epfd, |
| 2144 | struct compat_epoll_event __user *events, |
| 2145 | int maxevents, int timeout, |
| 2146 | const compat_sigset_t __user *sigmask, |
| 2147 | compat_size_t sigsetsize) |
| 2148 | { |
| 2149 | long err; |
| 2150 | compat_sigset_t csigmask; |
| 2151 | sigset_t ksigmask, sigsaved; |
| 2152 | |
| 2153 | /* |
| 2154 | * If the caller wants a certain signal mask to be set during the wait, |
| 2155 | * we apply it here. |
| 2156 | */ |
| 2157 | if (sigmask) { |
| 2158 | if (sigsetsize != sizeof(compat_sigset_t)) |
| 2159 | return -EINVAL; |
| 2160 | if (copy_from_user(&csigmask, sigmask, sizeof(csigmask))) |
| 2161 | return -EFAULT; |
| 2162 | sigset_from_compat(&ksigmask, &csigmask); |
| 2163 | sigdelsetmask(&ksigmask, sigmask(SIGKILL) | sigmask(SIGSTOP)); |
| 2164 | sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved); |
| 2165 | } |
| 2166 | |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 2167 | err = sys_epoll_wait(epfd, events, maxevents, timeout); |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 2168 | |
| 2169 | /* |
| 2170 | * If we changed the signal mask, we need to restore the original one. |
| 2171 | * In case we've got a signal while waiting, we do not restore the |
| 2172 | * signal mask yet, and we allow do_signal() to deliver the signal on |
| 2173 | * the way back to userspace, before the signal mask is restored. |
| 2174 | */ |
| 2175 | if (sigmask) { |
| 2176 | if (err == -EINTR) { |
| 2177 | memcpy(¤t->saved_sigmask, &sigsaved, |
| 2178 | sizeof(sigsaved)); |
Roland McGrath | 4e4c22c | 2008-04-30 00:53:06 -0700 | [diff] [blame] | 2179 | set_restore_sigmask(); |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 2180 | } else |
| 2181 | sigprocmask(SIG_SETMASK, &sigsaved, NULL); |
| 2182 | } |
| 2183 | |
| 2184 | return err; |
| 2185 | } |
Roland McGrath | f3de272 | 2008-04-30 00:53:09 -0700 | [diff] [blame] | 2186 | #endif /* HAVE_SET_RESTORE_SIGMASK */ |
Davide Libenzi | f6dfb4f | 2007-03-07 20:41:21 -0800 | [diff] [blame] | 2187 | |
| 2188 | #endif /* CONFIG_EPOLL */ |
Davide Libenzi | 6d18c92 | 2007-05-10 22:23:15 -0700 | [diff] [blame] | 2189 | |
| 2190 | #ifdef CONFIG_SIGNALFD |
| 2191 | |
Ulrich Drepper | 9deb27b | 2008-07-23 21:29:24 -0700 | [diff] [blame] | 2192 | asmlinkage long compat_sys_signalfd4(int ufd, |
| 2193 | const compat_sigset_t __user *sigmask, |
| 2194 | compat_size_t sigsetsize, int flags) |
Davide Libenzi | 6d18c92 | 2007-05-10 22:23:15 -0700 | [diff] [blame] | 2195 | { |
| 2196 | compat_sigset_t ss32; |
| 2197 | sigset_t tmp; |
| 2198 | sigset_t __user *ksigmask; |
| 2199 | |
| 2200 | if (sigsetsize != sizeof(compat_sigset_t)) |
| 2201 | return -EINVAL; |
| 2202 | if (copy_from_user(&ss32, sigmask, sizeof(ss32))) |
| 2203 | return -EFAULT; |
| 2204 | sigset_from_compat(&tmp, &ss32); |
| 2205 | ksigmask = compat_alloc_user_space(sizeof(sigset_t)); |
| 2206 | if (copy_to_user(ksigmask, &tmp, sizeof(sigset_t))) |
| 2207 | return -EFAULT; |
| 2208 | |
Ulrich Drepper | 9deb27b | 2008-07-23 21:29:24 -0700 | [diff] [blame] | 2209 | return sys_signalfd4(ufd, ksigmask, sizeof(sigset_t), flags); |
Davide Libenzi | 6d18c92 | 2007-05-10 22:23:15 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
Ulrich Drepper | 9deb27b | 2008-07-23 21:29:24 -0700 | [diff] [blame] | 2212 | asmlinkage long compat_sys_signalfd(int ufd, |
| 2213 | const compat_sigset_t __user *sigmask, |
| 2214 | compat_size_t sigsetsize) |
| 2215 | { |
| 2216 | return compat_sys_signalfd4(ufd, sigmask, sigsetsize, 0); |
| 2217 | } |
Davide Libenzi | 6d18c92 | 2007-05-10 22:23:15 -0700 | [diff] [blame] | 2218 | #endif /* CONFIG_SIGNALFD */ |
| 2219 | |
Davide Libenzi | 83f5d12 | 2007-05-10 22:23:18 -0700 | [diff] [blame] | 2220 | #ifdef CONFIG_TIMERFD |
| 2221 | |
Davide Libenzi | 4d672e7 | 2008-02-04 22:27:26 -0800 | [diff] [blame] | 2222 | asmlinkage long compat_sys_timerfd_settime(int ufd, int flags, |
| 2223 | const struct compat_itimerspec __user *utmr, |
| 2224 | struct compat_itimerspec __user *otmr) |
Davide Libenzi | 83f5d12 | 2007-05-10 22:23:18 -0700 | [diff] [blame] | 2225 | { |
Davide Libenzi | 4d672e7 | 2008-02-04 22:27:26 -0800 | [diff] [blame] | 2226 | int error; |
Davide Libenzi | 83f5d12 | 2007-05-10 22:23:18 -0700 | [diff] [blame] | 2227 | struct itimerspec t; |
| 2228 | struct itimerspec __user *ut; |
| 2229 | |
Davide Libenzi | 83f5d12 | 2007-05-10 22:23:18 -0700 | [diff] [blame] | 2230 | if (get_compat_itimerspec(&t, utmr)) |
Heiko Carstens | 8317f14 | 2007-05-16 22:11:08 -0700 | [diff] [blame] | 2231 | return -EFAULT; |
Davide Libenzi | 4d672e7 | 2008-02-04 22:27:26 -0800 | [diff] [blame] | 2232 | ut = compat_alloc_user_space(2 * sizeof(struct itimerspec)); |
| 2233 | if (copy_to_user(&ut[0], &t, sizeof(t))) |
Heiko Carstens | 8317f14 | 2007-05-16 22:11:08 -0700 | [diff] [blame] | 2234 | return -EFAULT; |
Davide Libenzi | 4d672e7 | 2008-02-04 22:27:26 -0800 | [diff] [blame] | 2235 | error = sys_timerfd_settime(ufd, flags, &ut[0], &ut[1]); |
| 2236 | if (!error && otmr) |
| 2237 | error = (copy_from_user(&t, &ut[1], sizeof(struct itimerspec)) || |
| 2238 | put_compat_itimerspec(otmr, &t)) ? -EFAULT: 0; |
Davide Libenzi | 83f5d12 | 2007-05-10 22:23:18 -0700 | [diff] [blame] | 2239 | |
Davide Libenzi | 4d672e7 | 2008-02-04 22:27:26 -0800 | [diff] [blame] | 2240 | return error; |
| 2241 | } |
| 2242 | |
| 2243 | asmlinkage long compat_sys_timerfd_gettime(int ufd, |
| 2244 | struct compat_itimerspec __user *otmr) |
| 2245 | { |
| 2246 | int error; |
| 2247 | struct itimerspec t; |
| 2248 | struct itimerspec __user *ut; |
| 2249 | |
| 2250 | ut = compat_alloc_user_space(sizeof(struct itimerspec)); |
| 2251 | error = sys_timerfd_gettime(ufd, ut); |
| 2252 | if (!error) |
| 2253 | error = (copy_from_user(&t, ut, sizeof(struct itimerspec)) || |
| 2254 | put_compat_itimerspec(otmr, &t)) ? -EFAULT: 0; |
| 2255 | |
| 2256 | return error; |
Davide Libenzi | 83f5d12 | 2007-05-10 22:23:18 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | #endif /* CONFIG_TIMERFD */ |