Message ID | 20170614114851.17146-1-linus.walleij@linaro.org |
---|---|
State | New |
Headers | show |
Hi Linus, On 2017/6/14 19:48, Linus Walleij wrote: > mmc_blk_ioctl() calls either mmc_blk_ioctl_cmd() or > mmc_blk_ioctl_multi_cmd() and each of these make the same > check. Factor it into the first call and save one chunk > of duplicate code. > Probably you still cannot save the check like what this patch does. Refer to commit, 83c742c344c08 ("mmc: block: fix ABI regression of mmc_blk_ioctl") > Signed-off-by: Linus Walleij <linus.walleij@linaro.org> > --- > drivers/mmc/core/block.c | 24 ++++++++---------------- > 1 file changed, 8 insertions(+), 16 deletions(-) > > diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c > index 1ce6012ce3c1..c80bee4a9cff 100644 > --- a/drivers/mmc/core/block.c > +++ b/drivers/mmc/core/block.c > @@ -566,14 +566,6 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, > int err = 0, ioc_err = 0; > struct request *req; > > - /* > - * 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); > @@ -626,14 +618,6 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, > __u64 num_of_cmds; > struct request *req; > > - /* > - * 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; > @@ -700,6 +684,14 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, > 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, > -- Best Regards Shawn Lin -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Jun 14, 2017 at 2:22 PM, Shawn Lin <shawn.lin@rock-chips.com> wrote: > Hi Linus, > > On 2017/6/14 19:48, Linus Walleij wrote: >> >> mmc_blk_ioctl() calls either mmc_blk_ioctl_cmd() or >> mmc_blk_ioctl_multi_cmd() and each of these make the same >> check. Factor it into the first call and save one chunk >> of duplicate code. >> > > Probably you still cannot save the check like what this patch > does. Refer to commit, > > 83c742c344c08 ("mmc: block: fix ABI regression of mmc_blk_ioctl") AHa I see what's happening. I guess I have to make a small helper function to check it and inline that instead. Yours, Linus Walleij -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 1ce6012ce3c1..c80bee4a9cff 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -566,14 +566,6 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, int err = 0, ioc_err = 0; struct request *req; - /* - * 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); @@ -626,14 +618,6 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, __u64 num_of_cmds; struct request *req; - /* - * 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; @@ -700,6 +684,14 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, 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,
mmc_blk_ioctl() calls either mmc_blk_ioctl_cmd() or mmc_blk_ioctl_multi_cmd() and each of these make the same check. Factor it into the first call and save one chunk of duplicate code. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> --- drivers/mmc/core/block.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) -- 2.9.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html