blkdev_common_ioctl() takes both arg (unsigned long) and argp (void __user *). The latter should always be used when a pointer is expected by a command, as it has already been converted as appropriate (compat_ptr() when called from compat_blkdev_ioctl()).
A number of helpers still take arg and cast it to a void __user *, which is generally invalid. Amend them to take argp instead, saving a cast along the way.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- block/blk-zoned.c | 6 ++---- block/ioctl.c | 22 +++++++++++----------- include/linux/blkdev.h | 8 ++++---- 3 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 89194cf697c6..9844a02edd52 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -330,9 +330,8 @@ static int blkdev_copy_zone_to_user(struct blk_zone *zone, unsigned int idx, * Called from blkdev_ioctl. */ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, user_uintptr_t arg) + unsigned int cmd, void __user *argp) { - void __user *argp = (void __user *)arg; struct zone_report_args args; struct blk_zone_report rep; int ret; @@ -383,9 +382,8 @@ static int blkdev_truncate_zone_range(struct block_device *bdev, fmode_t mode, * Called from blkdev_ioctl. */ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, user_uintptr_t arg) + unsigned int cmd, void __user *argp) { - void __user *argp = (void __user *)arg; struct blk_zone_range zrange; enum req_op op; int ret; diff --git a/block/ioctl.c b/block/ioctl.c index 5534aeb470c7..9fa13a9dddaf 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -83,7 +83,7 @@ static int compat_blkpg_ioctl(struct block_device *bdev, #endif
static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, - user_uintptr_t arg) + void __user *argp) { uint64_t range[2]; uint64_t start, len; @@ -96,7 +96,7 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, if (!bdev_max_discard_sectors(bdev)) return -EOPNOTSUPP;
- if (copy_from_user(range, (void __user *)arg, sizeof(range))) + if (copy_from_user(range, argp, sizeof(range))) return -EFAULT;
start = range[0]; @@ -152,7 +152,7 @@ static int blk_ioctl_secure_erase(struct block_device *bdev, fmode_t mode,
static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, - user_uintptr_t arg) + void __user *argp) { uint64_t range[2]; uint64_t start, end, len; @@ -162,7 +162,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, if (!(mode & FMODE_WRITE)) return -EBADF;
- if (copy_from_user(range, (void __user *)arg, sizeof(range))) + if (copy_from_user(range, argp, sizeof(range))) return -EFAULT;
start = range[0]; @@ -355,14 +355,14 @@ static int blkdev_flushbuf(struct block_device *bdev, fmode_t mode, }
static int blkdev_roset(struct block_device *bdev, fmode_t mode, - unsigned cmd, user_uintptr_t arg) + unsigned cmd, int __user *argp) { int ret, n;
if (!capable(CAP_SYS_ADMIN)) return -EACCES;
- if (get_user(n, (int __user *)arg)) + if (get_user(n, argp)) return -EFAULT; if (bdev->bd_disk->fops->set_read_only) { ret = bdev->bd_disk->fops->set_read_only(bdev, n); @@ -477,22 +477,22 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, case BLKFLSBUF: return blkdev_flushbuf(bdev, mode, cmd, arg); case BLKROSET: - return blkdev_roset(bdev, mode, cmd, arg); + return blkdev_roset(bdev, mode, cmd, argp); case BLKDISCARD: - return blk_ioctl_discard(bdev, mode, arg); + return blk_ioctl_discard(bdev, mode, argp); case BLKSECDISCARD: return blk_ioctl_secure_erase(bdev, mode, argp); case BLKZEROOUT: - return blk_ioctl_zeroout(bdev, mode, arg); + return blk_ioctl_zeroout(bdev, mode, argp); case BLKGETDISKSEQ: return put_u64(argp, bdev->bd_disk->diskseq); case BLKREPORTZONE: - return blkdev_report_zones_ioctl(bdev, mode, cmd, arg); + return blkdev_report_zones_ioctl(bdev, mode, cmd, argp); case BLKRESETZONE: case BLKOPENZONE: case BLKCLOSEZONE: case BLKFINISHZONE: - return blkdev_zone_mgmt_ioctl(bdev, mode, cmd, arg); + return blkdev_zone_mgmt_ioctl(bdev, mode, cmd, argp); case BLKGETZONESZ: return put_uint(argp, bdev_zone_sectors(bdev)); case BLKGETNRZONES: diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 7630916c1471..128fdac6e9a8 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -330,9 +330,9 @@ int blk_revalidate_disk_zones(struct gendisk *disk, void (*update_driver_data)(struct gendisk *disk));
extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg); + unsigned int cmd, void __user *argp); extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg); + unsigned int cmd, void __user *argp);
#else /* CONFIG_BLK_DEV_ZONED */
@@ -343,14 +343,14 @@ static inline unsigned int bdev_nr_zones(struct block_device *bdev)
static inline int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, - unsigned long arg) + void __user *argp) { return -ENOTTY; }
static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, - unsigned long arg) + void __user *argp) { return -ENOTTY; }