From nobody Fri May 3 23:21:53 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1579190197; cv=none; d=zohomail.com; s=zohoarc; b=ikXFYhgZnkv0ZeYdyAcXZ/psaq2vo3NuJZTqXp0omPvT06Y8X2pMSEyAahplf7QSuSW/9iK9d1+c5QhXLzY6dPrcSXCo87EZjQTSYd53zfCowAC3ZyT+yzau57r6jnl5YMaZxOorbwBiapKzgUP0hyk5bzPDL65QYjIJDoT2AQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579190197; h=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=35COgWpkJTESR4OmpNv4vTUrzuy5ZIAGrHVsTA1a67E=; b=ETJZpCV8H50hJxR/hqzt+PUasmVhSJOYYcXzJ+srb3VJTgw+Y1qFISpN/eL7CfSXnS7zXm9LbaXaVwnsFjrtCTSIVOcFfc8VpBxjl4VwTaxpUNo8u1pBq5Tee0GWU7Ve19JQ043DxJl9fu4FaPQsdUAJVlWeqNRYAcW/mkrqhCE= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 157919019779792.19101698665122; Thu, 16 Jan 2020 07:56:37 -0800 (PST) Received: from localhost ([::1]:44214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is7Vc-0007C1-1r for importer@patchew.org; Thu, 16 Jan 2020 10:56:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36846) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is7UH-0005no-Ac for qemu-devel@nongnu.org; Thu, 16 Jan 2020 10:55:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1is7UF-0001bF-Rr for qemu-devel@nongnu.org; Thu, 16 Jan 2020 10:55:13 -0500 Received: from relay.sw.ru ([185.231.240.75]:58016) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1is7UA-0001VK-Vf; Thu, 16 Jan 2020 10:55:07 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1is7Tz-00021t-W2; Thu, 16 Jan 2020 18:54:56 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 1/2] block/backup-top: fix failure path Date: Thu, 16 Jan 2020 18:54:51 +0300 Message-Id: <20200116155452.30972-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200116155452.30972-1-vsementsov@virtuozzo.com> References: <20200116155452.30972-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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: kwolf@redhat.com, qemu-stable@nongnu.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We can't access top after call bdrv_backup_top_drop, as it is already freed at this time. Also, no needs to unref target child by hand, it will be unrefed on bdrv_close() automatically. So, just do bdrv_backup_top_drop if append succeed and one bdrv_unref otherwise. Note, that in !appended case bdrv_unref(top) moved into drained section on source. It doesn't really matter, but just for code simplicity. Fixes: 7df7868b96404 Cc: qemu-stable@nongnu.org # v4.2.0 Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/backup-top.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/block/backup-top.c b/block/backup-top.c index 818d3f26b4..19f18d541b 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -190,6 +190,7 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverSta= te *source, BlockDriverState *top =3D bdrv_new_open_driver(&bdrv_backup_top_filter, filter_node_name, BDRV_O_RDWR, errp); + bool appended =3D false; =20 if (!top) { return NULL; @@ -212,8 +213,9 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverSta= te *source, bdrv_append(top, source, &local_err); if (local_err) { error_prepend(&local_err, "Cannot append backup-top filter: "); - goto append_failed; + goto fail; } + appended =3D true; =20 /* * bdrv_append() finished successfully, now we can require permissions @@ -224,14 +226,14 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverS= tate *source, if (local_err) { error_prepend(&local_err, "Cannot set permissions for backup-top filter: "); - goto failed_after_append; + goto fail; } =20 state->bcs =3D block_copy_state_new(top->backing, state->target, cluster_size, write_flags, &local_er= r); if (local_err) { error_prepend(&local_err, "Cannot create block-copy-state: "); - goto failed_after_append; + goto fail; } *bcs =3D state->bcs; =20 @@ -239,14 +241,15 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverS= tate *source, =20 return top; =20 -failed_after_append: - state->active =3D false; - bdrv_backup_top_drop(top); +fail: + if (appended) { + state->active =3D false; + bdrv_backup_top_drop(top); + } else { + bdrv_unref(top); + } =20 -append_failed: bdrv_drained_end(source); - bdrv_unref_child(top, state->target); - bdrv_unref(top); error_propagate(errp, local_err); =20 return NULL; --=20 2.21.0 From nobody Fri May 3 23:21:53 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1579190318; cv=none; d=zohomail.com; s=zohoarc; b=cru8EDerFFdtIWi0jnrzjzoQnW/ht8PuJ6xa7OXMYVAh6pjaPnkak9M2XEPQQGpcWR1EoEQn/JNNwZaTzRz4Cf8TYdJjC1qXFwDrpw6JWL1mCmQSGITGmX/FsX7Dj71FvUhuFMS6ahogL4FN0lfwgZ3jTePDZ/peJGGzcGmgo7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579190318; 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=MGq3S9C0rXiKzBZYqtEBMx1Vw5Z9Ykfa357npt5/QDg=; b=UkWZx3d637Mmu3KMTYw9a1yUNw6iX0IpWIhvcgJpAvXSY14sS4QHBMKlCk5bkiXrkCecjVWQVknSeprEQhLKAfOl5KAnY3rfNFdqjoSzEkh/HZs+Db3sPjhXZimAXKw0dC5Dl/EGbJqzz5DC/m4IDfKBuJZpZoAGQI7Mjeybrk8= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1579190318178346.4980561444022; Thu, 16 Jan 2020 07:58:38 -0800 (PST) Received: from localhost ([::1]:44242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is7XY-0000wX-Pw for importer@patchew.org; Thu, 16 Jan 2020 10:58:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36847) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1is7UH-0005nq-Aw for qemu-devel@nongnu.org; Thu, 16 Jan 2020 10:55:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1is7UF-0001bJ-Rs for qemu-devel@nongnu.org; Thu, 16 Jan 2020 10:55:13 -0500 Received: from relay.sw.ru ([185.231.240.75]:58024) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1is7UB-0001VM-3q; Thu, 16 Jan 2020 10:55:07 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1is7U0-00021t-47; Thu, 16 Jan 2020 18:54:56 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 2/2] iotests: add test for backup-top failure on permission activation Date: Thu, 16 Jan 2020 18:54:52 +0300 Message-Id: <20200116155452.30972-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200116155452.30972-1-vsementsov@virtuozzo.com> References: <20200116155452.30972-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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: kwolf@redhat.com, qemu-stable@nongnu.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This test checks that bug is really fixed by previous commit. Cc: qemu-stable@nongnu.org # v4.2.0 Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/283 | 75 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/283.out | 8 ++++ tests/qemu-iotests/group | 1 + 3 files changed, 84 insertions(+) create mode 100644 tests/qemu-iotests/283 create mode 100644 tests/qemu-iotests/283.out diff --git a/tests/qemu-iotests/283 b/tests/qemu-iotests/283 new file mode 100644 index 0000000000..f0f216d109 --- /dev/null +++ b/tests/qemu-iotests/283 @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# +# Test for backup-top filter permission activation failure +# +# Copyright (c) 2019 Virtuozzo International GmbH. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import iotests + +# The test is unrelated to formats, restrict it to qcow2 to avoid extra ru= ns +iotests.verify_image_format(supported_fmts=3D['qcow2']) + +size =3D 1024 * 1024 + +""" +On activation, backup-top is going to unshare write permission on its +source child. It will be impossible for the following configuration: + + =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=90 target =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=90 + =E2=94=82 target =E2=94=82 =E2=97=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 backup_top =E2=94=82 + =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=98 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=98 + =E2=94=82 + =E2=94=82 backing + =E2=96=BC + =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=90 + =E2=94=82 source =E2=94=82 + =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=98 + =E2=94=82 + =E2=94=82 file + =E2=96=BC + =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=90 write perm =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=90 + =E2=94=82 base =E2=94=82 =E2=97=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80 =E2=94=82 other =E2=94=82 + =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=98 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=98 + +Write unsharing will be propagated to the "source->base"link and will +conflict with other node write permission. + +(Note, that we can't just consider source to be direct child of other, +as in this case this link will be broken, when backup_top is appended) +""" + +vm =3D iotests.VM() +vm.launch() + +vm.qmp_log('blockdev-add', **{'node-name': 'target', 'driver': 'null-co'}) + +vm.qmp_log('blockdev-add', **{ + 'node-name': 'source', + 'driver': 'blkdebug', + 'image': {'node-name': 'base', 'driver': 'null-co', 'size': size} +}) + +vm.qmp_log('blockdev-add', **{ + 'node-name': 'other', + 'driver': 'blkdebug', + 'image': 'base', + 'take-child-perms': ['write'] +}) + +vm.qmp_log('blockdev-backup', sync=3D'full', device=3D'source', target=3D'= target') + +vm.shutdown() diff --git a/tests/qemu-iotests/283.out b/tests/qemu-iotests/283.out new file mode 100644 index 0000000000..daaf5828c1 --- /dev/null +++ b/tests/qemu-iotests/283.out @@ -0,0 +1,8 @@ +{"execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name"= : "target"}} +{"return": {}} +{"execute": "blockdev-add", "arguments": {"driver": "blkdebug", "image": {= "driver": "null-co", "node-name": "base", "size": 1048576}, "node-name": "s= ource"}} +{"return": {}} +{"execute": "blockdev-add", "arguments": {"driver": "blkdebug", "image": "= base", "node-name": "other", "take-child-perms": ["write"]}} +{"return": {}} +{"execute": "blockdev-backup", "arguments": {"device": "source", "sync": "= full", "target": "target"}} +{"error": {"class": "GenericError", "desc": "Cannot set permissions for ba= ckup-top filter: Conflicts with use by other as 'image', which uses 'write'= on base"}} diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index cb2b789e44..d827e8c821 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -288,3 +288,4 @@ 277 rw quick 279 rw backing quick 280 rw migration quick +283 auto quick --=20 2.21.0