From patchwork Thu Jan 18 21:00:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 125039 Delivered-To: patch@linaro.org Received: by 10.46.64.27 with SMTP id n27csp294773lja; Thu, 18 Jan 2018 13:01:27 -0800 (PST) X-Google-Smtp-Source: ACJfBosh7UfeaLsZJvdcYjviRxslZVv+2rvWFbxzzHV+mM7KQ77BVf8tG9rlAxkE9mmuOHkYewVw X-Received: by 10.101.81.7 with SMTP id f7mr38340285pgq.435.1516309287053; Thu, 18 Jan 2018 13:01:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516309287; cv=none; d=google.com; s=arc-20160816; b=b8zQJw84HMWia7327zSFE3D3QHZK7U9XkQQZiwUkY0H8/6JYJ5Qitl/ePmwQ+U+QTB tzUrQ0s+gTtvt6eF6RDCCeHRMtrNTa6Dtkn/r972RLFWRcvS7jR35UyYet1QQIFAfykD oh/VBBDQdfm9c2DugqLVQ/+0ufdjjln4nWtI98h+lL9Dv42QIVjoWl7Du6Sn1b+jeuLU wDOSlQO4pb20NfBxIC3og1xMBIFNyxsDjCjJulxwtWeRJoKhgVce0Kz1IP2MqSf2CMIm QQV0480lcbuZ03FD1m0duap/T0nSmKVC52TtmgTjwlD4Dfc3lK8+iue+mOF624NRKe0R Ng1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=QS2+SzdrJ+FUs8KoseVo51FCyOgUcoUUHIBkP8+QMJQ=; b=kjPhI+D0Ok1AJYEBtpw3Rw7a7Nq75JCLVVtcyxAm9NMt2JjPWKDwtABhUo1CqsaJuU DgdEpsj98NNmlMkxK8EERNsEfJqtseZ9j4qD/re8Ing3lRnr0V0oFsxteLxyhXS/EVMQ i0aHSUErXZNKkxagbQ0ZysTmWhc1SBry+lBKJKEbMdamZpj8/4eStXCMeb9jdL/PohIE Z0vZhn/pfpJUMoR2Ivoq1OrtxNNM/jMwSP9JvyrT94OG2OI09JNBg7eODP7YMk3SxZ6D Pi2Udg710pIqOK4tQG9BjHaq1GxSEwWOMpj2iwrA6Glkyl/0JLavlSZUM+10TfgVNpbv 5Aew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=mpr9YSDa; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c16si4933770pgu.706.2018.01.18.13.01.26; Thu, 18 Jan 2018 13:01:27 -0800 (PST) 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=@microsoft.com header.s=selector1 header.b=mpr9YSDa; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754812AbeARVBZ (ORCPT + 10 others); Thu, 18 Jan 2018 16:01:25 -0500 Received: from mail-by2nam01on0104.outbound.protection.outlook.com ([104.47.34.104]:11884 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754882AbeARVBV (ORCPT ); Thu, 18 Jan 2018 16:01:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=QS2+SzdrJ+FUs8KoseVo51FCyOgUcoUUHIBkP8+QMJQ=; b=mpr9YSDayNmrWAgf142hskaQ9+89GJZ0GXAf71EWbqcpPW9ZZNSHj6U4FQjDUUQEWO7apbQ8uZyAqMULFo6k+qNzqDXzMu5QvZY0TBdSQWZi/+RwhRph90LPYFQTDYYkF9AYHsPh7V20I6eDWLM75TelVEQArTv3xNA0hfh0sFg= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0805.namprd21.prod.outlook.com (10.167.105.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.428.7; Thu, 18 Jan 2018 21:01:15 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0428.008; Thu, 18 Jan 2018 21:01:15 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Sumit Semwal , Mauricio Faria de Oliveira , Brahadambal Srinivasan , Jens Axboe , Sasha Levin Subject: [added to the 4.1 stable tree] block: allow WRITE_SAME commands with the SG_IO ioctl Thread-Topic: [added to the 4.1 stable tree] block: allow WRITE_SAME commands with the SG_IO ioctl Thread-Index: AQHTkJ9Q9vdHJiWKS0Wt7i8T1a+leQ== Date: Thu, 18 Jan 2018 21:00:05 +0000 Message-ID: <20180118205908.3220-80-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [167.220.98.9] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB0805; 7:RG/8VdgfMsJpZAb3Fikz78Z6YQt/JQpSFvXL4KpM/+CglDIWz8uSHGgIZqGNPCglpOmE6InW1FZyseb7DCmFKuxHQTouXYIg7ueN9aX8Kmynb+1B4k+scAjpKs3WsQaMRv3TqyNUYmbk0Xaf8iyT9/pIVrpnzkih3Q26gY4jYnFghhQLl6UFWeSXZGIJC0wmWQSPhx+dCuTEG7krLGY0VHgC38SfxXdYVbLahpohIOUCRhnzYdvGTBLcXhuZKxvQ x-ms-office365-filtering-correlation-id: 69a8cc01-3e70-4986-d997-08d55eb69d14 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020); SRVR:DM5PR2101MB0805; x-ms-traffictypediagnostic: DM5PR2101MB0805: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(190756311086443)(89211679590171)(67672495146484)(280536654915231)(104084551191319); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(61425038)(6040495)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231046)(2400067)(944501161)(3002001)(6055026)(61426038)(61427038)(6041282)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011); SRVR:DM5PR2101MB0805; BCL:0; PCL:0; RULEID:(100000803126)(100110400120); SRVR:DM5PR2101MB0805; x-forefront-prvs: 05568D1FF7 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(39380400002)(366004)(376002)(346002)(396003)(189003)(199004)(2906002)(2900100001)(6512007)(86362001)(305945005)(97736004)(68736007)(10090500001)(2501003)(6666003)(7736002)(105586002)(5250100002)(2950100002)(5660300001)(6116002)(36756003)(6486002)(26005)(86612001)(54906003)(4326008)(3280700002)(3846002)(6346003)(6436002)(3660700001)(10290500003)(478600001)(107886003)(76176011)(66066001)(1076002)(81156014)(99286004)(81166006)(106356001)(6306002)(53936002)(102836004)(22452003)(110136005)(59450400001)(14454004)(316002)(72206003)(25786009)(966005)(6506007)(8676002)(8936002)(22906009); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB0805; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: PK7mkm829ijmx7AEeOpa2mQ2t37U3Hs3XUh/yFe4NQOKG4bmHUeZzbLwcw6Vk9JMmP/wwQ5R0Y8vpVZeE3n3HA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69a8cc01-3e70-4986-d997-08d55eb69d14 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2018 21:00:05.5409 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0805 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Sumit Semwal This patch has been added to the stable tree. If you have any objections, please let us know. -- 2.11.0 =============== [ 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 --- block/scsi_ioctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 55b6f15dac90..3356fd91bc61 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);