FROMLIST: mmc: block: fix ABI regression of mmc_blk_ioctl
[firefly-linux-kernel-4.4.55.git] / drivers / mmc / card / block.c
index 90e9738a129a7e757c5d6c9e9a01bc987b75db80..f2ce13ab7ae6e523ab9b3740a203e27786a6e2a9 100644 (file)
@@ -593,6 +593,14 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
        struct mmc_card *card;
        int err = 0, ioc_err = 0;
 
+       /*
+        * The caller must have CAP_SYS_RAWIO, and must be calling this on the
+        * whole block device, not on a partition.  This prevents overspray
+        * between sibling partitions.
+        */
+       if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains))
+               return -EPERM;
+
        idata = mmc_blk_ioctl_copy_from_user(ic_ptr);
        if (IS_ERR(idata))
                return PTR_ERR(idata);
@@ -635,6 +643,14 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
        int i, err = 0, ioc_err = 0;
        __u64 num_of_cmds;
 
+       /*
+        * The caller must have CAP_SYS_RAWIO, and must be calling this on the
+        * whole block device, not on a partition.  This prevents overspray
+        * between sibling partitions.
+        */
+       if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains))
+               return -EPERM;
+
        if (copy_from_user(&num_of_cmds, &user->num_of_cmds,
                           sizeof(num_of_cmds)))
                return -EFAULT;
@@ -690,14 +706,6 @@ cmd_err:
 static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode,
        unsigned int cmd, unsigned long arg)
 {
-       /*
-        * The caller must have CAP_SYS_RAWIO, and must be calling this on the
-        * whole block device, not on a partition.  This prevents overspray
-        * between sibling partitions.
-        */
-       if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains))
-               return -EPERM;
-
        switch (cmd) {
        case MMC_IOC_CMD:
                return mmc_blk_ioctl_cmd(bdev,