From nobody Sun May 5 07:04:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516503156126384.3809161450748; Sat, 20 Jan 2018 18:52:36 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19CB320273; Sun, 21 Jan 2018 02:52:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1425D608F6; Sun, 21 Jan 2018 02:52:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 34A984ED37; Sun, 21 Jan 2018 02:52:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0L2qMpr007696 for ; Sat, 20 Jan 2018 21:52:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8F75E60C99; Sun, 21 Jan 2018 02:52:22 +0000 (UTC) Received: from vhost2.laine.org (ovpn-117-87.phx2.redhat.com [10.3.117.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB00560C94; Sun, 21 Jan 2018 02:52:19 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Sat, 20 Jan 2018 21:52:15 -0500 Message-Id: <20180121025215.20191-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Sylvain Petreolle Subject: [libvirt] [PATCH] vbox: fix SEGV during dumpxml of a serial port X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sun, 21 Jan 2018 02:52:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" commit 77a12987a48 changed the "virDomainChrSourceDef source" inside virDomainChrDef to "virDomainChrSourceDefPtr source", and started allocating source inside virDomainChrDefNew(), but vboxDumpSerial() was allocating a virDomainChrDef with a simple VIR_ALLOC(), so source was never initialized, leading to a SEGV any time a serial port was present. The same problem was created in vboxDumpParallel(). This patch changes vboxDumpSerial() and vboxDumpParallel() to use virDomainChrDefNew() instead of VIR_ALLOC(), and makes a cursory attempt to "recover" from OOM afterwards (much of the vbox code was written to assume success, e.g. by having functions return void. Since I have no way to test a more sweeping change to this code, I chose to just short-circuit the rest of the function if virDomainChrDefNew() fails - this is at least one step better than the previous code, which would otherwise end up trying to dereference a NULL def->serials[i] and crash libvirtd. This resolves: https://bugzilla.redhat.com/1536649 --- src/vbox/vbox_common.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 33aefabe5..c5fa5f08b 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3887,8 +3887,19 @@ vboxDumpSerial(virDomainDefPtr def, vboxDriverPtr da= ta, IMachine *machine, PRUin =20 /* Allocate memory for the serial ports which are enabled */ if ((def->nserials > 0) && (VIR_ALLOC_N(def->serials, def->nserials) >= =3D 0)) { - for (i =3D 0; i < def->nserials; i++) - ignore_value(VIR_ALLOC(def->serials[i])); + for (i =3D 0; i < def->nserials; i++) { + def->serials[i] =3D virDomainChrDefNew(NULL); + if (!def->serials[i]) { + /* there is no provision for returning an error + * (although the libvirtd logs will show an OOM error), + * but we need to at least prevent dereferencing + * def->serials[i] and later (including continuing in + * this function), as it will otherwise cause a SEGV. + */ + def->nserials =3D i; + return; + } + } } =20 /* Now get the details about the serial ports here */ @@ -3975,8 +3986,19 @@ vboxDumpParallel(virDomainDefPtr def, vboxDriverPtr = data, IMachine *machine, PRU =20 /* Allocate memory for the parallel ports which are enabled */ if ((def->nparallels > 0) && (VIR_ALLOC_N(def->parallels, def->nparall= els) >=3D 0)) { - for (i =3D 0; i < def->nparallels; i++) - ignore_value(VIR_ALLOC(def->parallels[i])); + for (i =3D 0; i < def->nparallels; i++) { + def->parallels[i] =3D virDomainChrDefNew(NULL); + if (!def->parallels[i]) { + /* there is no provision for returning an error + * (although the libvirtd logs will show an OOM error), + * but we need to at least prevent dereferencing + * def->parallels[i] and later (including continuing in + * this function), as it will otherwise cause a SEGV. + */ + def->nparallels =3D i; + return; + } + } } =20 /* Now get the details about the parallel ports here */ --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list