linux/block
Paolo Bonzini 0bfc96cb77 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>
2012-01-14 15:07:24 -08:00
..
partitions separate partition format handling from generic code 2012-01-03 22:54:06 -05:00
blk-cgroup.c cgroup: don't use subsys->can_attach_task() or ->attach_task() 2011-12-12 18:12:21 -08:00
blk-cgroup.h block: fix a typo in the blk-cgroup.h file 2011-10-24 16:08:38 +02:00
blk-core.c block: don't kick empty queue in blk_drain_queue() 2011-12-15 20:03:04 +01:00
blk-exec.c [SCSI] fix crash in scsi_dispatch_cmd() 2011-07-21 14:21:18 -07:00
blk-flush.c blk-flush: move the queue kick into 2011-10-24 16:24:31 +02:00
blk-integrity.c block: add export.h to files using EXPORT_SYMBOL/THIS_MODULE macros 2011-10-31 19:31:12 -04:00
blk-ioc.c Merge branch 'for-linus' into for-3.1/core 2011-07-01 16:17:13 +02:00
blk-iopoll.c tree-wide: fix assorted typos all over the place 2009-12-04 15:39:55 +01:00
blk-lib.c block: fix patch import error in max_discard_sectors check 2011-07-23 20:34:59 +02:00
blk-map.c block: re-use existing 'reading' variable instead of checking direction again 2011-12-21 15:27:24 +01:00
blk-merge.c block: attempt to merge with existing requests on plug flush 2011-03-21 10:14:27 +01:00
blk-settings.c block: Fix discard topology stacking and reporting 2011-05-18 10:37:35 +02:00
blk-softirq.c block: Don't check QUEUE_FLAG_SAME_COMP in __blk_complete_request 2011-09-14 09:31:01 +02:00
blk-sysfs.c block: fix request_queue lifetime handling by making blk_queue_cleanup() properly shutdown 2011-10-19 14:42:16 +02:00
blk-tag.c block: fix blk_queue_end_tag() 2011-12-29 09:16:28 +01:00
blk-throttle.c blk-throttle: use queue_is_locked() instead of lockdep_is_held() 2011-10-25 15:51:48 +02:00
blk-timeout.c fault-injection: add ability to export fault_attr in arbitrary directory 2011-08-03 14:25:20 -10:00
blk.h block: fix request_queue lifetime handling by making blk_queue_cleanup() properly shutdown 2011-10-19 14:42:16 +02:00
bsg-lib.c block: Change module.h -> export.h in bsg-lib.c 2011-10-31 19:31:13 -04:00
bsg.c switch device_get_devnode() and ->devnode() to umode_t * 2012-01-03 22:54:55 -05:00
cfq-iosched.c block, cfq: fix empty queue crash caused by request merge 2011-12-16 14:04:23 +01:00
cfq.h blk-cgroup: Add unaccounted time to timeslice_used. 2011-03-12 16:54:00 +01:00
compat_ioctl.c compat_ioctl: fix warning caused by qemu 2011-07-01 22:32:26 +02:00
deadline-iosched.c iosched: prevent aliased requests from starving other I/O 2011-06-02 21:19:05 +02:00
elevator.c block: fix request_queue lifetime handling by making blk_queue_cleanup() properly shutdown 2011-10-19 14:42:16 +02:00
genhd.c Merge branches 'vfsmount-guts', 'umode_t' and 'partitions' into Z 2012-01-06 23:15:54 -05:00
ioctl.c Merge branch 'for-linus2' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2012-01-08 12:19:57 -08:00
Kconfig move fs/partitions to block/ 2012-01-03 22:54:06 -05:00
Kconfig.iosched blk-cgroup: config options re-arrangement 2010-04-26 19:27:56 +02:00
Makefile separate partition format handling from generic code 2012-01-03 22:54:06 -05:00
noop-iosched.c block: remove per-queue plugging 2011-03-10 08:52:07 +01:00
partition-generic.c separate partition format handling from generic code 2012-01-03 22:54:06 -05:00
scsi_ioctl.c block: fail SCSI passthrough ioctls on partition devices 2012-01-14 15:07:24 -08:00