linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] block: add queue-private command filter, editable via sysfs
@ 2012-09-12 11:25 Paolo Bonzini
  2012-09-12 11:25 ` [PATCH 1/3] block: add back queue-private command filter Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Paolo Bonzini @ 2012-09-12 11:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tejun Heo, James Bottomley, Jens Axboe, Ric Wheeler, linux-scsi

[sorry for the resend, I used a wrong mailing list address]

The set of use cases for SG_IO is quite variable that no single filter can
accomodate all of them.  The current filter is tailored very much to
CD burning, and includes many MMC-specific commands that may have
other meanings in different standards.  Someone may want to remove
those commands; at the same time, people that trust their users may
want to add persistent reservations, trim/discard, or even access to
vendor-specific commands.

Filters used to be mutable via sysfs, but the implementation was
never enabled.  Add it back, and let the admin set this up per device.
The ideal is that we would be much more restrictive by default and
give root the ability to override this both globally and per-device.
But this piece of the policy should probably be implemented in userspace
for better backwards compatibility.

In the meanwhile, this patch series provides the sysfs knob.  It is a
tweaked revert of commit 018e044 (block: get rid of queue-private command
filter, 2009-06-26).

Paolo Bonzini (3):
  block: add back queue-private command filter
  scsi: create an all-zero filter for scanners
  block: add back command filter modification via sysfs

 Documentation/block/queue-sysfs.txt |   16 +++++
 block/Kconfig                       |   10 +++
 block/blk-sysfs.c                   |   43 +++++++++++++
 block/bsg.c                         |    2 +-
 block/scsi_ioctl.c                  |  117 +++++++++++++++++++++++++++++++----
 drivers/scsi/scsi_scan.c            |    6 ++-
 drivers/scsi/sg.c                   |    7 +-
 include/linux/blkdev.h              |   31 +++++++++-
 8 files changed, 213 insertions(+), 19 deletions(-)


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH 0/3] SG_IO command filtering via sysfs
@ 2018-11-10 16:35 Paolo Bonzini
  2018-11-10 16:35 ` [PATCH 3/3] block: add back command filter modification " Paolo Bonzini
  0 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2018-11-10 16:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-scsi, Hannes Reinecke, Martin K. Petersen, James Bottomley

Currently, SG_IO ioctls are implemented so that non-CAP_SYS_RAWIO users
can send commands from a predetermined whitelist.  The whitelist is very
simple-minded though, and basically corresponds to MMC commands---the idea
being that it would be nice for local users to read/copy/burn CDs.

This was probably sensible when the whitelist was first added (in the pre-git
era), but quite a few things have changed since then:

- there is a lot more focus on not running things as root unnecessarily;
it is generally much more common to have non-root processes accessing disks
and we would like that to happen more, not less.

- there is also a lot more focus on not giving capabilities unnecessarily.
Using CAP_SYS_RAWIO, which gives full access to all commands, allows
you to send a WRITE SCSI command to a file opened for reading, which is
a nice recipe for data corruption.  A more fine-grained whitelist allows
you to give the desired access to the application.

- we've discovered that some commands conflict between the various
SCSI standards.  UNMAP (a write command) in SBC has the same number as
the obscure MMC command READ SUBCHANNEL.  As such it's allowed if a
block device is opened for reading!

This series, which was last sent in 2012 before I lost interest in the
endless discussions that followed, adds the possibility to make the filter
mutable via sysfs, so that it can be set up per device.  This of course can
go both ways; interested applications can set a wider filter, but one can
also imagine setting much more restrictive filters by default (possibly
allowing little more than INQUIRY, TEST UNIT READY, READ CAPACITY and the
like).

Back then there was opposition to giving unfettered access to "dangerous"
or "too easily destructive" commands such as WRITE SAME or PERSISTENT
RESERVE OUT to unprivileged users.  Even then, I think this objection
is now moot thanks to the following things that have happened in 2012:

- WRITE SAME commands, which were considered too destructive, have
been added to the filter since commit 25cdb6451064 ("block: allow
WRITE_SAME commands with the SG_IO ioctl", 2016-12-15, Linux 4.10).
They are basically the only non-MMC commands included in the filter,
by the way.

- persistent reservations are also allowed now via PR ioctls (commit
924d55b06347, "sd: implement the Persistent Reservation API", 2015-10-21,
Linux 4.4).  These require CAP_SYS_ADMIN, which is the same capability
that is needed to *grant* access to PR commands via the SG_IO filter.

So, here is the 2018 version of these patches.  Please review! :)

Paolo

Paolo Bonzini (3):
  block: add back queue-private command filter
  scsi: create an all-one filter for scanners
  block: add back command filter modification via sysfs

 Documentation/block/queue-sysfs.txt |  19 +++++
 block/Kconfig                       |  10 +++
 block/blk-sysfs.c                   |  43 ++++++++++++
 block/bsg-lib.c                     |   4 +-
 block/bsg.c                         |   8 +--
 block/scsi_ioctl.c                  | 136 +++++++++++++++++++++++++++++++++---
 drivers/scsi/scsi_scan.c            |  13 ++++
 drivers/scsi/sg.c                   |   6 +-
 include/linux/blkdev.h              |  18 ++++-
 include/linux/bsg.h                 |   4 +-
 10 files changed, 238 insertions(+), 23 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH 0/3] block: add queue-private command filter, editable via sysfs
@ 2012-09-12 11:23 Paolo Bonzini
  2012-09-12 11:23 ` [PATCH 3/3] block: add back command filter modification " Paolo Bonzini
  0 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2012-09-12 11:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tejun Heo, James Bottomley, Jens Axboe, Ric Wheeler, linux-iscsi

The set of use cases for SG_IO is quite variable that no single filter can
accomodate all of them.  The current filter is tailored very much to
CD burning, and includes many MMC-specific commands that may have
other meanings in different standards.  Someone may want to remove
those commands; at the same time, people that trust their users may
want to add persistent reservations, trim/discard, or even access to
vendor-specific commands.

Filters used to be mutable via sysfs, but the implementation was
never enabled.  Add it back, and let the admin set this up per device.
The ideal is that we would be much more restrictive by default and
give root the ability to override this both globally and per-device.
But this piece of the policy should probably be implemented in userspace
for better backwards compatibility.

In the meanwhile, this patch series provides the sysfs knob.  It is a
tweaked revert of commit 018e044 (block: get rid of queue-private command
filter, 2009-06-26).

Paolo Bonzini (3):
  block: add back queue-private command filter
  scsi: create an all-zero filter for scanners
  block: add back command filter modification via sysfs

 Documentation/block/queue-sysfs.txt |   16 +++++
 block/Kconfig                       |   10 +++
 block/blk-sysfs.c                   |   43 +++++++++++++
 block/bsg.c                         |    2 +-
 block/scsi_ioctl.c                  |  117 +++++++++++++++++++++++++++++++----
 drivers/scsi/scsi_scan.c            |    6 ++-
 drivers/scsi/sg.c                   |    7 +-
 include/linux/blkdev.h              |   31 +++++++++-
 8 files changed, 213 insertions(+), 19 deletions(-)


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-11-16 14:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-12 11:25 [PATCH 0/3] block: add queue-private command filter, editable via sysfs Paolo Bonzini
2012-09-12 11:25 ` [PATCH 1/3] block: add back queue-private command filter Paolo Bonzini
2012-09-12 11:25 ` [PATCH 2/3] scsi: create an all-zero filter for scanners Paolo Bonzini
2012-09-12 11:25 ` [PATCH 3/3] block: add back command filter modification via sysfs Paolo Bonzini
2012-09-12 12:38   ` Alan Cox
2012-09-12 12:41   ` Alan Cox
2012-09-12 12:56     ` Paolo Bonzini
  -- strict thread matches above, loose matches on Subject: below --
2018-11-10 16:35 [PATCH 0/3] SG_IO command filtering " Paolo Bonzini
2018-11-10 16:35 ` [PATCH 3/3] block: add back command filter modification " Paolo Bonzini
2018-11-16  5:46   ` Bart Van Assche
2018-11-16  7:00     ` Paolo Bonzini
2018-11-16 14:42       ` Bart Van Assche
2012-09-12 11:23 [PATCH 0/3] block: add queue-private command filter, editable " Paolo Bonzini
2012-09-12 11:23 ` [PATCH 3/3] block: add back command filter modification " Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).