aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-01-12 10:01:28 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-14 18:07:24 -0500
commit0bfc96cb77224736dfa35c3c555d37b3646ef35e (patch)
treeaf5135c929ee8e1bdb38c306b2634dbc547d5189 /drivers/scsi
parent577ebb374c78314ac4617242f509e2f5e7156649 (diff)
block: fail SCSI passthrough ioctls on partition devices
Linux allows executing the SG_IO ioctl on a partition or LVM volume, and will pass the command to the underlying block device. This is well-known, but it is also a large security problem when (via Unix permissions, ACLs, SELinux or a combination thereof) a program or user needs to be granted access only to part of the disk. This patch lets partitions forward a small set of harmless ioctls; others are logged with printk so that we can see which ioctls are actually sent. In my tests only CDROM_GET_CAPABILITY actually occurred. Of course it was being sent to a (partition on a) hard disk, so it would have failed with ENOTTY and the patch isn't changing anything in practice. Still, I'm treating it specially to avoid spamming the logs. In principle, this restriction should include programs running with CAP_SYS_RAWIO. If for example I let a program access /dev/sda2 and /dev/sdb, it still should not be able to read/write outside the boundaries of /dev/sda2 independent of the capabilities. However, for now programs with CAP_SYS_RAWIO will still be allowed to send the ioctls. Their actions will still be logged. This patch does not affect the non-libata IDE driver. That driver however already tests for bd != bd->bd_contains before issuing some ioctl; it could be restricted further to forbid these ioctls even for programs running with CAP_SYS_ADMIN/CAP_SYS_RAWIO. 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> [ Make it also print the command name when warning - Linus ] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/sd.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index b4d57bb04c72..c691fb50e6cb 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1075,6 +1075,10 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
1075 SCSI_LOG_IOCTL(1, sd_printk(KERN_INFO, sdkp, "sd_ioctl: disk=%s, " 1075 SCSI_LOG_IOCTL(1, sd_printk(KERN_INFO, sdkp, "sd_ioctl: disk=%s, "
1076 "cmd=0x%x\n", disk->disk_name, cmd)); 1076 "cmd=0x%x\n", disk->disk_name, cmd));
1077 1077
1078 error = scsi_verify_blk_ioctl(bdev, cmd);
1079 if (error < 0)
1080 return error;
1081
1078 /* 1082 /*
1079 * If we are in the middle of error recovery, don't let anyone 1083 * If we are in the middle of error recovery, don't let anyone
1080 * else try and use this device. Also, if error recovery fails, it 1084 * else try and use this device. Also, if error recovery fails, it
@@ -1267,6 +1271,11 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
1267 unsigned int cmd, unsigned long arg) 1271 unsigned int cmd, unsigned long arg)
1268{ 1272{
1269 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device; 1273 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device;
1274 int ret;
1275
1276 ret = scsi_verify_blk_ioctl(bdev, cmd);
1277 if (ret < 0)
1278 return ret;
1270 1279
1271 /* 1280 /*
1272 * If we are in the middle of error recovery, don't let anyone 1281 * If we are in the middle of error recovery, don't let anyone
@@ -1278,8 +1287,6 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
1278 return -ENODEV; 1287 return -ENODEV;
1279 1288
1280 if (sdev->host->hostt->compat_ioctl) { 1289 if (sdev->host->hostt->compat_ioctl) {
1281 int ret;
1282
1283 ret = sdev->host->hostt->compat_ioctl(sdev, cmd, (void __user *)arg); 1290 ret = sdev->host->hostt->compat_ioctl(sdev, cmd, (void __user *)arg);
1284 1291
1285 return ret; 1292 return ret;