From nobody Fri Apr 26 19:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552558530507776.3165913520056; Thu, 14 Mar 2019 03:15:30 -0700 (PDT) Received: from localhost ([127.0.0.1]:33484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4NOS-0006Xw-Fl for importer@patchew.org; Thu, 14 Mar 2019 06:15:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4NNZ-00064f-OO for qemu-devel@nongnu.org; Thu, 14 Mar 2019 06:14:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4NNY-0005HE-78 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 06:14:25 -0400 Received: from relay.sw.ru ([185.231.240.75]:35122) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h4NNX-0005FB-Mp; Thu, 14 Mar 2019 06:14:24 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1h4NNQ-0002uc-Pf; Thu, 14 Mar 2019 13:14:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 14 Mar 2019 13:14:15 +0300 Message-Id: <20190314101415.15427-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH] block/io: fix bdrv_co_do_copy_on_readv error handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, den@openvz.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's not safe to treat bdrv_is_allocated error as unallocated: if we mistake we may rewrite guest data. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index 2ba603c7bc..dccad64d46 100644 --- a/block/io.c +++ b/block/io.c @@ -1193,11 +1193,13 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bd= rvChild *child, ret =3D bdrv_is_allocated(bs, cluster_offset, MIN(cluster_bytes, max_transfer), &pnum); if (ret < 0) { - /* Safe to treat errors in querying allocation as if - * unallocated; we'll probably fail again soon on the - * read, but at least that will set a decent errno. + /* + * We must fail here, and can't treat error as allocated or + * unallocated: if we mistake, it will lead to not done copy-o= n-read + * in first case and to rewriting guest data that is already i= n top + * layer in the second case. */ - pnum =3D MIN(cluster_bytes, max_transfer); + goto err; } =20 /* Stop at EOF if the image ends in the middle of the cluster */ @@ -1208,7 +1210,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bdrv= Child *child, =20 assert(skip_bytes < pnum); =20 - if (ret <=3D 0) { + if (ret =3D=3D 0) { /* Must copy-on-read; use the bounce buffer */ pnum =3D MIN(pnum, MAX_BOUNCE_BUFFER); qemu_iovec_init_buf(&local_qiov, bounce_buffer, pnum); --=20 2.18.0