From nobody Sun Apr 28 20:46:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492098288620939.6293491198962; Thu, 13 Apr 2017 08:44:48 -0700 (PDT) Received: from localhost ([::1]:49704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cygvP-0007X5-1d for importer@patchew.org; Thu, 13 Apr 2017 11:44:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cygua-00079b-Fr for qemu-devel@nongnu.org; Thu, 13 Apr 2017 11:43:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyguZ-0006Fu-Fh for qemu-devel@nongnu.org; Thu, 13 Apr 2017 11:43:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20029) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cyguU-0006D5-0f; Thu, 13 Apr 2017 11:43:50 -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 mx1.redhat.com (Postfix) with ESMTPS id 7EFC46E77E; Thu, 13 Apr 2017 15:43:48 +0000 (UTC) Received: from localhost (ovpn-204-223.brq.redhat.com [10.40.204.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC1697FBAC; Thu, 13 Apr 2017 15:43:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7EFC46E77E Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7EFC46E77E From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Apr 2017 17:43:34 +0200 Message-Id: <20170413154334.23708-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 13 Apr 2017 15:43:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10?] block: Do not unref bs->file on error in BD's open 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: Kevin Wolf , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The block layer takes care of removing the bs->file child if the block driver's bdrv_open()/bdrv_file_open() implementation fails. The block driver therefore does not need to do so, and indeed should not unless it sets bs->file to NULL afterwards -- because if this is not done, the bdrv_unref_child() in bdrv_open_inherit() will dereference the freed memory block at bs->file afterwards, which is not good. We can now decide whether to add a "bs->file =3D NULL;" after each of the offending bdrv_unref_child() invocations, or just drop them altogether. The latter is simpler, so let's do that. Cc: qemu-stable Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- It's an issue only in blkdebug, blkreplace and blkverify, and only when an error occurs in their open functions; therefore I think this is fine to delay until 2.10. However, it *is* a use-after-free newly introduced in 2.9, so that's where the question mark comes from... --- block/blkdebug.c | 4 +--- block/blkreplay.c | 3 --- block/blkverify.c | 3 --- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 67e8024e36..cc4a146e84 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -389,14 +389,12 @@ static int blkdebug_open(BlockDriverState *bs, QDict = *options, int flags, } else if (align) { error_setg(errp, "Invalid alignment"); ret =3D -EINVAL; - goto fail_unref; + goto out; } =20 ret =3D 0; goto out; =20 -fail_unref: - bdrv_unref_child(bs, bs->file); out: if (ret < 0) { g_free(s->config_file); diff --git a/block/blkreplay.c b/block/blkreplay.c index e1102119fb..6aa5fd4156 100755 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -37,9 +37,6 @@ static int blkreplay_open(BlockDriverState *bs, QDict *op= tions, int flags, =20 ret =3D 0; fail: - if (ret < 0) { - bdrv_unref_child(bs, bs->file); - } return ret; } =20 diff --git a/block/blkverify.c b/block/blkverify.c index 9a1e21c6ad..af23281669 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -142,9 +142,6 @@ static int blkverify_open(BlockDriverState *bs, QDict *= options, int flags, =20 ret =3D 0; fail: - if (ret < 0) { - bdrv_unref_child(bs, bs->file); - } qemu_opts_del(opts); return ret; } --=20 2.12.2