From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUUtg-0008Am-QC for qemu-devel@nongnu.org; Tue, 02 Aug 2016 04:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUUtb-0007qn-3z for qemu-devel@nongnu.org; Tue, 02 Aug 2016 04:17:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUUta-0007qP-U9 for qemu-devel@nongnu.org; Tue, 02 Aug 2016 04:17:51 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6BCBC3B70D for ; Tue, 2 Aug 2016 08:17:50 +0000 (UTC) Date: Tue, 2 Aug 2016 16:17:47 +0800 From: Fam Zheng Message-ID: <20160802081747.GC2095@ad.usersys.redhat.com> References: <1470109301-12966-1-git-send-email-famz@redhat.com> <20160802101453.418ab9c4@nial.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160802101453.418ab9c4@nial.brq.redhat.com> Subject: Re: [Qemu-devel] [PATCH] qdev: Fix use after free in qdev_init_nofail error path List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: John Snow , qemu-devel@nongnu.org, ehabkost@redhat.com On Tue, 08/02 10:14, Igor Mammedov wrote: > On Tue, 2 Aug 2016 00:00:27 -0400 > John Snow wrote: > > > On 08/01/2016 11:41 PM, Fam Zheng wrote: > > > Since 69382d8b (qdev: Fix object reference leak in case device.realize() > > > fails), object_property_set_bool could release the object. The error > > > path wants the type name, so hold an reference before realizing it. > > > > > > Cc: Igor Mammedov > > > Signed-off-by: Fam Zheng > > > --- > > > hw/core/qdev.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > > > index ee4a083..5783442 100644 > > > --- a/hw/core/qdev.c > > > +++ b/hw/core/qdev.c > > > @@ -354,12 +354,14 @@ void qdev_init_nofail(DeviceState *dev) > > > > > > assert(!dev->realized); > > > > > > + object_ref(OBJECT(dev)); > > > object_property_set_bool(OBJECT(dev), true, "realized", &err); > > > if (err) { > > > error_reportf_err(err, "Initialization of device %s failed: ", > > > object_get_typename(OBJECT(dev))); > > > exit(1); > > > } > > > + object_unref(OBJECT(dev)); > > > } > > > > > > void qdev_machine_creation_done(void) > > > > > > > Thanks :) > > > > (For the list: this fixes qcow2 iotest 051. This is for-2.7.) > I don't see any error at 'make check' time, > could you provide reproducer CLI? It crashes for me with something as simple as: $ qemu-system-x86_64 -drive if=ide Fam