Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: add and use scsi_blk_cmd_ioctl

Introduce a wrapper around scsi_cmd_ioctl that takes a block device.

The function will then be enhanced to detect partition block devices
and, in that case, subject the ioctls to whitelisting.

Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Cc: James Bottomley <JBottomley@parallels.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Paolo Bonzini and committed by
Linus Torvalds
577ebb37 81d48f0a

+18 -12
+7
block/scsi_ioctl.c
··· 690 690 } 691 691 EXPORT_SYMBOL(scsi_cmd_ioctl); 692 692 693 + int scsi_cmd_blk_ioctl(struct block_device *bd, fmode_t mode, 694 + unsigned int cmd, void __user *arg) 695 + { 696 + return scsi_cmd_ioctl(bd->bd_disk->queue, bd->bd_disk, mode, cmd, arg); 697 + } 698 + EXPORT_SYMBOL(scsi_cmd_blk_ioctl); 699 + 693 700 static int __init blk_scsi_ioctl_init(void) 694 701 { 695 702 blk_set_cmd_filter_defaults(&blk_default_cmd_filter);
+3 -3
drivers/block/cciss.c
··· 1735 1735 case CCISS_BIG_PASSTHRU: 1736 1736 return cciss_bigpassthru(h, argp); 1737 1737 1738 - /* scsi_cmd_ioctl handles these, below, though some are not */ 1738 + /* scsi_cmd_blk_ioctl handles these, below, though some are not */ 1739 1739 /* very meaningful for cciss. SG_IO is the main one people want. */ 1740 1740 1741 1741 case SG_GET_VERSION_NUM: ··· 1746 1746 case SG_EMULATED_HOST: 1747 1747 case SG_IO: 1748 1748 case SCSI_IOCTL_SEND_COMMAND: 1749 - return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp); 1749 + return scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); 1750 1750 1751 - /* scsi_cmd_ioctl would normally handle these, below, but */ 1751 + /* scsi_cmd_blk_ioctl would normally handle these, below, but */ 1752 1752 /* they aren't a good fit for cciss, as CD-ROMs are */ 1753 1753 /* not supported, and we don't have any bus/target/lun */ 1754 1754 /* which we present to the kernel. */
+1 -2
drivers/block/ub.c
··· 1744 1744 static int ub_bd_ioctl(struct block_device *bdev, fmode_t mode, 1745 1745 unsigned int cmd, unsigned long arg) 1746 1746 { 1747 - struct gendisk *disk = bdev->bd_disk; 1748 1747 void __user *usermem = (void __user *) arg; 1749 1748 int ret; 1750 1749 1751 1750 mutex_lock(&ub_mutex); 1752 - ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem); 1751 + ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, usermem); 1753 1752 mutex_unlock(&ub_mutex); 1754 1753 1755 1754 return ret;
+2 -2
drivers/block/virtio_blk.c
··· 250 250 if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_SCSI)) 251 251 return -ENOTTY; 252 252 253 - return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, 254 - (void __user *)data); 253 + return scsi_cmd_blk_ioctl(bdev, mode, cmd, 254 + (void __user *)data); 255 255 } 256 256 257 257 /* We provide getgeo only to please some old bootloader/partitioning tools */
+1 -2
drivers/cdrom/cdrom.c
··· 2746 2746 { 2747 2747 void __user *argp = (void __user *)arg; 2748 2748 int ret; 2749 - struct gendisk *disk = bdev->bd_disk; 2750 2749 2751 2750 /* 2752 2751 * Try the generic SCSI command ioctl's first. 2753 2752 */ 2754 - ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp); 2753 + ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); 2755 2754 if (ret != -ENOTTY) 2756 2755 return ret; 2757 2756
+1 -2
drivers/ide/ide-floppy_ioctl.c
··· 292 292 * and CDROM_SEND_PACKET (legacy) ioctls 293 293 */ 294 294 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) 295 - err = scsi_cmd_ioctl(bdev->bd_disk->queue, bdev->bd_disk, 296 - mode, cmd, argp); 295 + err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); 297 296 298 297 if (err == -ENOTTY) 299 298 err = generic_ide_ioctl(drive, bdev, cmd, arg);
+1 -1
drivers/scsi/sd.c
··· 1097 1097 error = scsi_ioctl(sdp, cmd, p); 1098 1098 break; 1099 1099 default: 1100 - error = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, p); 1100 + error = scsi_cmd_blk_ioctl(bdev, mode, cmd, p); 1101 1101 if (error != -ENOTTY) 1102 1102 break; 1103 1103 error = scsi_ioctl(sdp, cmd, p);
+2
include/linux/blkdev.h
··· 675 675 struct request *rq); 676 676 extern void blk_delay_queue(struct request_queue *, unsigned long); 677 677 extern void blk_recount_segments(struct request_queue *, struct bio *); 678 + extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t, 679 + unsigned int, void __user *); 678 680 extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t, 679 681 unsigned int, void __user *); 680 682 extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,