Received: from eggs.gnu.org ([2001:4830:134:3::10]:33308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHlVd-00007h-Bf for qemu-devel@nongnu.org; Tue, 28 Jun 2016 01:24:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHlVa-0001gW-3t for qemu-devel@nongnu.org; Tue, 28 Jun 2016 01:24:29 -0400 Received: from 8.mo179.mail-out.ovh.net ([46.105.75.26]:58102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHlVZ-0001gD-Tf for qemu-devel@nongnu.org; Tue, 28 Jun 2016 01:24:26 -0400 Received: from player698.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id 9DD09FFD080 for ; Tue, 28 Jun 2016 07:24:23 +0200 (CEST) Date: Tue, 28 Jun 2016 07:24:16 +0200 From: Greg Kurz Message-ID: <20160628072416.2c1f2286@bahia.lan> In-Reply-To: <20160628025507.GS4242@voom.fritz.box> References: <146704489509.8607.12236848738501803903.stgit@bahia.lan> <20160628025507.GS4242@voom.fritz.box> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/OBQbayAOfVPr0wIuEWVUyb="; protocol="application/pgp-signature" Subject: Re: [Qemu-devel] [PATCH] spapr: fix write-past-end-of-array error in cpu core device init code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Alexander Graf , bharata@linux.vnet.ibm.com --Sig_/OBQbayAOfVPr0wIuEWVUyb= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Tue, 28 Jun 2016 12:55:07 +1000 David Gibson wrote: > On Mon, Jun 27, 2016 at 06:28:15PM +0200, Greg Kurz wrote: > > This fixes a potential QEMU crash introduced by commit 3b542549661. > >=20 > > Signed-off-by: Greg Kurz > > --- > > hw/ppc/spapr_cpu_core.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) =20 >=20 > Ugh. The existing code is wrong in the case where the failure happens > after the loop. >=20 > But this version is wrong in the case it happens during the loop - it > will fail to clean up the last object created. >=20 Hmm... unless I'm missing something, if object_property_add_child() fails to add object i, we don't want to unparent it, and we should start rollback at index i-1. Another weirdness is that I see no rollback for the object_child_foreach() loop: in case of failure, we will unparent realized objects... is it okay ? > > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c > > index 3a5da09b9902..8b802a6fcf0b 100644 > > --- a/hw/ppc/spapr_cpu_core.c > > +++ b/hw/ppc/spapr_cpu_core.c > > @@ -309,10 +309,9 @@ static void spapr_cpu_core_realize(DeviceState *de= v, Error **errp) > > } > > =20 > > err: > > - while (i >=3D 0) { > > + while (--i >=3D 0) { > > obj =3D sc->threads + i * size; > > object_unparent(obj); > > - i--; > > } > > g_free(sc->threads); > > error_propagate(errp, local_err); > > =20 >=20 --Sig_/OBQbayAOfVPr0wIuEWVUyb= Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAldyCgEACgkQAvw66wEB28LwMgCfULBRaceB5JlhmZJx692zt2ta rtgAnjb8YCFKMlyqZ8H6jq521jXf/bA2 =MCzp -----END PGP SIGNATURE----- --Sig_/OBQbayAOfVPr0wIuEWVUyb=--