From nobody Sat Nov 15 14:11:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595332340; cv=none; d=zohomail.com; s=zohoarc; b=V35XImq/IGeM7nGIXTgh5RnrBBpvUgJSRobdq9+bAOP35pyFIYDltX+QBvQbQk9uhf0IJxpnc0TcsI1yfVKN1NenCywrbXotI8M6vYrGuFRu4yFfm7TyiyM++U6YaQ2CfAjsjH2TFxJyUwtG/62PUQT9ptxP5MSHKIQdpayT8no= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595332340; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LO2o6iouqBBqtiAy+J1nbi0a6TP3rCZ4xkeB4F6aIr0=; b=mm29Hy31MC7z/0IYyPAiyKHykhI9ZAaFD19tf454Ocv9fYjoizDlkzV77RTZ9oVYdOweIFZ88JkQdmHAlXbTluQLxcyl38C+PvF38b4TPj29IVKVLi9/ILBTnwkUzXoQTtoZp65+5LJeRk4XoQUSlmyUs7L5SQdOFLZ3usXN6Xw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159533234013653.72722449519733; Tue, 21 Jul 2020 04:52:20 -0700 (PDT) Received: from localhost ([::1]:42452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxqok-0000nV-Uq for importer@patchew.org; Tue, 21 Jul 2020 07:52:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxqm7-0005Un-3j for qemu-devel@nongnu.org; Tue, 21 Jul 2020 07:49:35 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:20125 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jxqm4-00064V-5V for qemu-devel@nongnu.org; Tue, 21 Jul 2020 07:49:34 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-366-2Co-EZb5OdiCTmbyd-PKxQ-1; Tue, 21 Jul 2020 07:49:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E0D4100AA44; Tue, 21 Jul 2020 11:49:28 +0000 (UTC) Received: from localhost (ovpn-113-68.ams2.redhat.com [10.36.113.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B71C1872E6; Tue, 21 Jul 2020 11:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595332171; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LO2o6iouqBBqtiAy+J1nbi0a6TP3rCZ4xkeB4F6aIr0=; b=cHIObmrI//RpRqDvtaLcusfCrj27e29ghc87lGhlA/+96MPzYdodu4M7xk5hs6zmQQ8L2Q 8rYIFFupcDtOzp/CAAKjnFqpKcRsH0SXTI1jyola3FcIhpgW6EMpH1QzlwvtiucCp/Dqr3 T44ybBI7m932Y7Xn25/wGYLddjnQP/w= X-MC-Unique: 2Co-EZb5OdiCTmbyd-PKxQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 1/3] block/crypto: disallow write sharing by default Date: Tue, 21 Jul 2020 13:49:18 +0200 Message-Id: <20200721114920.1174149-2-mreitz@redhat.com> In-Reply-To: <20200721114920.1174149-1-mreitz@redhat.com> References: <20200721114920.1174149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/21 01:26:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky My commit 'block/crypto: implement the encryption key management' accidently allowed raw luks images to be shared between different qemu processes without share-rw=3Don explicit override. Fix that. Fixes: bbfdae91fb ("block/crypto: implement the encryption key management") Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D1857490 Signed-off-by: Maxim Levitsky Message-Id: <20200719122059.59843-2-mlevitsk@redhat.com> Signed-off-by: Max Reitz --- block/crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/crypto.c b/block/crypto.c index 8725c1bc02..0807557763 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -881,7 +881,7 @@ block_crypto_child_perms(BlockDriverState *bs, BdrvChil= d *c, * For backward compatibility, manually share the write * and resize permission */ - *nshared |=3D (BLK_PERM_WRITE | BLK_PERM_RESIZE); + *nshared |=3D shared & (BLK_PERM_WRITE | BLK_PERM_RESIZE); /* * Since we are not fully a format driver, don't always request * the read/resize permission but only when explicitly --=20 2.26.2 From nobody Sat Nov 15 14:11:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595332278; cv=none; d=zohomail.com; s=zohoarc; b=PKEU7ubnoIwjAdW4XLeUKk5hXy+umLqS77ES3Su94EShFdufsy2wfpmFIqOG1sPBauFHgkhT7d9EiO2Qpe7mdQUZrvGVS6q/1LhtWLRAAnxXQayJ64fR+qK83wwOlyUuIWkhXRoeTBgRJ4ajvlvLvMFMEqQhh3ACOxT1gpetOj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595332278; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7bu1ObqOj3OHCCldy+IL3MDU6Q+WzjsktlpzMOf6W3o=; b=S3sq7RvLYWx0KliULXuYmMwSdCF8DB0Kjjg+8wVqZVDP7niROfXJ1wlzW37iqyGvaADBiC+LWqV2b9ex+V0jGnV+iqW1d5u10zTbgphme0P+R8aku+dizvkAgjlYK8TOsofvI7fSsnUUKzepD9BuxbuXthQqsvx+LKHCNuXj0as= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595332278028668.9470389359839; Tue, 21 Jul 2020 04:51:18 -0700 (PDT) Received: from localhost ([::1]:38634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxqnk-0007fE-Rs for importer@patchew.org; Tue, 21 Jul 2020 07:51:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxqm7-0005Wx-VH for qemu-devel@nongnu.org; Tue, 21 Jul 2020 07:49:35 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:24154 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jxqm5-00064s-VH for qemu-devel@nongnu.org; Tue, 21 Jul 2020 07:49:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-kYXaggCXM0WYLij2lSA0fg-1; Tue, 21 Jul 2020 07:49:31 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F39058; Tue, 21 Jul 2020 11:49:30 +0000 (UTC) Received: from localhost (ovpn-113-68.ams2.redhat.com [10.36.113.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E6BB81002393; Tue, 21 Jul 2020 11:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595332173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7bu1ObqOj3OHCCldy+IL3MDU6Q+WzjsktlpzMOf6W3o=; b=H6K6FZw5fqkL88QmPDZbco9PCtHGLJb8iohBW/sqmdKmTUR4m55ZmWu8X0WF3A4eHgOb4L z74B7CVR9VsdtlufgcNvuh31RUaH3bEYwefDQc3wNF4KVp2BkDBNQL7f++GFBMSRIUaW5h 02oH+h4BmMm3YkTYWxk2/gEWvH85DGI= X-MC-Unique: kYXaggCXM0WYLij2lSA0fg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 2/3] qemu-iotests: add testcase for bz #1857490 Date: Tue, 21 Jul 2020 13:49:19 +0200 Message-Id: <20200721114920.1174149-3-mreitz@redhat.com> In-Reply-To: <20200721114920.1174149-1-mreitz@redhat.com> References: <20200721114920.1174149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/21 01:26:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Test that we can't write-share raw luks images by default, but we still can with share-rw=3Don Signed-off-by: Maxim Levitsky Message-Id: <20200719122059.59843-3-mlevitsk@redhat.com> Signed-off-by: Max Reitz --- tests/qemu-iotests/296 | 44 +++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/296.out | 12 +++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/296 b/tests/qemu-iotests/296 index ec69ec8974..fb7dec88aa 100755 --- a/tests/qemu-iotests/296 +++ b/tests/qemu-iotests/296 @@ -133,6 +133,21 @@ class EncryptionSetupTestCase(iotests.QMPTestCase): ) self.assert_qmp(result, 'return', {}) =20 + + ######################################################################= ##### + # add virtio-blk consumer for a block device + def addImageUser(self, vm, id, disk_id, share_rw=3DFalse): + result =3D vm.qmp('device_add', ** + { + 'driver': 'virtio-blk', + 'id': id, + 'drive': disk_id, + 'share-rw' : share_rw + } + ) + + iotests.log(result) + # close the encrypted block device def closeImageQmp(self, vm, id): result =3D vm.qmp('blockdev-del', **{ 'node-name': id }) @@ -159,7 +174,7 @@ class EncryptionSetupTestCase(iotests.QMPTestCase): vm.run_job('job0') =20 # test that when the image opened by two qemu processes, - # neither of them can update the image + # neither of them can update the encryption keys def test1(self): self.createImg(test_img, self.secrets[0]); =20 @@ -193,6 +208,9 @@ class EncryptionSetupTestCase(iotests.QMPTestCase): os.remove(test_img) =20 =20 + # test that when the image opened by two qemu processes, + # even if first VM opens it read-only, the second can't update encrypt= ion + # keys def test2(self): self.createImg(test_img, self.secrets[0]); =20 @@ -226,6 +244,30 @@ class EncryptionSetupTestCase(iotests.QMPTestCase): self.closeImageQmp(self.vm1, "testdev") os.remove(test_img) =20 + # test that two VMs can't open the same luks image by default + # and attach it to a guest device + def test3(self): + self.createImg(test_img, self.secrets[0]); + + self.openImageQmp(self.vm1, "testdev", test_img, self.secrets[0]) + self.addImageUser(self.vm1, "testctrl", "testdev") + + self.openImageQmp(self.vm2, "testdev", test_img, self.secrets[0]) + self.addImageUser(self.vm2, "testctrl", "testdev") + + + # test that two VMs can attach the same luks image to a guest device, + # if both use share-rw=3Don + def test4(self): + self.createImg(test_img, self.secrets[0]); + + self.openImageQmp(self.vm1, "testdev", test_img, self.secrets[0]) + self.addImageUser(self.vm1, "testctrl", "testdev", share_rw=3DTrue) + + self.openImageQmp(self.vm2, "testdev", test_img, self.secrets[0]) + self.addImageUser(self.vm2, "testctrl", "testdev", share_rw=3DTrue) + + =20 if __name__ =3D=3D '__main__': # support only raw luks since luks encrypted qcow2 is a proper diff --git a/tests/qemu-iotests/296.out b/tests/qemu-iotests/296.out index afb6d2d09d..cb2859a15c 100644 --- a/tests/qemu-iotests/296.out +++ b/tests/qemu-iotests/296.out @@ -26,8 +26,16 @@ Job failed: Failed to get shared "consistent read" lock {"return": {}} {"execute": "job-dismiss", "arguments": {"id": "job0"}} {"return": {}} -.. +Formatting 'TEST_DIR/test.img', fmt=3Dluks size=3D1048576 key-secret=3Dkey= sec0 iter-time=3D10 + +{"return": {}} +{"error": {"class": "GenericError", "desc": "Failed to get \"write\" lock"= }} +Formatting 'TEST_DIR/test.img', fmt=3Dluks size=3D1048576 key-secret=3Dkey= sec0 iter-time=3D10 + +{"return": {}} +{"return": {}} +.... ---------------------------------------------------------------------- -Ran 2 tests +Ran 4 tests =20 OK --=20 2.26.2 From nobody Sat Nov 15 14:11:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595332270; cv=none; d=zohomail.com; s=zohoarc; b=Frruf+C/ttvp/IL12/ORoZRd9OZcGMiI6DUJAdmXOdYSHGfhTzJBNTalBDQcuN+31MettcP1QhK82uoVC3pafw5Lv1/YaBhmxyahjF/8EVDNJMFS57kgRop4hPvW+27mge+yCrlRqCKcHQCxXoca4p6ZVaX/ojWdIQMPgkNN+s8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595332270; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rBsbvbrM0hTRp1RDTWa9O+FYk+piA4Xx60yUG/qUQw4=; b=QGAtFTNoaBnJPRZNv6X1ORwGguOGQv8HPEZEBcsLbeOGqAcSBARFKwIO4pXa6mcyPKZMyv0uiLoLCm45QjirUzZFTpe6LvdOso5zgXLn6d7CtL6k1vhedc67XQAbRitWj3jQ/GzjoSxG6qDVhkK56y1yd46M0rxfbYp9GmjHhd4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15953322708540.20685691578739807; Tue, 21 Jul 2020 04:51:10 -0700 (PDT) Received: from localhost ([::1]:38360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxqnd-0007YO-IN for importer@patchew.org; Tue, 21 Jul 2020 07:51:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxqmC-0005jq-Ql for qemu-devel@nongnu.org; Tue, 21 Jul 2020 07:49:40 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:24682 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jxqmA-00065X-Jk for qemu-devel@nongnu.org; Tue, 21 Jul 2020 07:49:40 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-406-LU3e3FMyMpa0FuCnx0EbgQ-1; Tue, 21 Jul 2020 07:49:33 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A7FB100D0DD; Tue, 21 Jul 2020 11:49:32 +0000 (UTC) Received: from localhost (ovpn-113-68.ams2.redhat.com [10.36.113.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0CA1A709E1; Tue, 21 Jul 2020 11:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595332177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rBsbvbrM0hTRp1RDTWa9O+FYk+piA4Xx60yUG/qUQw4=; b=PYwaia1f4R3TzMN8w1c2vVgUR8j18a+ELDAO0zIPNemTUiMm3pFQZcXyddH4u82dyxeDMH 9x2M2e59y85+iEbgnedkDjnrMhN+37+Gx7M1L0gSAzYdHcIXb8BRosqzDI17HHsclWnZ96 0k068Za/bLB00g1P2ixUjobQqVQ1TPw= X-MC-Unique: LU3e3FMyMpa0FuCnx0EbgQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 3/3] block: fix bdrv_aio_cancel() for ENOMEDIUM requests Date: Tue, 21 Jul 2020 13:49:20 +0200 Message-Id: <20200721114920.1174149-4-mreitz@redhat.com> In-Reply-To: <20200721114920.1174149-1-mreitz@redhat.com> References: <20200721114920.1174149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/21 01:26:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Stefan Hajnoczi bdrv_aio_cancel() calls aio_poll() on the AioContext for the given I/O request until it has completed. ENOMEDIUM requests are special because there is no BlockDriverState when the drive has no medium! Define a .get_aio_context() function for BlkAioEmAIOCB requests so that bdrv_aio_cancel() can find the AioContext where the completion BH is pending. Without this function bdrv_aio_cancel() aborts on ENOMEDIUM requests! libFuzzer triggered the following assertion: cat << EOF | qemu-system-i386 -M pc-q35-5.0 \ -nographic -monitor none -serial none \ -qtest stdio -trace ide\* outl 0xcf8 0x8000fa24 outl 0xcfc 0xe106c000 outl 0xcf8 0x8000fa04 outw 0xcfc 0x7 outl 0xcf8 0x8000fb20 write 0x0 0x3 0x2780e7 write 0xe106c22c 0xd 0x1130c218021130c218021130c2 write 0xe106c218 0x15 0x110010110010110010110010110010110010110010 EOF ide_exec_cmd IDE exec cmd: bus 0x56170a77a2b8; state 0x56170a77a340; cmd = 0xe7 ide_reset IDEstate 0x56170a77a340 Aborted (core dumped) (gdb) bt #1 0x00007ffff4f93895 in abort () at /lib64/libc.so.6 #2 0x0000555555dc6c00 in bdrv_aio_cancel (acb=3D0x555556765550) at block= /io.c:2745 #3 0x0000555555dac202 in blk_aio_cancel (acb=3D0x555556765550) at block/= block-backend.c:1546 #4 0x0000555555b1bd74 in ide_reset (s=3D0x555557213340) at hw/ide/core.c= :1318 #5 0x0000555555b1e3a1 in ide_bus_reset (bus=3D0x5555572132b8) at hw/ide/= core.c:2422 #6 0x0000555555b2aa27 in ahci_reset_port (s=3D0x55555720eb50, port=3D2) = at hw/ide/ahci.c:650 #7 0x0000555555b29fd7 in ahci_port_write (s=3D0x55555720eb50, port=3D2, = offset=3D44, val=3D16) at hw/ide/ahci.c:360 #8 0x0000555555b2a564 in ahci_mem_write (opaque=3D0x55555720eb50, addr= =3D556, val=3D16, size=3D1) at hw/ide/ahci.c:513 #9 0x000055555598415b in memory_region_write_accessor (mr=3D0x55555720eb= 80, addr=3D556, value=3D0x7fffffffb838, size=3D1, shift=3D0, mask=3D255, at= trs=3D...) at softmmu/memory.c:483 Looking at bdrv_aio_cancel: 2728 /* async I/Os */ 2729 2730 void bdrv_aio_cancel(BlockAIOCB *acb) 2731 { 2732 qemu_aio_ref(acb); 2733 bdrv_aio_cancel_async(acb); 2734 while (acb->refcnt > 1) { 2735 if (acb->aiocb_info->get_aio_context) { 2736 aio_poll(acb->aiocb_info->get_aio_context(acb), true); 2737 } else if (acb->bs) { 2738 /* qemu_aio_ref and qemu_aio_unref are not thread-safe, so 2739 * assert that we're not using an I/O thread. Thread-safe 2740 * code should use bdrv_aio_cancel_async exclusively. 2741 */ 2742 assert(bdrv_get_aio_context(acb->bs) =3D=3D qemu_get_aio_c= ontext()); 2743 aio_poll(bdrv_get_aio_context(acb->bs), true); 2744 } else { 2745 abort(); <=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D 2746 } 2747 } 2748 qemu_aio_unref(acb); 2749 } Fixes: 02c50efe08736116048d5fc355043080f4d5859c ("block: Add bdrv_aio_cance= l_async") Reported-by: Alexander Bulekov Buglink: https://bugs.launchpad.net/qemu/+bug/1878255 Originally-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefan Hajnoczi Message-Id: <20200720100141.129739-1-stefanha@redhat.com> Signed-off-by: Max Reitz --- block/block-backend.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 0bf0188133..3a13cb5f0b 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1394,8 +1394,16 @@ typedef struct BlkAioEmAIOCB { bool has_returned; } BlkAioEmAIOCB; =20 +static AioContext *blk_aio_em_aiocb_get_aio_context(BlockAIOCB *acb_) +{ + BlkAioEmAIOCB *acb =3D container_of(acb_, BlkAioEmAIOCB, common); + + return blk_get_aio_context(acb->rwco.blk); +} + static const AIOCBInfo blk_aio_em_aiocb_info =3D { .aiocb_size =3D sizeof(BlkAioEmAIOCB), + .get_aio_context =3D blk_aio_em_aiocb_get_aio_context, }; =20 static void blk_aio_complete(BlkAioEmAIOCB *acb) --=20 2.26.2