aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ioctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r--fs/btrfs/ioctl.c58
1 files changed, 18 insertions, 40 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 7594bec1be10..5e94ea6e1cbe 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -461,15 +461,9 @@ static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg)
461 if (!capable(CAP_SYS_ADMIN)) 461 if (!capable(CAP_SYS_ADMIN))
462 return -EPERM; 462 return -EPERM;
463 463
464 vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS); 464 vol_args = memdup_user(arg, sizeof(*vol_args));
465 465 if (IS_ERR(vol_args))
466 if (!vol_args) 466 return PTR_ERR(vol_args);
467 return -ENOMEM;
468
469 if (copy_from_user(vol_args, arg, sizeof(*vol_args))) {
470 ret = -EFAULT;
471 goto out;
472 }
473 467
474 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; 468 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
475 namelen = strlen(vol_args->name); 469 namelen = strlen(vol_args->name);
@@ -483,11 +477,13 @@ static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg)
483 *devstr = '\0'; 477 *devstr = '\0';
484 devstr = vol_args->name; 478 devstr = vol_args->name;
485 devid = simple_strtoull(devstr, &end, 10); 479 devid = simple_strtoull(devstr, &end, 10);
486 printk(KERN_INFO "resizing devid %llu\n", devid); 480 printk(KERN_INFO "resizing devid %llu\n",
481 (unsigned long long)devid);
487 } 482 }
488 device = btrfs_find_device(root, devid, NULL, NULL); 483 device = btrfs_find_device(root, devid, NULL, NULL);
489 if (!device) { 484 if (!device) {
490 printk(KERN_INFO "resizer unable to find device %llu\n", devid); 485 printk(KERN_INFO "resizer unable to find device %llu\n",
486 (unsigned long long)devid);
491 ret = -EINVAL; 487 ret = -EINVAL;
492 goto out_unlock; 488 goto out_unlock;
493 } 489 }
@@ -545,7 +541,6 @@ static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg)
545 541
546out_unlock: 542out_unlock:
547 mutex_unlock(&root->fs_info->volume_mutex); 543 mutex_unlock(&root->fs_info->volume_mutex);
548out:
549 kfree(vol_args); 544 kfree(vol_args);
550 return ret; 545 return ret;
551} 546}
@@ -565,15 +560,9 @@ static noinline int btrfs_ioctl_snap_create(struct file *file,
565 if (root->fs_info->sb->s_flags & MS_RDONLY) 560 if (root->fs_info->sb->s_flags & MS_RDONLY)
566 return -EROFS; 561 return -EROFS;
567 562
568 vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS); 563 vol_args = memdup_user(arg, sizeof(*vol_args));
569 564 if (IS_ERR(vol_args))
570 if (!vol_args) 565 return PTR_ERR(vol_args);
571 return -ENOMEM;
572
573 if (copy_from_user(vol_args, arg, sizeof(*vol_args))) {
574 ret = -EFAULT;
575 goto out;
576 }
577 566
578 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; 567 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
579 namelen = strlen(vol_args->name); 568 namelen = strlen(vol_args->name);
@@ -675,19 +664,13 @@ static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
675 if (!capable(CAP_SYS_ADMIN)) 664 if (!capable(CAP_SYS_ADMIN))
676 return -EPERM; 665 return -EPERM;
677 666
678 vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS); 667 vol_args = memdup_user(arg, sizeof(*vol_args));
668 if (IS_ERR(vol_args))
669 return PTR_ERR(vol_args);
679 670
680 if (!vol_args)
681 return -ENOMEM;
682
683 if (copy_from_user(vol_args, arg, sizeof(*vol_args))) {
684 ret = -EFAULT;
685 goto out;
686 }
687 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; 671 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
688 ret = btrfs_init_new_device(root, vol_args->name); 672 ret = btrfs_init_new_device(root, vol_args->name);
689 673
690out:
691 kfree(vol_args); 674 kfree(vol_args);
692 return ret; 675 return ret;
693} 676}
@@ -703,19 +686,13 @@ static long btrfs_ioctl_rm_dev(struct btrfs_root *root, void __user *arg)
703 if (root->fs_info->sb->s_flags & MS_RDONLY) 686 if (root->fs_info->sb->s_flags & MS_RDONLY)
704 return -EROFS; 687 return -EROFS;
705 688
706 vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS); 689 vol_args = memdup_user(arg, sizeof(*vol_args));
690 if (IS_ERR(vol_args))
691 return PTR_ERR(vol_args);
707 692
708 if (!vol_args)
709 return -ENOMEM;
710
711 if (copy_from_user(vol_args, arg, sizeof(*vol_args))) {
712 ret = -EFAULT;
713 goto out;
714 }
715 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; 693 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
716 ret = btrfs_rm_device(root, vol_args->name); 694 ret = btrfs_rm_device(root, vol_args->name);
717 695
718out:
719 kfree(vol_args); 696 kfree(vol_args);
720 return ret; 697 return ret;
721} 698}
@@ -830,7 +807,8 @@ static long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
830 BUG_ON(!trans); 807 BUG_ON(!trans);
831 808
832 /* punch hole in destination first */ 809 /* punch hole in destination first */
833 btrfs_drop_extents(trans, root, inode, off, off+len, 0, &hint_byte); 810 btrfs_drop_extents(trans, root, inode, off, off + len,
811 off + len, 0, &hint_byte);
834 812
835 /* clone data */ 813 /* clone data */
836 key.objectid = src->i_ino; 814 key.objectid = src->i_ino;