From patchwork Sat Mar 25 16:18:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 95991 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp532221qgd; Sat, 25 Mar 2017 09:19:39 -0700 (PDT) X-Received: by 10.84.254.5 with SMTP id b5mr4374216plm.76.1490458779776; Sat, 25 Mar 2017 09:19:39 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3si6723034pli.62.2017.03.25.09.19.39; Sat, 25 Mar 2017 09:19:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751360AbdCYQTj (ORCPT + 5 others); Sat, 25 Mar 2017 12:19:39 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:33836 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751309AbdCYQTj (ORCPT ); Sat, 25 Mar 2017 12:19:39 -0400 Received: by mail-pg0-f44.google.com with SMTP id 21so9215198pgg.1 for ; Sat, 25 Mar 2017 09:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TNT7O0QLCWISB3yrKCiC49+Bd7risWClwuoDPwXayaQ=; b=ZkqYyRAQPdKqJXv7zKeuLB3f6nSDIaozaTafca9OBtNAwMgOOnI75qiBq9eaxrsHuM uMA67vU7k8yAurUgrh0yUSRZ3sbtYu54kEG/I4GU0LMPlaVcGv2N7vq6rdFUuAjniyNc uIqlFVNYQriGpLEXqXHwt3ke0muHb51M25Vc0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TNT7O0QLCWISB3yrKCiC49+Bd7risWClwuoDPwXayaQ=; b=Q7lQd7avj3/kGZRh+3AKsQG6KRobJycHZ9lTXIlxLyO4vAXjYLY3QWjMwkM/Ndxm2/ zzEaW6gG/q/kqpqqHW0PlPpyP86yVnfMCTULrh7WgpUugB9Frjfv+B5yazB04+kNybJg Is4/tS9ZwrAsKvcoo+ELOgKO4mnTwDHRB8LaxBrzuRyGMCq7DlZu6LyO49FLQUsjaEGy 8CjeDIP66Az3r7OWqyPI2YxF8HZsuCf2vUcXRTnz4pA0vJ6nnEmuHYk1Qk8biCJHjiKK /wZEvyhwFJWt0FPexvQWUlxjz/GQLh5DpXdrETTrxPiFjJ8j9WxOB0K7m41VBGU9tLjs /zig== X-Gm-Message-State: AFeK/H0OS2yjXFvJeokCMV4c7G1HcpqM7CGuQfvBECCGzcN4/9yUwCP/2E8ZBMhN1uHpbi7d X-Received: by 10.99.238.69 with SMTP id n5mr15558972pgk.38.1490458777603; Sat, 25 Mar 2017 09:19:37 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id q194sm11469541pfq.43.2017.03.25.09.19.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Mar 2017 09:19:36 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Mauricio Faria de Oliveira , Brahadambal Srinivasan , Jens Axboe , Sasha Levin , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 14/19] block: allow WRITE_SAME commands with the SG_IO ioctl Date: Sat, 25 Mar 2017 21:48:14 +0530 Message-Id: <1490458699-24484-15-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490458699-24484-1-git-send-email-sumit.semwal@linaro.org> References: <1490458699-24484-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mauricio Faria de Oliveira [ Upstream commit 25cdb64510644f3e854d502d69c73f21c6df88a9 ] 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 "" [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 Signed-off-by: Brahadambal Srinivasan Reported-by: Manjunatha H R Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- block/scsi_ioctl.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.7.4 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 0774799..c6fee74 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -182,6 +182,9 @@ static void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter) __set_bit(WRITE_16, filter->write_ok); __set_bit(WRITE_LONG, filter->write_ok); __set_bit(WRITE_LONG_2, filter->write_ok); + __set_bit(WRITE_SAME, filter->write_ok); + __set_bit(WRITE_SAME_16, filter->write_ok); + __set_bit(WRITE_SAME_32, filter->write_ok); __set_bit(ERASE, filter->write_ok); __set_bit(GPCMD_MODE_SELECT_10, filter->write_ok); __set_bit(MODE_SELECT, filter->write_ok);