| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
#include <linux/linkage.h> |
|---|
| 19 |
#include <linux/compat.h> |
|---|
| 20 |
#include <linux/errno.h> |
|---|
| 21 |
#include <linux/time.h> |
|---|
| 22 |
#include <linux/fs.h> |
|---|
| 23 |
#include <linux/fcntl.h> |
|---|
| 24 |
#include <linux/namei.h> |
|---|
| 25 |
#include <linux/file.h> |
|---|
| 26 |
#include <linux/vfs.h> |
|---|
| 27 |
#include <linux/ioctl32.h> |
|---|
| 28 |
#include <linux/init.h> |
|---|
| 29 |
#include <linux/sockios.h> |
|---|
| 30 |
#include <linux/smb.h> |
|---|
| 31 |
#include <linux/smb_mount.h> |
|---|
| 32 |
#include <linux/ncp_mount.h> |
|---|
| 33 |
#include <linux/smp_lock.h> |
|---|
| 34 |
#include <linux/syscalls.h> |
|---|
| 35 |
#include <linux/ctype.h> |
|---|
| 36 |
#include <linux/module.h> |
|---|
| 37 |
#include <linux/dnotify.h> |
|---|
| 38 |
#include <linux/highuid.h> |
|---|
| 39 |
#include <linux/sunrpc/svc.h> |
|---|
| 40 |
#include <linux/nfsd/nfsd.h> |
|---|
| 41 |
#include <linux/nfsd/syscall.h> |
|---|
| 42 |
#include <linux/personality.h> |
|---|
| 43 |
|
|---|
| 44 |
#include <net/sock.h> |
|---|
| 45 |
|
|---|
| 46 |
#include <asm/uaccess.h> |
|---|
| 47 |
#include <asm/mmu_context.h> |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
asmlinkage long compat_sys_utime(char __user *filename, struct compat_utimbuf __user *t) |
|---|
| 54 |
{ |
|---|
| 55 |
struct timeval tv[2]; |
|---|
| 56 |
|
|---|
| 57 |
if (t) { |
|---|
| 58 |
if (get_user(tv[0].tv_sec, &t->actime) || |
|---|
| 59 |
get_user(tv[1].tv_sec, &t->modtime)) |
|---|
| 60 |
return -EFAULT; |
|---|
| 61 |
tv[0].tv_usec = 0; |
|---|
| 62 |
tv[1].tv_usec = 0; |
|---|
| 63 |
} |
|---|
| 64 |
return do_utimes(filename, t ? tv : NULL); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval __user *t) |
|---|
| 68 |
{ |
|---|
| 69 |
struct timeval tv[2]; |
|---|
| 70 |
|
|---|
| 71 |
if (t) { |
|---|
| 72 |
if (get_user(tv[0].tv_sec, &t[0].tv_sec) || |
|---|
| 73 |
get_user(tv[0].tv_usec, &t[0].tv_usec) || |
|---|
| 74 |
get_user(tv[1].tv_sec, &t[1].tv_sec) || |
|---|
| 75 |
get_user(tv[1].tv_usec, &t[1].tv_usec)) |
|---|
| 76 |
return -EFAULT; |
|---|
| 77 |
} |
|---|
| 78 |
return do_utimes(filename, t ? tv : NULL); |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
asmlinkage long compat_sys_newstat(char __user * filename, |
|---|
| 82 |
struct compat_stat __user *statbuf) |
|---|
| 83 |
{ |
|---|
| 84 |
struct kstat stat; |
|---|
| 85 |
int error = vfs_stat(filename, &stat); |
|---|
| 86 |
|
|---|
| 87 |
if (!error) |
|---|
| 88 |
error = cp_compat_stat(&stat, statbuf); |
|---|
| 89 |
return error; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
asmlinkage long compat_sys_newlstat(char __user * filename, |
|---|
| 93 |
struct compat_stat __user *statbuf) |
|---|
| 94 |
{ |
|---|
| 95 |
struct kstat stat; |
|---|
| 96 |
int error = vfs_lstat(filename, &stat); |
|---|
| 97 |
|
|---|
| 98 |
if (!error) |
|---|
| 99 |
error = cp_compat_stat(&stat, statbuf); |
|---|
| 100 |
return error; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
asmlinkage long compat_sys_newfstat(unsigned int fd, |
|---|
| 104 |
struct compat_stat __user * statbuf) |
|---|
| 105 |
{ |
|---|
| 106 |
struct kstat stat; |
|---|
| 107 |
int error = vfs_fstat(fd, &stat); |
|---|
| 108 |
|
|---|
| 109 |
if (!error) |
|---|
| 110 |
error = cp_compat_stat(&stat, statbuf); |
|---|
| 111 |
return error; |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf) |
|---|
| 115 |
{ |
|---|
| 116 |
|
|---|
| 117 |
if (sizeof ubuf->f_blocks == 4) { |
|---|
| 118 |
if ((kbuf->f_blocks | kbuf->f_bfree | |
|---|
| 119 |
kbuf->f_bavail | kbuf->f_files | kbuf->f_ffree) & |
|---|
| 120 |
0xffffffff00000000ULL) |
|---|
| 121 |
return -EOVERFLOW; |
|---|
| 122 |
} |
|---|
| 123 |
if (verify_area(VERIFY_WRITE, ubuf, sizeof(*ubuf)) || |
|---|
| 124 |
__put_user(kbuf->f_type, &ubuf->f_type) || |
|---|
| 125 |
__put_user(kbuf->f_bsize, &ubuf->f_bsize) || |
|---|
| 126 |
__put_user(kbuf->f_blocks, &ubuf->f_blocks) || |
|---|
| 127 |
__put_user(kbuf->f_bfree, &ubuf->f_bfree) || |
|---|
| 128 |
__put_user(kbuf->f_bavail, &ubuf->f_bavail) || |
|---|
| 129 |
__put_user(kbuf->f_files, &ubuf->f_files) || |
|---|
| 130 |
__put_user(kbuf->f_ffree, &ubuf->f_ffree) || |
|---|
| 131 |
__put_user(kbuf->f_namelen, &ubuf->f_namelen) || |
|---|
| 132 |
__put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) || |
|---|
| 133 |
__put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) || |
|---|
| 134 |
__put_user(kbuf->f_frsize, &ubuf->f_frsize) || |
|---|
| 135 |
__put_user(0, &ubuf->f_spare[0]) || |
|---|
| 136 |
__put_user(0, &ubuf->f_spare[1]) || |
|---|
| 137 |
__put_user(0, &ubuf->f_spare[2]) || |
|---|
| 138 |
__put_user(0, &ubuf->f_spare[3]) || |
|---|
| 139 |
__put_user(0, &ubuf->f_spare[4])) |
|---|
| 140 |
return -EFAULT; |
|---|
| 141 |
return 0; |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
asmlinkage long compat_sys_statfs(const char __user *path, struct compat_statfs __user *buf) |
|---|
| 149 |
{ |
|---|
| 150 |
struct nameidata nd; |
|---|
| 151 |
int error; |
|---|
| 152 |
|
|---|
| 153 |
error = user_path_walk(path, &nd); |
|---|
| 154 |
if (!error) { |
|---|
| 155 |
struct kstatfs tmp; |
|---|
| 156 |
error = vfs_statfs(nd.dentry->d_inode->i_sb, &tmp); |
|---|
| 157 |
if (!error && put_compat_statfs(buf, &tmp)) |
|---|
| 158 |
error = -EFAULT; |
|---|
| 159 |
path_release(&nd); |
|---|
| 160 |
} |
|---|
| 161 |
return error; |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs __user *buf) |
|---|
| 165 |
{ |
|---|
| 166 |
struct file * file; |
|---|
| 167 |
struct kstatfs tmp; |
|---|
| 168 |
int error; |
|---|
| 169 |
|
|---|
| 170 |
error = -EBADF; |
|---|
| 171 |
file = fget(fd); |
|---|
| 172 |
if (!file) |
|---|
| 173 |
goto out; |
|---|
| 174 |
error = vfs_statfs(file->f_dentry->d_inode->i_sb, &tmp); |
|---|
| 175 |
if (!error && put_compat_statfs(buf, &tmp)) |
|---|
| 176 |
error = -EFAULT; |
|---|
| 177 |
fput(file); |
|---|
| 178 |
out: |
|---|
| 179 |
return error; |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf) |
|---|
| 183 |
{ |
|---|
| 184 |
if (sizeof ubuf->f_blocks == 4) { |
|---|
| 185 |
if ((kbuf->f_blocks | kbuf->f_bfree | |
|---|
| 186 |
kbuf->f_bavail | kbuf->f_files | kbuf->f_ffree) & |
|---|
| 187 |
0xffffffff00000000ULL) |
|---|
| 188 |
return -EOVERFLOW; |
|---|
| 189 |
} |
|---|
| 190 |
if (verify_area(VERIFY_WRITE, ubuf, sizeof(*ubuf)) || |
|---|
| 191 |
__put_user(kbuf->f_type, &ubuf->f_type) || |
|---|
| 192 |
__put_user(kbuf->f_bsize, &ubuf->f_bsize) || |
|---|
| 193 |
__put_user(kbuf->f_blocks, &ubuf->f_blocks) || |
|---|
| 194 |
__put_user(kbuf->f_bfree, &ubuf->f_bfree) || |
|---|
| 195 |
__put_user(kbuf->f_bavail, &ubuf->f_bavail) || |
|---|
| 196 |
__put_user(kbuf->f_files, &ubuf->f_files) || |
|---|
| 197 |
__put_user(kbuf->f_ffree, &ubuf->f_ffree) || |
|---|
| 198 |
__put_user(kbuf->f_namelen, &ubuf->f_namelen) || |
|---|
| 199 |
__put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) || |
|---|
| 200 |
__put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) || |
|---|
| 201 |
__put_user(kbuf->f_frsize, &ubuf->f_frsize)) |
|---|
| 202 |
return -EFAULT; |
|---|
| 203 |
return 0; |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
asmlinkage long compat_statfs64(const char __user *path, compat_size_t sz, struct compat_statfs64 __user *buf) |
|---|
| 207 |
{ |
|---|
| 208 |
struct nameidata nd; |
|---|
| 209 |
int error; |
|---|
| 210 |
|
|---|
| 211 |
if (sz != sizeof(*buf)) |
|---|
| 212 |
return -EINVAL; |
|---|
| 213 |
|
|---|
| 214 |
error = user_path_walk(path, &nd); |
|---|
| 215 |
if (!error) { |
|---|
| 216 |
struct kstatfs tmp; |
|---|
| 217 |
error = vfs_statfs(nd.dentry->d_inode->i_sb, &tmp); |
|---|
| 218 |
if (!error && put_compat_statfs64(buf, &tmp)) |
|---|
| 219 |
error = -EFAULT; |
|---|
| 220 |
path_release(&nd); |
|---|
| 221 |
} |
|---|
| 222 |
return error; |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
asmlinkage long compat_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user *buf) |
|---|
| 226 |
{ |
|---|
| 227 |
struct file * file; |
|---|
| 228 |
struct kstatfs tmp; |
|---|
| 229 |
int error; |
|---|
| 230 |
|
|---|
| 231 |
if (sz != sizeof(*buf)) |
|---|
| 232 |
return -EINVAL; |
|---|
| 233 |
|
|---|
| 234 |
error = -EBADF; |
|---|
| 235 |
file = fget(fd); |
|---|
| 236 |
if (!file) |
|---|
| 237 |
goto out; |
|---|
| 238 |
error = vfs_statfs(file->f_dentry->d_inode->i_sb, &tmp); |
|---|
| 239 |
if (!error && put_compat_statfs64(buf, &tmp)) |
|---|
| 240 |
error = -EFAULT; |
|---|
| 241 |
fput(file); |
|---|
| 242 |
out: |
|---|
| 243 |
return error; |
|---|
| 244 |
} |
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
#define IOCTL_HASHSIZE 256 |
|---|
| 249 |
struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE]; |
|---|
| 250 |
|
|---|
| 251 |
extern struct ioctl_trans ioctl_start[]; |
|---|
| 252 |
extern int ioctl_table_size; |
|---|
| 253 |
|
|---|
| 254 |
static inline unsigned long ioctl32_hash(unsigned long cmd) |
|---|
| 255 |
{ |
|---|
| 256 |
return (((cmd >> 6) ^ (cmd >> 4) ^ cmd)) % IOCTL_HASHSIZE; |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
static void ioctl32_insert_translation(struct ioctl_trans *trans) |
|---|
| 260 |
{ |
|---|
| 261 |
unsigned long hash; |
|---|
| 262 |
struct ioctl_trans *t; |
|---|
| 263 |
|
|---|
| 264 |
hash = ioctl32_hash (trans->cmd); |
|---|
| 265 |
if (!ioctl32_hash_table[hash]) |
|---|
| 266 |
ioctl32_hash_table[hash] = trans; |
|---|
| 267 |
else { |
|---|
| 268 |
t = ioctl32_hash_table[hash]; |
|---|
| 269 |
while (t->next) |
|---|
| 270 |
t = t->next; |
|---|
| 271 |
trans->next = 0; |
|---|
| 272 |
t->next = trans; |
|---|
| 273 |
} |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
static int __init init_sys32_ioctl(void) |
|---|
| 277 |
{ |
|---|
| 278 |
int i; |
|---|
| 279 |
|
|---|
| 280 |
for (i = 0; i < ioctl_table_size; i++) { |
|---|
| 281 |
if (ioctl_start[i].next != 0) { |
|---|
| 282 |
printk("ioctl translation %d bad\n",i); |
|---|
| 283 |
return -1; |
|---|
| 284 |
} |
|---|
| 285 |
|
|---|
| 286 |
ioctl32_insert_translation(&ioctl_start[i]); |
|---|
| 287 |
} |
|---|
| 288 |
return 0; |
|---|
| 289 |
} |
|---|
| 290 |
|
|---|
| 291 |
__initcall(init_sys32_ioctl); |
|---|
| 292 |
|
|---|
| 293 |
int register_ioctl32_conversion(unsigned int cmd, int (*handler)(unsigned int, |
|---|
| 294 |
unsigned int, unsigned long, struct file *)) |
|---|
| 295 |
{ |
|---|
| 296 |
struct ioctl_trans *t; |
|---|
| 297 |
struct ioctl_trans *new_t; |
|---|
| 298 |
unsigned long hash = ioctl32_hash(cmd); |
|---|
| 299 |
|
|---|
| 300 |
new_t = kmalloc(sizeof(*new_t), GFP_KERNEL); |
|---|
| 301 |
if (!new_t) |
|---|
| 302 |
return -ENOMEM; |
|---|
| 303 |
|
|---|
| 304 |
lock_kernel(); |
|---|
| 305 |
for (t = ioctl32_hash_table[hash]; t; t = t->next) { |
|---|
| 306 |
if (t->cmd == cmd) { |
|---|
| 307 |
printk(KERN_ERR "Trying to register duplicated ioctl32 " |
|---|
| 308 |
"handler %x\n", cmd); |
|---|
| 309 |
unlock_kernel(); |
|---|
| 310 |
kfree(new_t); |
|---|
| 311 |
return -EINVAL; |
|---|
| 312 |
} |
|---|
| 313 |
} |
|---|
| 314 |
new_t->next = NULL; |
|---|
| 315 |
new_t->cmd = cmd; |
|---|
| 316 |
new_t->handler = handler; |
|---|
| 317 |
ioctl32_insert_translation(new_t); |
|---|
| 318 |
|
|---|
| 319 |
unlock_kernel(); |
|---|
| 320 |
return 0; |
|---|
| 321 |
} |
|---|
| 322 |
EXPORT_SYMBOL(register_ioctl32_conversion); |
|---|
| 323 |
|
|---|
| 324 |
static inline int builtin_ioctl(struct ioctl_trans *t) |
|---|
| 325 |
{ |
|---|
| 326 |
return t >= ioctl_start && t < (ioctl_start + ioctl_table_size); |
|---|
| 327 |
} |
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
int unregister_ioctl32_conversion(unsigned int cmd) |
|---|
| 335 |
{ |
|---|
| 336 |
unsigned long hash = ioctl32_hash(cmd); |
|---|
| 337 |
struct ioctl_trans *t, *t1; |
|---|
| 338 |
|
|---|
| 339 |
lock_kernel(); |
|---|
| 340 |
|
|---|
| 341 |
t = ioctl32_hash_table[hash]; |
|---|
| 342 |
if (!t) { |
|---|
| 343 |
unlock_kernel(); |
|---|
| 344 |
return -EINVAL; |
|---|
| 345 |
} |
|---|
| 346 |
|
|---|
| 347 |
if (t->cmd == cmd) { |
|---|
| 348 |
if (builtin_ioctl(t)) { |
|---|
| 349 |
printk("%p tried to unregister builtin ioctl %x\n", |
|---|
| 350 |
__builtin_return_address(0), cmd); |
|---|
| 351 |
} else { |
|---|
| 352 |
ioctl32_hash_table[hash] = t->next; |
|---|
| 353 |
unlock_kernel(); |
|---|
| 354 |
kfree(t); |
|---|
| 355 |
return 0; |
|---|
| 356 |
} |
|---|
| 357 |
} |
|---|
| 358 |
while (t->next) { |
|---|
| 359 |
t1 = t->next; |
|---|
| 360 |
if (t1->cmd == cmd) { |
|---|
| 361 |
if (builtin_ioctl(t1)) { |
|---|
| 362 |
printk("%p tried to unregister builtin " |
|---|
| 363 |
"ioctl %x\n", |
|---|
| 364 |
__builtin_return_address(0), cmd); |
|---|
| 365 |
goto out; |
|---|
| 366 |
} else { |
|---|
| 367 |
t->next = t1->next; |
|---|
| 368 |
unlock_kernel(); |
|---|
| 369 |
kfree(t1); |
|---|
| 370 |
return 0; |
|---|
| 371 |
} |
|---|
| 372 |
} |
|---|
| 373 |
t = t1; |
|---|
| 374 |
} |
|---|
| 375 |
printk(KERN_ERR "Trying to free unknown 32bit ioctl handler %x\n", |
|---|
| 376 |
cmd); |
|---|
| 377 |
out: |
|---|
| 378 |
unlock_kernel(); |
|---|
| 379 |
return -EINVAL; |
|---|
| 380 |
} |
|---|
| 381 |
EXPORT_SYMBOL(unregister_ioctl32_conversion); |
|---|
| 382 |
|
|---|
| 383 |
asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, |
|---|
| 384 |
unsigned long arg) |
|---|
| 385 |
{ |
|---|
| 386 |
struct file * filp; |
|---|
| 387 |
int error = -EBADF; |
|---|
| 388 |
struct ioctl_trans *t; |
|---|
| 389 |
|
|---|
| 390 |
filp = fget(fd); |
|---|
| 391 |
if(!filp) |
|---|
| 392 |
goto out2; |
|---|
| 393 |
|
|---|
| 394 |
if (!filp->f_op || !filp->f_op->ioctl) { |
|---|
| 395 |
error = sys_ioctl (fd, cmd, arg); |
|---|
| 396 |
goto out; |
|---|
| 397 |
} |
|---|
| 398 |
|
|---|
| 399 |
lock_kernel(); |
|---|
| 400 |
|
|---|
| 401 |
t = ioctl32_hash_table[ioctl32_hash (cmd)]; |
|---|
| 402 |
|
|---|
| 403 |
while (t && t->cmd != cmd) |
|---|
| 404 |
t = t->next; |
|---|
| 405 |
if (t) { |
|---|
| 406 |
if (t->handler) { |
|---|
| 407 |
error = t->handler(fd, cmd, arg, filp); |
|---|
| 408 |
unlock_kernel(); |
|---|
| 409 |
} else { |
|---|
| 410 |
unlock_kernel(); |
|---|
| 411 |
error = sys_ioctl(fd, cmd, arg); |
|---|
| 412 |
} |
|---|
| 413 |
} else { |
|---|
| 414 |
unlock_kernel(); |
|---|
| 415 |
if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) { |
|---|
| 416 |
error = siocdevprivate_ioctl(fd, cmd, arg); |
|---|
| 417 |
} else { |
|---|
| 418 |
static int count; |
|---|
| 419 |
if (++count <= 50) { |
|---|
| 420 |
char buf[10]; |
|---|
| 421 |
char *fn = "?"; |
|---|
| 422 |
char *path; |
|---|
| 423 |
|
|---|
| 424 |
path = (char *)__get_free_page(GFP_KERNEL); |
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
if (path) { |
|---|
| 428 |
fn = d_path(filp->f_dentry, |
|---|
| 429 |
filp->f_vfsmnt, path, |
|---|
| 430 |
PAGE_SIZE); |
|---|
| 431 |
} |
|---|
| 432 |
|
|---|
| 433 |
sprintf(buf,"'%c'", (cmd>>24) & 0x3f); |
|---|
| 434 |
if (!isprint(buf[1])) |
|---|
| 435 |
sprintf(buf, "%02x", buf[1]); |
|---|
| 436 |
printk("ioctl32(%s:%d): Unknown cmd fd(%d) " |
|---|
| 437 |
"cmd(%08x){%s} arg(%08x) on %s\n", |
|---|
| 438 |
current->comm, current->pid, |
|---|
| 439 |
(int)fd, (unsigned int)cmd, buf, |
|---|
| 440 |
(unsigned int)arg, fn); |
|---|
| 441 |
if (path) |
|---|
| 442 |
free_page((unsigned long)path); |
|---|
| 443 |
} |
|---|
| 444 |
error = -EINVAL; |
|---|
| 445 |
} |
|---|
| 446 |
} |
|---|
| 447 |
out: |
|---|
| 448 |
fput(filp); |
|---|
| 449 |
out2: |
|---|
| 450 |
return error; |
|---|
| 451 |
} |
|---|
| 452 |
|
|---|
| 453 |
static int get_compat_flock(struct flock *kfl, struct compat_flock __user *ufl) |
|---|
| 454 |
{ |
|---|
| 455 |
if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) || |
|---|
| 456 |
__get_user(kfl->l_type, &ufl->l_type) || |
|---|
| 457 |
__get_user(kfl->l_whence, &ufl->l_whence) || |
|---|
| 458 |
__get_user(kfl->l_start, &ufl->l_start) || |
|---|
| 459 |
__get_user(kfl->l_len, &ufl->l_len) || |
|---|
| 460 |
__get_user(kfl->l_pid, &ufl->l_pid)) |
|---|
| 461 |
return -EFAULT; |
|---|
| 462 |
return 0; |
|---|
| 463 |
} |
|---|
| 464 |
|
|---|
| 465 |
static int put_compat_flock(struct flock *kfl, struct compat_flock __user *ufl) |
|---|
| 466 |
{ |
|---|
| 467 |
if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) || |
|---|
| 468 |
__put_user(kfl->l_type, &ufl->l_type) || |
|---|
| 469 |
__put_user(kfl->l_whence, &ufl->l_whence) || |
|---|
| 470 |
__put_user(kfl->l_start, &ufl->l_start) || |
|---|
| 471 |
__put_user(kfl->l_len, &ufl->l_len) || |
|---|
| 472 |
__put_user(kfl->l_pid, &ufl->l_pid)) |
|---|
| 473 |
return -EFAULT; |
|---|
| 474 |
return 0; |
|---|
| 475 |
} |
|---|
| 476 |
|
|---|
| 477 |
#ifndef HAVE_ARCH_GET_COMPAT_FLOCK64 |
|---|
| 478 |
static int get_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl) |
|---|
| 479 |
{ |
|---|
| 480 |
if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) || |
|---|
| 481 |
__get_user(kfl->l_type, &ufl->l_type) || |
|---|
| 482 |
__get_user(kfl->l_whence, &ufl->l_whence) || |
|---|
| 483 |
__get_user(kfl->l_start, &ufl->l_start) || |
|---|
| 484 |
__get_user(kfl->l_len, &ufl->l_len) || |
|---|
| 485 |
__get_user(kfl->l_pid, &ufl->l_pid)) |
|---|
| 486 |
return -EFAULT; |
|---|
| 487 |
return 0; |
|---|
| 488 |
} |
|---|
| 489 |
#endif |
|---|
| 490 |
|
|---|
| 491 |
#ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64 |
|---|
| 492 |
static int put_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl) |
|---|
| 493 |
{ |
|---|
| 494 |
if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) || |
|---|
| 495 |
__put_user(kfl->l_type, &ufl->l_type) || |
|---|
| 496 |
__put_user(kfl->l_whence, &ufl->l_whence) || |
|---|
| 497 |
__put_user(kfl->l_start, &ufl->l_start) || |
|---|
| 498 |
__put_user(kfl->l_len, &ufl->l_len) || |
|---|
| 499 |
__put_user(kfl->l_pid, &ufl->l_pid)) |
|---|
| 500 |
return -EFAULT; |
|---|
| 501 |
return 0; |
|---|
| 502 |
} |
|---|
| 503 |
#endif |
|---|
| 504 |
|
|---|
| 505 |
asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd, |
|---|
| 506 |
unsigned long arg) |
|---|
| 507 |
{ |
|---|
| 508 |
mm_segment_t old_fs; |
|---|
| 509 |
struct flock f; |
|---|
| 510 |
long ret; |
|---|
| 511 |
|
|---|
| 512 |
switch (cmd) { |
|---|
| 513 |
case F_GETLK: |
|---|
| 514 |
case F_SETLK: |
|---|
| 515 |
case F_SETLKW: |
|---|
| 516 |
ret = get_compat_flock(&f, compat_ptr(arg)); |
|---|
| 517 |
if (ret != 0) |
|---|
| 518 |
break; |
|---|
| 519 |
old_fs = get_fs(); |
|---|
| 520 |
set_fs(KERNEL_DS); |
|---|
| 521 |
ret = sys_fcntl(fd, cmd, (unsigned long)&f); |
|---|
| 522 |
set_fs(old_fs); |
|---|
| 523 |
if ((cmd == F_GETLK) && (ret == 0)) { |
|---|
| 524 |
if ((f.l_start >= COMPAT_OFF_T_MAX) || |
|---|
| 525 |
((f.l_start + f.l_len) >= COMPAT_OFF_T_MAX)) |
|---|
| 526 |
ret = -EOVERFLOW; |
|---|
| 527 |
if (ret == 0) |
|---|
| 528 |
ret = put_compat_flock(&f, compat_ptr(arg)); |
|---|
| 529 |
} |
|---|
| 530 |
break; |
|---|
| 531 |
|
|---|
| 532 |
case F_GETLK64: |
|---|
| 533 |
case F_SETLK64: |
|---|
| 534 |
case F_SETLKW64: |
|---|
| 535 |
ret = get_compat_flock64(&f, compat_ptr(arg)); |
|---|
| 536 |
if (ret != 0) |
|---|
| 537 |
break; |
|---|
| 538 |
old_fs = get_fs(); |
|---|
| 539 |
set_fs(KERNEL_DS); |
|---|
| 540 |
ret = sys_fcntl(fd, (cmd == F_GETLK64) ? F_GETLK : |
|---|
| 541 |
((cmd == F_SETLK64) ? F_SETLK : F_SETLKW), |
|---|
| 542 |
(unsigned long)&f); |
|---|
| 543 |
set_fs(old_fs); |
|---|
| 544 |
if ((cmd == F_GETLK64) && (ret == 0)) { |
|---|
| 545 |
if ((f.l_start >= COMPAT_LOFF_T_MAX) || |
|---|
| 546 |
((f.l_start + f.l_len) >= COMPAT_LOFF_T_MAX)) |
|---|
| 547 |
ret = -EOVERFLOW; |
|---|
| 548 |
if (ret == 0) |
|---|
| 549 |
ret = put_compat_flock64(&f, compat_ptr(arg)); |
|---|
| 550 |
} |
|---|
| 551 |
break; |
|---|
| 552 |
|
|---|
| 553 |
default: |
|---|
| 554 |
ret = sys_fcntl(fd, cmd, arg); |
|---|
| 555 |
break; |
|---|
| 556 |
} |
|---|
| 557 |
return ret; |
|---|
| 558 |
} |
|---|
| 559 |
|
|---|
| 560 |
asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd, |
|---|
| 561 |
unsigned long arg) |
|---|
| 562 |
{ |
|---|
| 563 |
if ((cmd == F_GETLK64) || (cmd == F_SETLK64) || (cmd == F_SETLKW64)) |
|---|
| 564 |
return -EINVAL; |
|---|
| 565 |
return compat_sys_fcntl64(fd, cmd, arg); |
|---|
| 566 |
} |
|---|
| 567 |
|
|---|
| 568 |
asmlinkage long |
|---|
| 569 |
compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p) |
|---|
| 570 |
{ |
|---|
| 571 |
long ret; |
|---|
| 572 |
aio_context_t ctx64; |
|---|
| 573 |
|
|---|
| 574 |
mm_segment_t oldfs = get_fs(); |
|---|
| 575 |
if (unlikely(get_user(ctx64, ctx32p))) |
|---|
| 576 |
return -EFAULT; |
|---|
| 577 |
|
|---|
| 578 |
set_fs(KERNEL_DS); |
|---|
| 579 |
|
|---|
| 580 |
ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64); |
|---|
| 581 |
set_fs(oldfs); |
|---|
| 582 |
|
|---|
| 583 |
if (!ret) |
|---|
| 584 |
ret = put_user((u32) ctx64, ctx32p); |
|---|
| 585 |
return ret; |
|---|
| 586 |
} |
|---|
| 587 |
|
|---|
| 588 |
asmlinkage long |
|---|
| 589 |
compat_sys_io_getevents(aio_context_t ctx_id, |
|---|
| 590 |
unsigned long min_nr, |
|---|
| 591 |
unsigned long nr, |
|---|
| 592 |
struct io_event __user *events, |
|---|
| 593 |
struct compat_timespec __user *timeout) |
|---|
| 594 |
{ |
|---|
| 595 |
long ret; |
|---|
| 596 |
struct timespec t; |
|---|
| 597 |
struct timespec __user *ut = NULL; |
|---|
| 598 |
|
|---|
| 599 |
ret = -EFAULT; |
|---|
| 600 |
if (unlikely(!access_ok(VERIFY_WRITE, events, |
|---|
| 601 |
nr * sizeof(struct io_event)))) |
|---|
| 602 |
goto out; |
|---|
| 603 |
if (timeout) { |
|---|
| 604 |
if (get_compat_timespec(&t, timeout)) |
|---|
| 605 |
goto out; |
|---|
| 606 |
|
|---|
| 607 |
ut = compat_alloc_user_space(sizeof(*ut)); |
|---|
| 608 |
if (copy_to_user(ut, &t, sizeof(t)) ) |
|---|
| 609 |
goto out; |
|---|
| 610 |
} |
|---|
| 611 |
ret = sys_io_getevents(ctx_id, min_nr, nr, events, ut); |
|---|
| 612 |
out: |
|---|
| 613 |
return ret; |
|---|
| 614 |
} |
|---|
| 615 |
|
|---|
| 616 |
static inline long |
|---|
| 617 |
copy_iocb(long nr, u32 __user *ptr32, struct iocb __user * __user *ptr64) |
|---|
| 618 |
{ |
|---|
| 619 |
compat_uptr_t uptr; |
|---|
| 620 |
int i; |
|---|
| 621 |
|
|---|
| 622 |
for (i = 0; i < nr; ++i) { |
|---|
| 623 |
if (get_user(uptr, ptr32 + i)) |
|---|
| 624 |
return -EFAULT; |
|---|
| 625 |
if (put_user(compat_ptr(uptr), ptr64 + i)) |
|---|
| 626 |
return -EFAULT; |
|---|
| 627 |
} |
|---|
| 628 |
return 0; |
|---|
| 629 |
} |
|---|
| 630 |
|
|---|
| 631 |
#define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *)) |
|---|
| 632 |
|
|---|
| 633 |
asmlinkage long |
|---|
| 634 |
compat_sys_io_submit(aio_context_t ctx_id, int nr, u32 __user *iocb) |
|---|
| 635 |
{ |
|---|
| 636 |
struct iocb __user * __user *iocb64; |
|---|
| 637 |
long ret; |
|---|
| 638 |
|
|---|
| 639 |
if (unlikely(nr < 0)) |
|---|
| 640 |
return -EINVAL; |
|---|
| 641 |
|
|---|
| 642 |
if (nr > MAX_AIO_SUBMITS) |
|---|
| 643 |
nr = MAX_AIO_SUBMITS; |
|---|
| 644 |
|
|---|
| 645 |
iocb64 = compat_alloc_user_space(nr * sizeof(*iocb64)); |
|---|
| 646 |
ret = copy_iocb(nr, iocb, iocb64); |
|---|
| 647 |
if (!ret) |
|---|
| 648 |
ret = sys_io_submit(ctx_id, nr, iocb64); |
|---|
| 649 |
return ret; |
|---|
| 650 |
} |
|---|
| 651 |
|
|---|
| 652 |
struct compat_ncp_mount_data { |
|---|
| 653 |
compat_int_t version; |
|---|
| 654 |
compat_uint_t ncp_fd; |
|---|
| 655 |
compat_uid_t mounted_uid; |
|---|
| 656 |
compat_pid_t wdog_pid; |
|---|
| 657 |
unsigned char mounted_vol[NCP_VOLNAME_LEN + 1]; |
|---|
| 658 |
compat_uint_t time_out; |
|---|
| 659 |
compat_uint_t retry_count; |
|---|
| 660 |
compat_uint_t flags; |
|---|
| 661 |
compat_uid_t uid; |
|---|
| 662 |
compat_gid_t gid; |
|---|
| 663 |
compat_mode_t file_mode; |
|---|
| 664 |
compat_mode_t dir_mode; |
|---|
| 665 |
}; |
|---|
| 666 |
|
|---|
| 667 |
struct compat_ncp_mount_data_v4 { |
|---|
| 668 |
compat_int_t version; |
|---|
| 669 |
compat_ulong_t flags; |
|---|
| 670 |
compat_ulong_t mounted_uid; |
|---|
| 671 |
compat_long_t wdog_pid; |
|---|
| 672 |
compat_uint_t ncp_fd; |
|---|
| 673 |
compat_uint_t time_out; |
|---|
| 674 |
compat_uint_t retry_count; |
|---|
| 675 |
compat_ulong_t uid; |
|---|
| 676 |
compat_ulong_t gid; |
|---|
| 677 |
compat_ulong_t file_mode; |
|---|
| 678 |
compat_ulong_t dir_mode; |
|---|
| 679 |
}; |
|---|
| 680 |
|
|---|
| 681 |
static void *do_ncp_super_data_conv(void *raw_data) |
|---|
| 682 |
{ |
|---|
| 683 |
int version = *(unsigned int *)raw_data; |
|---|
| 684 |
|
|---|
| 685 |
if (version == 3) { |
|---|
| 686 |
struct compat_ncp_mount_data *c_n = raw_data; |
|---|
| 687 |
struct ncp_mount_data *n = raw_data; |
|---|
| 688 |
|
|---|
| 689 |
n->dir_mode = c_n->dir_mode; |
|---|
| 690 |
n->file_mode = c_n->file_mode; |
|---|
| 691 |
n->gid = c_n->gid; |
|---|
| 692 |
n->uid = c_n->uid; |
|---|
| 693 |
memmove (n->mounted_vol, c_n->mounted_vol, (sizeof (c_n->mounted_vol) + 3 * sizeof (unsigned int))); |
|---|
| 694 |
n->wdog_pid = c_n->wdog_pid; |
|---|
| 695 |
n->mounted_uid = c_n->mounted_uid; |
|---|
| 696 |
} else if (version == 4) { |
|---|
| 697 |
struct compat_ncp_mount_data_v4 *c_n = raw_data; |
|---|
| 698 |
struct ncp_mount_data_v4 *n = raw_data; |
|---|
| 699 |
|
|---|
| 700 |
n->dir_mode = c_n->dir_mode; |
|---|
| 701 |
n->file_mode = c_n->file_mode; |
|---|
| 702 |
n->gid = c_n->gid; |
|---|
| 703 |
n->uid = c_n->uid; |
|---|
| 704 |
n->retry_count = c_n->retry_count; |
|---|
| 705 |
n->time_out = c_n->time_out; |
|---|
| 706 |
n->ncp_fd = c_n->ncp_fd; |
|---|
| 707 |
n->wdog_pid = c_n->wdog_pid; |
|---|
| 708 |
n->mounted_uid = c_n->mounted_uid; |
|---|
| 709 |
n->flags = c_n->flags; |
|---|
| 710 |
} else if (version != 5) { |
|---|
| 711 |
return NULL; |
|---|
| 712 |
} |
|---|
| 713 |
|
|---|
| 714 |
return raw_data; |
|---|
| 715 |
} |
|---|
| 716 |
|
|---|
| 717 |
struct compat_smb_mount_data { |
|---|
| 718 |
compat_int_t version; |
|---|
| 719 |
compat_uid_t mounted_uid; |
|---|
| 720 |
compat_uid_t uid; |
|---|
| 721 |
compat_gid_t gid; |
|---|
| 722 |
compat_mode_t file_mode; |
|---|
| 723 |
compat_mode_t dir_mode; |
|---|
| 724 |
}; |
|---|
| 725 |
|
|---|
| 726 |
static void *do_smb_super_data_conv(void *raw_data) |
|---|
| 727 |
{ |
|---|
| 728 |
struct smb_mount_data *s = raw_data; |
|---|
| 729 |
struct compat_smb_mount_data *c_s = raw_data; |
|---|
| 730 |
|
|---|
| 731 |
if (c_s->version != SMB_MOUNT_OLDVERSION) |
|---|
| 732 |
goto out; |
|---|
| 733 |
s->dir_mode = c_s->dir_mode; |
|---|
| 734 |
s->file_mode = c_s->file_mode; |
|---|
| 735 |
s->gid = c_s->gid; |
|---|
| 736 |
s->uid = c_s->uid; |
|---|
| 737 |
s->mounted_uid = c_s->mounted_uid; |
|---|
| 738 |
out: |
|---|
| 739 |
return raw_data; |
|---|
| 740 |
} |
|---|
| 741 |
|
|---|
| 742 |
extern int copy_mount_options (const void __user *, unsigned long *); |
|---|
| 743 |
|
|---|
| 744 |
#define SMBFS_NAME "smbfs" |
|---|
| 745 |
#define NCPFS_NAME "ncpfs" |
|---|
| 746 |
|
|---|
| 747 |
asmlinkage long compat_sys_mount(char __user * dev_name, char __user * dir_name, |
|---|
| 748 |
char __user * type, unsigned long flags, |
|---|
| 749 |
void __user * data) |
|---|
| 750 |
{ |
|---|
| 751 |
unsigned long type_page; |
|---|
| 752 |
unsigned long data_page; |
|---|
| 753 |
unsigned long dev_page; |
|---|
| 754 |
char *dir_page; |
|---|
| 755 |
int retval; |
|---|
| 756 |
|
|---|
| 757 |
retval = copy_mount_options (type, &type_page); |
|---|
| 758 |
if (retval < 0) |
|---|
| 759 |
goto out; |
|---|
| 760 |
|
|---|
| 761 |
dir_page = getname(dir_name); |
|---|
| 762 |
retval = PTR_ERR(dir_page); |
|---|
| 763 |
if (IS_ERR(dir_page)) |
|---|
| 764 |
goto out1; |
|---|
| 765 |
|
|---|
| 766 |
retval = copy_mount_options (dev_name, &dev_page); |
|---|
| 767 |
if (retval < 0) |
|---|
| 768 |
goto out2; |
|---|
| 769 |
|
|---|
| 770 |
retval = copy_mount_options (data, &data_page); |
|---|
| 771 |
if (retval < 0) |
|---|
| 772 |
goto out3; |
|---|
| 773 |
|
|---|
| 774 |
retval = -EINVAL; |
|---|
| 775 |
|
|---|
| 776 |
if (type_page) { |
|---|
| 777 |
if (!strcmp((char *)type_page, SMBFS_NAME)) { |
|---|
| 778 |
do_smb_super_data_conv((void *)data_page); |
|---|
| 779 |
} else if (!strcmp((char *)type_page, NCPFS_NAME)) { |
|---|
| 780 |
do_ncp_super_data_conv((void *)data_page); |
|---|
| 781 |
} |
|---|
| 782 |
} |
|---|
| 783 |
|
|---|
| 784 |
lock_kernel(); |
|---|
| 785 |
retval = do_mount((char*)dev_page, dir_page, (char*)type_page, |
|---|
| 786 |
flags, (void*)data_page); |
|---|
| 787 |
unlock_kernel(); |
|---|
| 788 |
|
|---|
| 789 |
free_page(data_page); |
|---|
| 790 |
out3: |
|---|
| 791 |
free_page(dev_page); |
|---|
| 792 |
out2: |
|---|
| 793 |
putname(dir_page); |
|---|
| 794 |
out1: |
|---|
| 795 |
free_page(type_page); |
|---|
| 796 |
out: |
|---|
| 797 |
return retval; |
|---|
| 798 |
} |
|---|
| 799 |
|
|---|
| 800 |
static ssize_t compat_do_readv_writev(int type, struct file *file, |
|---|
| 801 |
const struct compat_iovec __user *uvector, |
|---|
| 802 |
unsigned long nr_segs, loff_t *pos) |
|---|
| 803 |
{ |
|---|
| 804 |
typedef ssize_t (*io_fn_t)(struct file *, char __user *, size_t, loff_t *); |
|---|
| 805 |
typedef ssize_t (*iov_fn_t)(struct file *, const struct iovec *, unsigned long, loff_t *); |
|---|
| 806 |
|
|---|
| 807 |
compat_ssize_t tot_len; |
|---|
| 808 |
struct iovec iovstack[UIO_FASTIOV]; |
|---|
| 809 |
struct iovec *iov=iovstack, *vector; |
|---|
| 810 |
ssize_t ret; |
|---|
| 811 |
int seg; |
|---|
| 812 |
io_fn_t fn; |
|---|
| 813 |
iov_fn_t fnv; |
|---|
| 814 |
struct inode *inode; |
|---|
| 815 |
|
|---|
| 816 |
|
|---|
| 817 |
|
|---|
| 818 |
|
|---|
| 819 |
|
|---|
| 820 |
|
|---|
| 821 |
ret = 0; |
|---|
| 822 |
if (nr_segs == 0) |
|---|
| 823 |
goto out; |
|---|
| 824 |
|
|---|
| 825 |
|
|---|
| 826 |
|
|---|
| 827 |
|
|---|
| 828 |
|
|---|
| 829 |
ret = -EINVAL; |
|---|
| 830 |
if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0)) |
|---|
| 831 |
goto out; |
|---|
| 832 |
if (!file->f_op) |
|---|
| 833 |
goto out; |
|---|
| 834 |
if (nr_segs > UIO_FASTIOV) { |
|---|
| 835 |
ret = -ENOMEM; |
|---|
| 836 |
iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL); |
|---|
| 837 |
if (!iov) |
|---|
| 838 |
goto out; |
|---|
| 839 |
} |
|---|
| 840 |
ret = -EFAULT; |
|---|
| 841 |
if (verify_area(VERIFY_READ, uvector, nr_segs*sizeof(*uvector))) |
|---|
| 842 |
goto out; |
|---|
| 843 |
|
|---|
| 844 |
|
|---|
| 845 |
|
|---|
| 846 |
|
|---|
| 847 |
|
|---|
| 848 |
|
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 |
tot_len = 0; |
|---|
| 852 |
vector = iov; |
|---|
| 853 |
ret = -EINVAL; |
|---|
| 854 |
for (seg = 0 ; seg < nr_segs; seg++) { |
|---|
| 855 |
compat_ssize_t tmp = tot_len; |
|---|
| 856 |
compat_ssize_t len; |
|---|
| 857 |
compat_uptr_t buf; |
|---|
| 858 |
|
|---|
| 859 |
if (__get_user(len, &uvector->iov_len) || |
|---|
| 860 |
__get_user(buf, &uvector->iov_base)) { |
|---|
| 861 |
ret = -EFAULT; |
|---|
| 862 |
goto out; |
|---|
| 863 |
} |
|---|
| 864 |
if (len < 0) |
|---|
| 865 |
goto out; |
|---|
| 866 |
tot_len += len; |
|---|
| 867 |
if (tot_len < tmp) |
|---|
| 868 |
goto out; |
|---|
| 869 |
vector->iov_base = compat_ptr(buf); |
|---|
| 870 |
vector->iov_len = (compat_size_t) len; |
|---|
| 871 |
uvector++; |
|---|
| 872 |
vector++; |
|---|
| 873 |
} |
|---|
| 874 |
if (tot_len == 0) { |
|---|
| 875 |
ret = 0; |
|---|
| 876 |
goto out; |
|---|
| 877 |
} |
|---|
| 878 |
|
|---|
| 879 |
inode = file->f_dentry->d_inode; |
|---|
| 880 |
|
|---|
| 881 |
ret = locks_verify_area((type == READ |
|---|
| 882 |
? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE), |
|---|
| 883 |
inode, file, *pos, tot_len); |
|---|
| 884 |
if (ret) |
|---|
| 885 |
goto out; |
|---|
| 886 |
|
|---|
| 887 |
fnv = NULL; |
|---|
| 888 |
if (type == READ) { |
|---|
| 889 |
fn = file->f_op->read; |
|---|
| 890 |
fnv = file->f_op->readv; |
|---|
| 891 |
} else { |
|---|
| 892 |
fn = (io_fn_t)file->f_op->write; |
|---|
| 893 |
fnv = file->f_op->writev; |
|---|
| 894 |
} |
|---|
| 895 |
if (fnv) { |
|---|
| 896 |
ret = fnv(file, iov, nr_segs, pos); |
|---|
| 897 |
goto out; |
|---|
| 898 |
} |
|---|
| 899 |
|
|---|
| 900 |
|
|---|
| 901 |
ret = 0; |
|---|
| 902 |
vector = iov; |
|---|
| 903 |
while (nr_segs > 0) { |
|---|
| 904 |
void __user * base; |
|---|
| 905 |
size_t len; |
|---|
| 906 |
ssize_t nr; |
|---|
| 907 |
|
|---|
| 908 |
base = vector->iov_base; |
|---|
| 909 |
len = vector->iov_len; |
|---|
| 910 |
vector++; |
|---|
| 911 |
nr_segs--; |
|---|
| 912 |
|
|---|
| 913 |
nr = fn(file, base, len, pos); |
|---|
| 914 |
|
|---|
| 915 |
if (nr < 0) { |
|---|
| 916 |
if (!ret) ret = nr; |
|---|
| 917 |
break; |
|---|
| 918 |
} |
|---|
| 919 |
ret += nr; |
|---|
| 920 |
if (nr != len) |
|---|
| 921 |
break; |
|---|
| 922 |
} |
|---|
| 923 |
out: |
|---|
| 924 |
if (iov != iovstack) |
|---|
| 925 |
kfree(iov); |
|---|
| 926 |
if ((ret + (type == READ)) > 0) |
|---|
| 927 |
dnotify_parent(file->f_dentry, |
|---|
| 928 |
(type == READ) ? DN_ACCESS : DN_MODIFY); |
|---|
| 929 |
return ret; |
|---|
| 930 |
} |
|---|
| 931 |
|
|---|
| 932 |
asmlinkage ssize_t |
|---|
| 933 |
compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec, unsigned long vlen) |
|---|
| 934 |
{ |
|---|
| 935 |
struct file *file; |
|---|
| 936 |
ssize_t ret = -EBADF; |
|---|
| 937 |
|
|---|
| 938 |
file = fget(fd); |
|---|
| 939 |
if (!file) |
|---|
| 940 |
return -EBADF; |
|---|
| 941 |
|
|---|
| 942 |
if (!(file->f_mode & FMODE_READ)) |
|---|
| 943 |
goto out; |
|---|
| 944 |
|
|---|
| 945 |
ret = -EINVAL; |
|---|
| 946 |
if (!file->f_op || (!file->f_op->readv && !file->f_op->read)) |
|---|
| 947 |
goto out; |
|---|
| 948 |
|
|---|
| 949 |
ret = compat_do_readv_writev(READ, file, vec, vlen, &file->f_pos); |
|---|
| 950 |
|
|---|
| 951 |
out: |
|---|
| 952 |
fput(file); |
|---|
| 953 |
return ret; |
|---|
| 954 |
} |
|---|
| 955 |
|
|---|
| 956 |
asmlinkage ssize_t |
|---|
| 957 |
compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec, unsigned long vlen) |
|---|
| 958 |
{ |
|---|
| 959 |
struct file *file; |
|---|
| 960 |
ssize_t ret = -EBADF; |
|---|
| 961 |
|
|---|
| 962 |
file = fget(fd); |
|---|
| 963 |
if (!file) |
|---|
| 964 |
return -EBADF; |
|---|
| 965 |
if (!(file->f_mode & FMODE_WRITE)) |
|---|
| 966 |
goto out; |
|---|
| 967 |
|
|---|
| 968 |
ret = -EINVAL; |
|---|
| 969 |
if (!file->f_op || (!file->f_op->writev && !file->f_op->write)) |
|---|
| 970 |
goto out; |
|---|
| 971 |
|
|---|
| 972 |
ret = compat_do_readv_writev(WRITE, file, vec, vlen, &file->f_pos); |
|---|
| 973 |
|
|---|
| 974 |
out: |
|---|
| 975 |
fput(file); |
|---|
| 976 |
return ret; |
|---|
| 977 |
} |
|---|
| 978 |
|
|---|
| 979 |
|
|---|
| 980 |
|
|---|
| 981 |
|
|---|
| 982 |
|
|---|
| 983 |
|
|---|
| 984 |
static int compat_count(compat_uptr_t __user *argv, int max) |
|---|
| 985 |
{ |
|---|
| 986 |
int i = 0; |
|---|
| 987 |
|
|---|
| 988 |
if (argv != NULL) { |
|---|
| 989 |
for (;;) { |
|---|
| 990 |
compat_uptr_t p; |
|---|
| 991 |
|
|---|
| 992 |
if (get_user(p, argv)) |
|---|
| 993 |
return -EFAULT; |
|---|
| 994 |
if (!p) |
|---|
| 995 |
break; |
|---|
| 996 |
argv++; |
|---|
| 997 |
if(++i > max) |
|---|
| 998 |
return -E2BIG; |
|---|
| 999 |
} |
|---|
| 1000 |
} |
|---|
| 1001 |
return i; |
|---|
| 1002 |
} |
|---|
| 1003 |
|
|---|
| 1004 |
|
|---|
| 1005 |
|
|---|
| 1006 |
|
|---|
| 1007 |
|
|---|
| 1008 |
static int compat_copy_strings(int argc, compat_uptr_t __user *argv, |
|---|
| 1009 |
struct linux_binprm *bprm) |
|---|
| 1010 |
{ |
|---|
| 1011 |
struct page *kmapped_page = NULL; |
|---|
| 1012 |
char *kaddr = NULL; |
|---|
| 1013 |
int ret; |
|---|
| 1014 |
|
|---|
| 1015 |
while (argc-- > 0) { |
|---|
| 1016 |
compat_uptr_t str; |
|---|
| 1017 |
int len; |
|---|
| 1018 |
unsigned long pos; |
|---|
| 1019 |
|
|---|
| 1020 |
if (get_user(str, argv+argc) || |
|---|
| 1021 |
!(len = strnlen_user(compat_ptr(str), bprm->p))) { |
|---|
| 1022 |
ret = -EFAULT; |
|---|
| 1023 |
goto out; |
|---|
| 1024 |
} |
|---|
| 1025 |
|
|---|
| 1026 |
if (bprm->p < len) { |
|---|
| 1027 |
ret = -E2BIG; |
|---|
| 1028 |
goto out; |
|---|
| 1029 |
} |
|---|
| 1030 |
|
|---|
| 1031 |
bprm->p -= len; |
|---|
| 1032 |
|
|---|
| 1033 |
pos = bprm->p; |
|---|
| 1034 |
|
|---|
| 1035 |
while (len > 0) { |
|---|
| 1036 |
int i, new, err; |
|---|
| 1037 |
int offset, bytes_to_copy; |
|---|
| 1038 |
struct page *page; |
|---|
| 1039 |
|
|---|
| 1040 |
offset = pos % PAGE_SIZE; |
|---|
| 1041 |
i = pos/PAGE_SIZE; |
|---|
| 1042 |
page = bprm->page[i]; |
|---|
| 1043 |
new = 0; |
|---|
| 1044 |
if (!page) { |
|---|
| 1045 |
page = alloc_page(GFP_HIGHUSER); |
|---|
| 1046 |
bprm->page[i] = page; |
|---|
| 1047 |
if (!page) { |
|---|
| 1048 |
ret = -ENOMEM; |
|---|
| 1049 |
goto out; |
|---|
| 1050 |
} |
|---|
| 1051 |
new = 1; |
|---|
| 1052 |
} |
|---|
| 1053 |
|
|---|
| 1054 |
if (page != kmapped_page) { |
|---|
| 1055 |
if (kmapped_page) |
|---|
| 1056 |
kunmap(kmapped_page); |
|---|
| 1057 |
kmapped_page = page; |
|---|
| 1058 |
kaddr = kmap(kmapped_page); |
|---|
| 1059 |
} |
|---|
| 1060 |
if (new && offset) |
|---|
| 1061 |
memset(kaddr, 0, offset); |
|---|
| 1062 |
bytes_to_copy = PAGE_SIZE - offset; |
|---|
| 1063 |
if (bytes_to_copy > len) { |
|---|
| 1064 |
bytes_to_copy = len; |
|---|
| 1065 |
if (new) |
|---|
| 1066 |
memset(kaddr+offset+len, 0, |
|---|
| 1067 |
PAGE_SIZE-offset-len); |
|---|
| 1068 |
} |
|---|
| 1069 |
err = copy_from_user(kaddr+offset, compat_ptr(str), |
|---|
| 1070 |
bytes_to_copy); |
|---|
| 1071 |
if (err) { |
|---|
| 1072 |
ret = -EFAULT; |
|---|
| 1073 |
goto out; |
|---|
| 1074 |
} |
|---|
| 1075 |
|
|---|
| 1076 |
pos += bytes_to_copy; |
|---|
| 1077 |
str += bytes_to_copy; |
|---|
| 1078 |
len -= bytes_to_copy; |
|---|
| 1079 |
} |
|---|
| 1080 |
} |
|---|
| 1081 |
ret = 0; |
|---|
| 1082 |
out: |
|---|
| 1083 |
if (kmapped_page) |
|---|
| 1084 |
kunmap(kmapped_page); |
|---|
| 1085 |
return ret; |
|---|
| 1086 |
} |
|---|
| 1087 |
|
|---|
| 1088 |
#ifdef CONFIG_MMU |
|---|
| 1089 |
|
|---|
| 1090 |
#define free_arg_pages(bprm) do { } while (0) |
|---|
| 1091 |
|
|---|
| 1092 |
#else |
|---|
| 1093 |
|
|---|
| 1094 |
static inline void free_arg_pages(struct linux_binprm *bprm) |
|---|
| 1095 |
{ |
|---|
| 1096 |
int i; |
|---|
| 1097 |
|
|---|
| 1098 |
for (i = 0; i < MAX_ARG_PAGES; i++) { |
|---|
| 1099 |
if (bprm->page[i]) |
|---|
| 1100 |
__free_page(bprm->page[i]); |
|---|
| 1101 |
bprm->page[i] = NULL; |
|---|
| 1102 |
} |
|---|
| 1103 |
} |
|---|
| 1104 |
|
|---|
| 1105 |
#endif |
|---|
| 1106 |
|
|---|
| 1107 |
|
|---|
| 1108 |
|
|---|
| 1109 |
|
|---|
| 1110 |
|
|---|
| 1111 |
int compat_do_execve(char * filename, |
|---|
| 1112 |
compat_uptr_t __user *argv, |
|---|
| 1113 |
compat_uptr_t __user *envp, |
|---|
| 1114 |
struct pt_regs * regs) |
|---|
| 1115 |
{ |
|---|
| 1116 |
struct linux_binprm bprm; |
|---|
| 1117 |
struct file *file; |
|---|
| 1118 |
int retval; |
|---|
| 1119 |
int i; |
|---|
| 1120 |
|
|---|
| 1121 |
sched_balance_exec(); |
|---|
| 1122 |
|
|---|
| 1123 |
file = open_exec(filename); |
|---|
| 1124 |
|
|---|
| 1125 |
retval = PTR_ERR(file); |
|---|
| 1126 |
if (IS_ERR(file)) |
|---|
| 1127 |
return retval; |
|---|
| 1128 |
|
|---|
| 1129 |
bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *); |
|---|
| 1130 |
memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0])); |
|---|
| 1131 |
|
|---|
| 1132 |
bprm.file = file; |
|---|
| 1133 |
bprm.filename = filename; |
|---|
| 1134 |
bprm.interp = filename; |
|---|
| 1135 |
bprm.sh_bang = 0; |
|---|
| 1136 |
bprm.loader = 0; |
|---|
| 1137 |
bprm.exec = 0; |
|---|
| 1138 |
bprm.security = NULL; |
|---|
| 1139 |
bprm.mm = mm_alloc(); |
|---|
| 1140 |
retval = -ENOMEM; |
|---|
| 1141 |
if (!bprm.mm) |
|---|
| 1142 |
goto out_file; |
|---|
| 1143 |
|
|---|
| 1144 |
retval = init_new_context(current, bprm.mm); |
|---|
| 1145 |
if (retval < 0) |
|---|
| 1146 |
goto out_mm; |
|---|
| 1147 |
|
|---|
| 1148 |
bprm.argc = compat_count(argv, bprm.p / sizeof(compat_uptr_t)); |
|---|
| 1149 |
if ((retval = bprm.argc) < 0) |
|---|
| 1150 |
goto out_mm; |
|---|
| 1151 |
|
|---|
| 1152 |
bprm.envc = compat_count(envp, bprm.p / sizeof(compat_uptr_t)); |
|---|
| 1153 |
if ((retval = bprm.envc) < 0) |
|---|
| 1154 |
goto out_mm; |
|---|
| 1155 |
|
|---|
| 1156 |
retval = security_bprm_alloc(&bprm); |
|---|
| 1157 |
if (retval) |
|---|
| 1158 |
goto out; |
|---|
| 1159 |
|
|---|
| 1160 |
retval = prepare_binprm(&bprm); |
|---|
| 1161 |
if (retval < 0) |
|---|
| 1162 |
goto out; |
|---|
| 1163 |
|
|---|
| 1164 |
retval = copy_strings_kernel(1, &bprm.filename, &bprm); |
|---|
| 1165 |
if (retval < 0) |
|---|
| 1166 |
goto out; |
|---|
| 1167 |
|
|---|
| 1168 |
bprm.exec = bprm.p; |
|---|
| 1169 |
retval = compat_copy_strings(bprm.envc, envp, &bprm); |
|---|
| 1170 |
if (retval < 0) |
|---|
| 1171 |
goto out; |
|---|
| 1172 |
|
|---|
| 1173 |
retval = compat_copy_strings(bprm.argc, argv, &bprm); |
|---|
| 1174 |
if (retval < 0) |
|---|
| 1175 |
goto out; |
|---|
| 1176 |
|
|---|
| 1177 |
retval = search_binary_handler(&bprm,regs); |
|---|
| 1178 |
if (retval >= 0) { |
|---|
| 1179 |
free_arg_pages(&bprm); |
|---|
| 1180 |
|
|---|
| 1181 |
|
|---|
| 1182 |
security_bprm_free(&bprm); |
|---|
| 1183 |
return retval; |
|---|
| 1184 |
} |
|---|
| 1185 |
|
|---|
| 1186 |
out: |
|---|
| 1187 |
|
|---|
| 1188 |
for (i = 0 ; i < MAX_ARG_PAGES ; i++) { |
|---|
| 1189 |
struct page * page = bprm.page[i]; |
|---|
| 1190 |
if (page) |
|---|
| 1191 |
__free_page(page); |
|---|
| 1192 |
} |
|---|
| 1193 |
|
|---|
| 1194 |
if (bprm.security) |
|---|
| 1195 |
security_bprm_free(&bprm); |
|---|
| 1196 |
|
|---|
| 1197 |
out_mm: |
|---|
| 1198 |
if (bprm.mm) |
|---|
| 1199 |
mmdrop(bprm.mm); |
|---|
| 1200 |
|
|---|
| 1201 |
out_file: |
|---|
| 1202 |
if (bprm.file) { |
|---|
| 1203 |
allow_write_access(bprm.file); |
|---|
| 1204 |
fput(bprm.file); |
|---|
| 1205 |
} |
|---|
| 1206 |
|
|---|
| 1207 |
return retval; |
|---|
| 1208 |
} |
|---|
| 1209 |
|
|---|
| 1210 |
#define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t)) |
|---|
| 1211 |
|
|---|
| 1212 |
#define ROUND_UP(x,y) (((x)+(y)-1)/(y)) |
|---|
| 1213 |
|
|---|
| 1214 |
|
|---|
| 1215 |
|
|---|
| 1216 |
|
|---|
| 1217 |
|
|---|
| 1218 |
static inline |
|---|
| 1219 |
int compat_get_fd_set(unsigned long nr, compat_ulong_t __user *ufdset, |
|---|
| 1220 |
unsigned long *fdset) |
|---|
| 1221 |
{ |
|---|
| 1222 |
nr = ROUND_UP(nr, __COMPAT_NFDBITS); |
|---|
| 1223 |
if (ufdset) { |
|---|
| 1224 |
unsigned long odd; |
|---|
| 1225 |
|
|---|
| 1226 |
if (verify_area(VERIFY_WRITE, ufdset, nr*sizeof(compat_ulong_t))) |
|---|
| 1227 |
return -EFAULT; |
|---|
| 1228 |
|
|---|
| 1229 |
odd = nr & 1UL; |
|---|
| 1230 |
nr &= ~1UL; |
|---|
| 1231 |
while (nr) { |
|---|
| 1232 |
unsigned long h, l; |
|---|
| 1233 |
__get_user(l, ufdset); |
|---|
| 1234 |
__get_user(h, ufdset+1); |
|---|
| 1235 |
ufdset += 2; |
|---|
| 1236 |
*fdset++ = h << 32 | l; |
|---|
| 1237 |
nr -= 2; |
|---|
| 1238 |
} |
|---|
| 1239 |
if (odd) |
|---|
| 1240 |
__get_user(*fdset, ufdset); |
|---|
| 1241 |
} else { |
|---|
| 1242 |
|
|---|
| 1243 |
|
|---|
| 1244 |
|
|---|
| 1245 |
|
|---|
| 1246 |
memset(fdset, 0, ((nr + 1) & ~1)*sizeof(compat_ulong_t)); |
|---|
| 1247 |
} |
|---|
| 1248 |
return 0; |
|---|
| 1249 |
} |
|---|
| 1250 |
|
|---|
| 1251 |
static inline |
|---|
| 1252 |
void compat_set_fd_set(unsigned long nr, compat_ulong_t __user *ufdset, |
|---|
| 1253 |
unsigned long *fdset) |
|---|
| 1254 |
{ |
|---|
| 1255 |
unsigned long odd; |
|---|
| 1256 |
nr = ROUND_UP(nr, __COMPAT_NFDBITS); |
|---|
| 1257 |
|
|---|
| 1258 |
if (!ufdset) |
|---|
| 1259 |
return; |
|---|
| 1260 |
|
|---|
| 1261 |
odd = nr & 1UL; |
|---|
| 1262 |
nr &= ~1UL; |
|---|
| 1263 |
while (nr) { |
|---|
| 1264 |
unsigned long h, l; |
|---|
| 1265 |
l = *fdset++; |
|---|
| 1266 |
h = l >> 32; |
|---|
| 1267 |
__put_user(l, ufdset); |
|---|
| 1268 |
__put_user(h, ufdset+1); |
|---|
| 1269 |
ufdset += 2; |
|---|
| 1270 |
nr -= 2; |
|---|
| 1271 |
} |
|---|
| 1272 |
if (odd) |
|---|
| 1273 |
__put_user(*fdset, ufdset); |
|---|
| 1274 |
} |
|---|
| 1275 |
|
|---|
| 1276 |
|
|---|
| 1277 |
|
|---|
| 1278 |
|
|---|
| 1279 |
|
|---|
| 1280 |
|
|---|
| 1281 |
static void *select_bits_alloc(int size) |
|---|
| 1282 |
{ |
|---|
| 1283 |
return kmalloc(6 * size, GFP_KERNEL); |
|---|
| 1284 |
} |
|---|
| 1285 |
|
|---|
| 1286 |
static void select_bits_free(void *bits, int size) |
|---|
| 1287 |
{ |
|---|
| 1288 |
kfree(bits); |
|---|
| 1289 |
} |
|---|
| 1290 |
|
|---|
| 1291 |
|
|---|
| 1292 |
|
|---|
| 1293 |
|
|---|
| 1294 |
|
|---|
| 1295 |
|
|---|
| 1296 |
|
|---|
| 1297 |
|
|---|
| 1298 |
|
|---|
| 1299 |
#define MAX_SELECT_SECONDS \ |
|---|
| 1300 |
((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1) |
|---|
| 1301 |
|
|---|
| 1302 |
asmlinkage long |
|---|
| 1303 |
compat_sys_select(int n, compat_ulong_t __user *inp, compat_ulong_t __user *outp, |
|---|
| 1304 |
compat_ulong_t __user *exp, struct compat_timeval __user *tvp) |
|---|
| 1305 |
{ |
|---|
| 1306 |
fd_set_bits fds; |
|---|
| 1307 |
char *bits; |
|---|
| 1308 |
long timeout; |
|---|
| 1309 |
int ret, size, max_fdset; |
|---|
| 1310 |
|
|---|
| 1311 |
timeout = MAX_SCHEDULE_TIMEOUT; |
|---|
| 1312 |
if (tvp) { |
|---|
| 1313 |
time_t sec, usec; |
|---|
| 1314 |
|
|---|
| 1315 |
if ((ret = verify_area(VERIFY_READ, tvp, sizeof(*tvp))) |
|---|
| 1316 |
|| (ret = __get_user(sec, &tvp->tv_sec)) |
|---|
| 1317 |
|| (ret = __get_user(usec, &tvp->tv_usec))) |
|---|
| 1318 |
goto out_nofds; |
|---|
| 1319 |
|
|---|
| 1320 |
ret = -EINVAL; |
|---|
| 1321 |
if (sec < 0 || usec < 0) |
|---|
| 1322 |
goto out_nofds; |
|---|
| 1323 |
|
|---|
| 1324 |
if ((unsigned long) sec < MAX_SELECT_SECONDS) { |
|---|
| 1325 |
timeout = ROUND_UP(usec, 1000000/HZ); |
|---|
| 1326 |
timeout += sec * (unsigned long) HZ; |
|---|
| 1327 |
} |
|---|
| 1328 |
} |
|---|
| 1329 |
|
|---|
| 1330 |
ret = -EINVAL; |
|---|
| 1331 |
if (n < 0) |
|---|
| 1332 |
goto out_nofds; |
|---|
| 1333 |
|
|---|
| 1334 |
|
|---|
| 1335 |
max_fdset = current->files->max_fdset; |
|---|
| 1336 |
if (n > max_fdset) |
|---|
| 1337 |
n = max_fdset; |
|---|
| 1338 |
|
|---|
| 1339 |
|
|---|
| 1340 |
|
|---|
| 1341 |
|
|---|
| 1342 |
|
|---|
| 1343 |
|
|---|
| 1344 |
ret = -ENOMEM; |
|---|
| 1345 |
size = FDS_BYTES(n); |
|---|
| 1346 |
bits = select_bits_alloc(size); |
|---|
| 1347 |
if (!bits) |
|---|
| 1348 |
goto out_nofds; |
|---|
| 1349 |
fds.in = (unsigned long *) bits; |
|---|
| 1350 |
fds.out = (unsigned long *) (bits + size); |
|---|
| 1351 |
fds.ex = (unsigned long *) (bits + 2*size); |
|---|
| 1352 |
fds.res_in = (unsigned long *) (bits + 3*size); |
|---|
| 1353 |
fds.res_out = (unsigned long *) (bits + 4*size); |
|---|
| 1354 |
fds.res_ex = (unsigned long *) (bits + 5*size); |
|---|
| 1355 |
|
|---|
| 1356 |
if ((ret = compat_get_fd_set(n, inp, fds.in)) || |
|---|
| 1357 |
(ret = compat_get_fd_set(n, outp, fds.out)) || |
|---|
| 1358 |
(ret = compat_get_fd_set(n, exp, fds.ex))) |
|---|
| 1359 |
goto out; |
|---|
| 1360 |
zero_fd_set(n, fds.res_in); |
|---|
| 1361 |
zero_fd_set(n, fds.res_out); |
|---|
| 1362 |
zero_fd_set(n, fds.res_ex); |
|---|
| 1363 |
|
|---|
| 1364 |
ret = do_select(n, &fds, &timeout); |
|---|
| 1365 |
|
|---|
| 1366 |
if (tvp && !(current->personality & STICKY_TIMEOUTS)) { |
|---|
| 1367 |
time_t sec = 0, usec = 0; |
|---|
| 1368 |
if (timeout) { |
|---|
| 1369 |
sec = timeout / HZ; |
|---|
| 1370 |
usec = timeout % HZ; |
|---|
| 1371 |
usec *= (1000000/HZ); |
|---|
| 1372 |
} |
|---|
| 1373 |
if (put_user(sec, &tvp->tv_sec) || |
|---|
| 1374 |
put_user(usec, &tvp->tv_usec)) |
|---|
| 1375 |
ret = -EFAULT; |
|---|
| 1376 |
} |
|---|
| 1377 |
|
|---|
| 1378 |
if (ret < 0) |
|---|
| 1379 |
goto out; |
|---|
| 1380 |
if (!ret) { |
|---|
| 1381 |
ret = -ERESTARTNOHAND; |
|---|
| 1382 |
if (signal_pending(current)) |
|---|
| 1383 |
goto out; |
|---|
| 1384 |
ret = 0; |
|---|
| 1385 |
} |
|---|
| 1386 |
|
|---|
| 1387 |
compat_set_fd_set(n, inp, fds.res_in); |
|---|
| 1388 |
compat_set_fd_set(n, outp, fds.res_out); |
|---|
| 1389 |
compat_set_fd_set(n, exp, fds.res_ex); |
|---|
| 1390 |
|
|---|
| 1391 |
out: |
|---|
| 1392 |
select_bits_free(bits, size); |
|---|
| 1393 |
out_nofds: |
|---|
| 1394 |
return ret; |
|---|
| 1395 |
} |
|---|
| 1396 |
|
|---|
| 1397 |
#if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE) |
|---|
| 1398 |
|
|---|
| 1399 |
struct compat_nfsctl_svc { |
|---|
| 1400 |
u16 svc32_port; |
|---|
| 1401 |
s32 svc32_nthreads; |
|---|
| 1402 |
}; |
|---|
| 1403 |
|
|---|
| 1404 |
struct compat_nfsctl_client { |
|---|
| 1405 |
s8 cl32_ident[NFSCLNT_IDMAX+1]; |
|---|
| 1406 |
s32 cl32_naddr; |
|---|
| 1407 |
struct in_addr cl32_addrlist[NFSCLNT_ADDRMAX]; |
|---|
| 1408 |
s32 cl32_fhkeytype; |
|---|
| 1409 |
s32 cl32_fhkeylen; |
|---|
| 1410 |
u8 cl32_fhkey[NFSCLNT_KEYMAX]; |
|---|
| 1411 |
}; |
|---|
| 1412 |
|
|---|
| 1413 |
struct compat_nfsctl_export { |
|---|
| 1414 |
char ex32_client[NFSCLNT_IDMAX+1]; |
|---|
| 1415 |
char ex32_path[NFS_MAXPATHLEN+1]; |
|---|
| 1416 |
compat_dev_t ex32_dev; |
|---|
| 1417 |
compat_ino_t ex32_ino; |
|---|
| 1418 |
compat_int_t ex32_flags; |
|---|
| 1419 |
compat_uid_t ex32_anon_uid; |
|---|
| 1420 |
compat_gid_t ex32_anon_gid; |
|---|
| 1421 |
}; |
|---|
| 1422 |
|
|---|
| 1423 |
struct compat_nfsctl_fdparm { |
|---|
| 1424 |
struct sockaddr gd32_addr; |
|---|
| 1425 |
s8 gd32_path[NFS_MAXPATHLEN+1]; |
|---|
| 1426 |
compat_int_t gd32_version; |
|---|
| 1427 |
}; |
|---|
| 1428 |
|
|---|
| 1429 |
struct compat_nfsctl_fsparm { |
|---|
| 1430 |
struct sockaddr gd32_addr; |
|---|
| 1431 |
s8 gd32_path[NFS_MAXPATHLEN+1]; |
|---|
| 1432 |
compat_int_t gd32_maxlen; |
|---|
| 1433 |
}; |
|---|
| 1434 |
|
|---|
| 1435 |
struct compat_nfsctl_arg { |
|---|
| 1436 |
compat_int_t ca32_version; |
|---|
| 1437 |
union { |
|---|
| 1438 |
struct compat_nfsctl_svc u32_svc; |
|---|
| 1439 |
struct compat_nfsctl_client u32_client; |
|---|
| 1440 |
struct compat_nfsctl_export u32_export; |
|---|
| 1441 |
struct compat_nfsctl_fdparm u32_getfd; |
|---|
| 1442 |
struct compat_nfsctl_fsparm u32_getfs; |
|---|
| 1443 |
} u; |
|---|
| 1444 |
#define ca32_svc u.u32_svc |
|---|
| 1445 |
#define ca32_client u.u32_client |
|---|
| 1446 |
#define ca32_export u.u32_export |
|---|
| 1447 |
#define ca32_getfd u.u32_getfd |
|---|
| 1448 |
#define ca32_getfs u.u32_getfs |
|---|
| 1449 |
}; |
|---|
| 1450 |
|
|---|
| 1451 |
union compat_nfsctl_res { |
|---|
| 1452 |
__u8 cr32_getfh[NFS_FHSIZE]; |
|---|
| 1453 |
struct knfsd_fh cr32_getfs; |
|---|
| 1454 |
}; |
|---|
| 1455 |
|
|---|
| 1456 |
static int compat_nfs_svc_trans(struct nfsctl_arg *karg, struct compat_nfsctl_arg __user *arg) |
|---|
| 1457 |
{ |
|---|
| 1458 |
int err; |
|---|
| 1459 |
|
|---|
| 1460 |
err = access_ok(VERIFY_READ, &arg->ca32_svc, sizeof(arg->ca32_svc)); |
|---|
| 1461 |
err |= get_user(karg->ca_version, &arg->ca32_version); |
|---|
| 1462 |
err |= __get_user(karg->ca_svc.svc_port, &arg->ca32_svc.svc32_port); |
|---|
| 1463 |
err |= __get_user(karg->ca_svc.svc_nthreads, &arg->ca32_svc.svc32_nthreads); |
|---|
| 1464 |
return (err) ? -EFAULT : 0; |
|---|
| 1465 |
} |
|---|
| 1466 |
|
|---|
| 1467 |
static int compat_nfs_clnt_trans(struct nfsctl_arg *karg, struct compat_nfsctl_arg __user *arg) |
|---|
| 1468 |
{ |
|---|
| 1469 |
int err; |
|---|
| 1470 |
|
|---|
| 1471 |
err = access_ok(VERIFY_READ, &arg->ca32_client, sizeof(arg->ca32_client)); |
|---|
| 1472 |
err |= get_user(karg->ca_version, &arg->ca32_version); |
|---|
| 1473 |
err |= __copy_from_user(&karg->ca_client.cl_ident[0], |
|---|
| 1474 |
&arg->ca32_client.cl32_ident[0], |
|---|
| 1475 |
NFSCLNT_IDMAX); |
|---|
| 1476 |
err |= __get_user(karg->ca_client.cl_naddr, &arg->ca32_client.cl32_naddr); |
|---|
| 1477 |
err |= __copy_from_user(&karg->ca_client.cl_addrlist[0], |
|---|
| 1478 |
&arg->ca32_client.cl32_addrlist[0], |
|---|
| 1479 |
(sizeof(struct in_addr) * NFSCLNT_ADDRMAX)); |
|---|
| 1480 |
err |= __get_user(karg->ca_client.cl_fhkeytype, |
|---|
| 1481 |
&arg->ca32_client.cl32_fhkeytype); |
|---|
| 1482 |
err |= __get_user(karg->ca_client.cl_fhkeylen, |
|---|
| 1483 |
&arg->ca32_client.cl32_fhkeylen); |
|---|
| 1484 |
err |= __copy_from_user(&karg->ca_client.cl_fhkey[0], |
|---|
| 1485 |
&arg->ca32_client.cl32_fhkey[0], |
|---|
| 1486 |
NFSCLNT_KEYMAX); |
|---|
| 1487 |
|
|---|
| 1488 |
return (err) ? -EFAULT : 0; |
|---|
| 1489 |
} |
|---|
| 1490 |
|
|---|
| 1491 |
static int compat_nfs_exp_trans(struct nfsctl_arg *karg, struct compat_nfsctl_arg __user *arg) |
|---|
| 1492 |
{ |
|---|
| 1493 |
int err; |
|---|
| 1494 |
|
|---|
| 1495 |
err = access_ok(VERIFY_READ, &arg->ca32_export, sizeof(arg->ca32_export)); |
|---|
| 1496 |
err |= get_user(karg->ca_version, &arg->ca32_version); |
|---|
| 1497 |
err |= __copy_from_user(&karg->ca_export.ex_client[0], |
|---|
| 1498 |
&arg->ca32_export.ex32_client[0], |
|---|
| 1499 |
NFSCLNT_IDMAX); |
|---|
| 1500 |
err |= __copy_from_user(&karg->ca_export.ex_path[0], |
|---|
| 1501 |
&arg->ca32_export.ex32_path[0], |
|---|
| 1502 |
NFS_MAXPATHLEN); |
|---|
| 1503 |
err |= __get_user(karg->ca_export.ex_dev, |
|---|
| 1504 |
&arg->ca32_export.ex32_dev); |
|---|
| 1505 |
err |= __get_user(karg->ca_export.ex_ino, |
|---|
| 1506 |
&arg->ca32_export.ex32_ino); |
|---|
| 1507 |
err |= __get_user(karg->ca_export.ex_flags, |
|---|
| 1508 |
&arg->ca32_export.ex32_flags); |
|---|
| 1509 |
err |= __get_user(karg->ca_export.ex_anon_uid, |
|---|
| 1510 |
&arg->ca32_export.ex32_anon_uid); |
|---|
| 1511 |
err |= __get_user(karg->ca_export.ex_anon_gid, |
|---|
| 1512 |
&arg->ca32_export.ex32_anon_gid); |
|---|
| 1513 |
SET_UID(karg->ca_export.ex_anon_uid, karg->ca_export.ex_anon_uid); |
|---|
| 1514 |
SET_GID(karg->ca_export.ex_anon_gid, karg->ca_export.ex_anon_gid); |
|---|
| 1515 |
|
|---|
| 1516 |
return (err) ? -EFAULT : 0; |
|---|
| 1517 |
} |
|---|
| 1518 |
|
|---|
| 1519 |
static int compat_nfs_getfd_trans(struct nfsctl_arg *karg, struct compat_nfsctl_arg __user *arg) |
|---|
| 1520 |
{ |
|---|
| 1521 |
int err; |
|---|
| 1522 |
|
|---|
| 1523 |
err = access_ok(VERIFY_READ, &arg->ca32_getfd, sizeof(arg->ca32_getfd)); |
|---|
| 1524 |
err |= get_user(karg->ca_version, &arg->ca32_version); |
|---|
| 1525 |
err |= __copy_from_user(&karg->ca_getfd.gd_addr, |
|---|
| 1526 |
&arg->ca32_getfd.gd32_addr, |
|---|
| 1527 |
(sizeof(struct sockaddr))); |
|---|
| 1528 |
err |= __copy_from_user(&karg->ca_getfd.gd_path, |
|---|
| 1529 |
&arg->ca32_getfd.gd32_path, |
|---|
| 1530 |
(NFS_MAXPATHLEN+1)); |
|---|
| 1531 |
err |= __get_user(karg->ca_getfd.gd_version, |
|---|
| 1532 |
&arg->ca32_getfd.gd32_version); |
|---|
| 1533 |
|
|---|
| 1534 |
return (err) ? -EFAULT : 0; |
|---|
| 1535 |
} |
|---|
| 1536 |
|
|---|
| 1537 |
static int compat_nfs_getfs_trans(struct nfsctl_arg *karg, struct compat_nfsctl_arg __user *arg) |
|---|
| 1538 |
{ |
|---|
| 1539 |
int err; |
|---|
| 1540 |
|
|---|
| 1541 |
err = access_ok(VERIFY_READ, &arg->ca32_getfs, sizeof(arg->ca32_getfs)); |
|---|
| 1542 |
err |= get_user(karg->ca_version, &arg->ca32_version); |
|---|
| 1543 |
err |= __copy_from_user(&karg->ca_getfs.gd_addr, |
|---|
| 1544 |
&arg->ca32_getfs.gd32_addr, |
|---|
| 1545 |
(sizeof(struct sockaddr))); |
|---|
| 1546 |
err |= __copy_from_user(&karg->ca_getfs.gd_path, |
|---|
| 1547 |
&arg->ca32_getfs.gd32_path, |
|---|
| 1548 |
(NFS_MAXPATHLEN+1)); |
|---|
| 1549 |
err |= __get_user(karg->ca_getfs.gd_maxlen, |
|---|
| 1550 |
&arg->ca32_getfs.gd32_maxlen); |
|---|
| 1551 |
|
|---|
| 1552 |
return (err) ? -EFAULT : 0; |
|---|
| 1553 |
} |
|---|
| 1554 |
|
|---|
| 1555 |
|
|---|
| 1556 |
|
|---|
| 1557 |
|
|---|
| 1558 |
static int compat_nfs_getfh_res_trans(union nfsctl_res *kres, union compat_nfsctl_res __user *res) |
|---|
| 1559 |
{ |
|---|
| 1560 |
int err; |
|---|
| 1561 |
|
|---|
| 1562 |
err = copy_to_user(res, kres, sizeof(*res)); |
|---|
| 1563 |
|
|---|
| 1564 |
return (err) ? -EFAULT : 0; |
|---|
| 1565 |
} |
|---|
| 1566 |
|
|---|
| 1567 |
asmlinkage long compat_sys_nfsservctl(int cmd, struct compat_nfsctl_arg __user *arg, |
|---|
| 1568 |
union compat_nfsctl_res __user *res) |
|---|
| 1569 |
{ |
|---|
| 1570 |
struct nfsctl_arg *karg; |
|---|
| 1571 |
union nfsctl_res *kres; |
|---|
| 1572 |
mm_segment_t oldfs; |
|---|
| 1573 |
int err; |
|---|
| 1574 |
|
|---|
| 1575 |
karg = kmalloc(sizeof(*karg), GFP_USER); |
|---|
| 1576 |
kres = kmalloc(sizeof(*kres), GFP_USER); |
|---|
| 1577 |
if(!karg || !kres) { |
|---|
| 1578 |
err = -ENOMEM; |
|---|
| 1579 |
goto done; |
|---|
| 1580 |
} |
|---|
| 1581 |
|
|---|
| 1582 |
switch(cmd) { |
|---|
| 1583 |
case NFSCTL_SVC: |
|---|
| 1584 |
err = compat_nfs_svc_trans(karg, arg); |
|---|
| 1585 |
break; |
|---|
| 1586 |
|
|---|
| 1587 |
case NFSCTL_ADDCLIENT: |
|---|
| 1588 |
err = compat_nfs_clnt_trans(karg, arg); |
|---|
| 1589 |
break; |
|---|
| 1590 |
|
|---|
| 1591 |
case NFSCTL_DELCLIENT: |
|---|
| 1592 |
err = compat_nfs_clnt_trans(karg, arg); |
|---|
| 1593 |
break; |
|---|
| 1594 |
|
|---|
| 1595 |
case NFSCTL_EXPORT: |
|---|
| 1596 |
case NFSCTL_UNEXPORT: |
|---|
| 1597 |
err = compat_nfs_exp_trans(karg, arg); |
|---|
| 1598 |
break; |
|---|
| 1599 |
|
|---|
| 1600 |
case NFSCTL_GETFD: |
|---|
| 1601 |
err = compat_nfs_getfd_trans(karg, arg); |
|---|
| 1602 |
break; |
|---|
| 1603 |
|
|---|
| 1604 |
case NFSCTL_GETFS: |
|---|
| 1605 |
err = compat_nfs_getfs_trans(karg, arg); |
|---|
| 1606 |
break; |
|---|
| 1607 |
|
|---|
| 1608 |
default: |
|---|
| 1609 |
err = -EINVAL; |
|---|
| 1610 |
goto done; |
|---|
| 1611 |
} |
|---|
| 1612 |
|
|---|
| 1613 |
oldfs = get_fs(); |
|---|
| 1614 |
set_fs(KERNEL_DS); |
|---|
| 1615 |
|
|---|
| 1616 |
err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres); |
|---|
| 1617 |
set_fs(oldfs); |
|---|
| 1618 |
|
|---|
| 1619 |
if (err) |
|---|
| 1620 |
goto done; |
|---|
| 1621 |
|
|---|
| 1622 |
if((cmd == NFSCTL_GETFD) || |
|---|
| 1623 |
(cmd == NFSCTL_GETFS)) |
|---|
| 1624 |
err = compat_nfs_getfh_res_trans(kres, res); |
|---|
| 1625 |
|
|---|
| 1626 |
done: |
|---|
| 1627 |
kfree(karg); |
|---|
| 1628 |
kfree(kres); |
|---|
| 1629 |
return err; |
|---|
| 1630 |
} |
|---|
| 1631 |
#else |
|---|
| 1632 |
long asmlinkage compat_sys_nfsservctl(int cmd, void *notused, void *notused2) |
|---|
| 1633 |
{ |
|---|
| 1634 |
return sys_ni_syscall(); |
|---|
| 1635 |
} |
|---|
| 1636 |
#endif |
|---|
| 1637 |
|
|---|