Skip to content

Commit 0478fe6

Browse files
bonziniaxboe
authored andcommitted
block: silently forbid sending any ioctl to a partition
After the first few months, the message has not led to many bug reports. It's been almost five years now, and in practice the main source of it seems to be MTIOCGET that someone is using to detect tape devices. While we could whitelist it just like CDROM_GET_CAPABILITY, this patch just removes the message altogether. The patch also removes the "safe but not very useful" ioctl whitelist, as suggested by Christoph. I doubt anything is using most of those ioctls _in general_, let alone on a partition. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7c3fb70 commit 0478fe6

File tree

1 file changed

+0
-29
lines changed

1 file changed

+0
-29
lines changed

block/scsi_ioctl.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -693,38 +693,9 @@ int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
693693
if (bd && bd == bd->bd_contains)
694694
return 0;
695695

696-
/* Actually none of these is particularly useful on a partition,
697-
* but they are safe.
698-
*/
699-
switch (cmd) {
700-
case SCSI_IOCTL_GET_IDLUN:
701-
case SCSI_IOCTL_GET_BUS_NUMBER:
702-
case SCSI_IOCTL_GET_PCI:
703-
case SCSI_IOCTL_PROBE_HOST:
704-
case SG_GET_VERSION_NUM:
705-
case SG_SET_TIMEOUT:
706-
case SG_GET_TIMEOUT:
707-
case SG_GET_RESERVED_SIZE:
708-
case SG_SET_RESERVED_SIZE:
709-
case SG_EMULATED_HOST:
710-
return 0;
711-
case CDROM_GET_CAPABILITY:
712-
/* Keep this until we remove the printk below. udev sends it
713-
* and we do not want to spam dmesg about it. CD-ROMs do
714-
* not have partitions, so we get here only for disks.
715-
*/
716-
return -ENOIOCTLCMD;
717-
default:
718-
break;
719-
}
720-
721696
if (capable(CAP_SYS_RAWIO))
722697
return 0;
723698

724-
/* In particular, rule out all resets and host-specific ioctls. */
725-
printk_ratelimited(KERN_WARNING
726-
"%s: sending ioctl %x to a partition!\n", current->comm, cmd);
727-
728699
return -ENOIOCTLCMD;
729700
}
730701
EXPORT_SYMBOL(scsi_verify_blk_ioctl);

0 commit comments

Comments
 (0)