From nobody Thu May 2 19:15:19 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532939126291370.60960477029437; Mon, 30 Jul 2018 01:25:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCAE43084035; Mon, 30 Jul 2018 08:25:21 +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 B860ED09C0; Mon, 30 Jul 2018 08:25:20 +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 3F5884BB78; Mon, 30 Jul 2018 08:25:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U8PDZv012243 for ; Mon, 30 Jul 2018 04:25:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 621192026D6D; Mon, 30 Jul 2018 08:25:13 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00DCD2026D68 for ; Mon, 30 Jul 2018 08:25:12 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 10:25:05 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH for v4.6.0] cgroups: Don't leave stale pointers around after virCgroupFree 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.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 30 Jul 2018 08:25:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" One of the attributes that original virCgroupFree() had was it set passed pointer to NULL. For instance in the following code the latter call would be practically a no-op: virCgroupFree(&var); virCgroupFree(&var); However, this behaviour of the function was changed in 0f80c71822d824 but corresponding 'var =3D NULL' lines were not added leading to double free: Invalid read of size 8 at 0x52CA3DA: virFree (viralloc.c:582) by 0x52D5272: virCgroupFree (vircgroup.c:1700) by 0x230CE113: qemuDomainObjPrivateDataClear (qemu_domain.c:1923) by 0x230CE2F3: qemuDomainObjPrivateFree (qemu_domain.c:1973) by 0x53922D7: virDomainObjDispose (domain_conf.c:3192) by 0x533B8ED: virObjectUnref (virobject.c:350) by 0x533BE39: virObjectFreeHashData (virobject.c:591) by 0x5305C23: virHashFree (virhash.c:304) by 0x53EAFA7: virDomainObjListDispose (virdomainobjlist.c:92) by 0x533B8ED: virObjectUnref (virobject.c:350) by 0x2315E2AE: qemuStateCleanup (qemu_driver.c:1067) by 0x557CFF6: virStateCleanup (libvirt.c:699) Address 0x29fbbdd0 is 16 bytes inside a block of size 328 free'd at 0x4C2E13B: free (vg_replace_malloc.c:530) by 0x52CA3E4: virFree (viralloc.c:582) by 0x52D52D4: virCgroupFree (vircgroup.c:1706) by 0x230CE113: qemuDomainObjPrivateDataClear (qemu_domain.c:1923) by 0x2311CFE9: qemuProcessStop (qemu_process.c:7144) by 0x2311BF1C: qemuProcessStart (qemu_process.c:6745) by 0x2316E634: qemuDomainObjStart (qemu_driver.c:7293) by 0x2316E8A2: qemuDomainCreateWithFlags (qemu_driver.c:7346) by 0x2316E925: qemuDomainCreate (qemu_driver.c:7365) by 0x5594E9F: virDomainCreate (libvirt-domain.c:6534) by 0x1367D1: remoteDispatchDomainCreate (remote_daemon_dispatch_stubs.h= :4434) by 0x1366EA: remoteDispatchDomainCreateHelper (remote_daemon_dispatch_s= tubs.h:4410) Signed-off-by: Michal Privoznik --- src/lxc/lxc_process.c | 1 + src/qemu/qemu_cgroup.c | 2 ++ src/qemu/qemu_domain.c | 1 + src/util/vircgroup.c | 5 +++++ 4 files changed, 9 insertions(+) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 5d8fa63c67..4d118cb6fd 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -221,6 +221,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, if (priv->cgroup) { virCgroupRemove(priv->cgroup); virCgroupFree(priv->cgroup); + priv->cgroup =3D NULL; } =20 /* Get machined to terminate the machine as it may not have cleaned it diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 8a00ffcd45..cd1e01262b 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -921,6 +921,7 @@ qemuInitCgroup(virDomainObjPtr vm, goto done; =20 virCgroupFree(priv->cgroup); + priv->cgroup =3D NULL; =20 if (!vm->def->resource) { virDomainResourceDefPtr res; @@ -1058,6 +1059,7 @@ qemuConnectCgroup(virDomainObjPtr vm) goto done; =20 virCgroupFree(priv->cgroup); + priv->cgroup =3D NULL; =20 if (virCgroupNewDetectMachine(vm->def->name, "qemu", diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index bda53814a3..bfffd3da27 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1921,6 +1921,7 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr= priv) priv->qemuDevices =3D NULL; =20 virCgroupFree(priv->cgroup); + priv->cgroup =3D NULL; =20 virPerfFree(priv->perf); priv->perf =3D NULL; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 472a8167f5..6e2e06bae3 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1371,6 +1371,7 @@ virCgroupNewDomainPartition(virCgroupPtr partition, VIR_CGROUP_MEM_HIERACHY) < 0) { virCgroupRemove(*group); virCgroupFree(*group); + *group =3D NULL; return -1; } =20 @@ -1428,6 +1429,7 @@ virCgroupNewThread(virCgroupPtr domain, if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) { virCgroupRemove(*group); virCgroupFree(*group); + *group =3D NULL; return -1; } =20 @@ -1466,6 +1468,7 @@ virCgroupNewDetectMachine(const char *name, VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'", name, drivername); virCgroupFree(*group); + *group =3D NULL; return 0; } =20 @@ -1566,6 +1569,7 @@ virCgroupNewMachineSystemd(const char *name, virErrorPtr saved =3D virSaveLastError(); virCgroupRemove(*group); virCgroupFree(*group); + *group =3D NULL; if (saved) { virSetError(saved); virFreeError(saved); @@ -1617,6 +1621,7 @@ virCgroupNewMachineManual(const char *name, virErrorPtr saved =3D virSaveLastError(); virCgroupRemove(*group); virCgroupFree(*group); + *group =3D NULL; if (saved) { virSetError(saved); virFreeError(saved); --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list