android_kernel_samsung_msm8976/block
Mauricio Faria de Oliveira e6e480992e block: allow WRITE_SAME commands with the SG_IO ioctl
commit 25cdb64510644f3e854d502d69c73f21c6df88a9 upstream.

The WRITE_SAME commands are not present in the blk_default_cmd_filter
write_ok list, and thus are failed with -EPERM when the SG_IO ioctl()
is executed without CAP_SYS_RAWIO capability (e.g., unprivileged users).
[ sg_io() -> blk_fill_sghdr_rq() > blk_verify_command() -> -EPERM ]

The problem can be reproduced with the sg_write_same command

  # sg_write_same --num 1 --xferlen 512 /dev/sda
  #

  # capsh --drop=cap_sys_rawio -- -c \
    'sg_write_same --num 1 --xferlen 512 /dev/sda'
    Write same: pass through os error: Operation not permitted
  #

For comparison, the WRITE_VERIFY command does not observe this problem,
since it is in that list:

  # capsh --drop=cap_sys_rawio -- -c \
    'sg_write_verify --num 1 --ilen 512 --lba 0 /dev/sda'
  #

So, this patch adds the WRITE_SAME commands to the list, in order
for the SG_IO ioctl to finish successfully:

  # capsh --drop=cap_sys_rawio -- -c \
    'sg_write_same --num 1 --xferlen 512 /dev/sda'
  #

That case happens to be exercised by QEMU KVM guests with 'scsi-block' devices
(qemu "-device scsi-block" [1], libvirt "<disk type='block' device='lun'>" [2]),
which employs the SG_IO ioctl() and runs as an unprivileged user (libvirt-qemu).

In that scenario, when a filesystem (e.g., ext4) performs its zero-out calls,
which are translated to write-same calls in the guest kernel, and then into
SG_IO ioctls to the host kernel, SCSI I/O errors may be observed in the guest:

  [...] sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
  [...] sd 0:0:0:0: [sda] tag#0 Sense Key : Aborted Command [current]
  [...] sd 0:0:0:0: [sda] tag#0 Add. Sense: I/O process terminated
  [...] sd 0:0:0:0: [sda] tag#0 CDB: Write Same(10) 41 00 01 04 e0 78 00 00 08 00
  [...] blk_update_request: I/O error, dev sda, sector 17096824

Links:
[1] http://git.qemu.org/?p=qemu.git;a=commit;h=336a6915bc7089fb20fea4ba99972ad9a97c5f52
[2] https://libvirt.org/formatdomain.html#elementsDisks (see 'disk' -> 'device')

Signed-off-by: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
Signed-off-by: Brahadambal Srinivasan <latha@linux.vnet.ibm.com>
Reported-by: Manjunatha H R <manjuhr1@in.ibm.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
2019-07-27 21:43:28 +02:00
..
partitions This is the 3.10.99 stable release 2017-04-18 17:17:46 +02:00
Kconfig
Kconfig.iosched block: cgroups, kconfig, build bits for BFQ-v7r8-3.10.8+ 2017-04-18 04:37:19 +02:00
Makefile block: cgroups, kconfig, build bits for BFQ-v7r8-3.10.8+ 2017-04-18 04:37:19 +02:00
bfq-cgroup.c block: introduce the BFQ-v7r8 I/O sched for 3.10.8+ 2017-04-18 04:37:19 +02:00
bfq-ioc.c block: introduce the BFQ-v7r8 I/O sched for 3.10.8+ 2017-04-18 04:37:19 +02:00
bfq-iosched.c block, bfq: add Early Queue Merge (EQM) to BFQ-v7r8 for 3.10.8+ 2017-04-18 04:37:20 +02:00
bfq-sched.c block, bfq: add Early Queue Merge (EQM) to BFQ-v7r8 for 3.10.8+ 2017-04-18 04:37:20 +02:00
bfq.h block, bfq: add Early Queue Merge (EQM) to BFQ-v7r8 for 3.10.8+ 2017-04-18 04:37:20 +02:00
blk-cgroup.c blkcg: fix gendisk reference leak in blkg_conf_prep() 2015-08-10 12:20:30 -07:00
blk-cgroup.h
blk-core.c BACKPORT: block: add blk_rq_set_block_pc() 2017-04-22 23:03:01 +02:00
blk-exec.c
blk-flush.c
blk-integrity.c
blk-ioc.c
blk-iopoll.c
blk-lib.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
blk-map.c
blk-merge.c dm: dm-req-crypt: Split read requests to reduce decryption latency 2015-01-14 12:20:01 -08:00
blk-settings.c This is the 3.10.67 stable release 2015-04-24 18:04:40 -07:00
blk-softirq.c
blk-sysfs.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
blk-tag.c
blk-throttle.c blk-throttle: check stats_cpu before reading it from sysfs 2015-03-06 14:40:54 -08:00
blk-timeout.c
blk.h Revert "block: do not requeue completed request" 2015-02-02 17:07:57 +02:00
bsg-lib.c
bsg.c BACKPORT: block: add blk_rq_set_block_pc() 2017-04-22 23:03:01 +02:00
cfq-iosched.c cfq: fix starvation of asynchronous writes 2019-07-27 21:42:46 +02:00
compat_ioctl.c
deadline-iosched.c
elevator.c
genhd.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
ioctl.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
noop-iosched.c
partition-generic.c This is the 3.10.67 stable release 2015-04-24 18:04:40 -07:00
row-iosched.c
scsi_ioctl.c block: allow WRITE_SAME commands with the SG_IO ioctl 2019-07-27 21:43:28 +02:00
test-iosched.c block: test-iosched: expose sector_range variable to user 2015-01-13 16:17:04 +02:00