From nobody Fri May 3 17:19:05 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 1528230906632963.1018685875418; Tue, 5 Jun 2018 13:35:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B3F17A4B9; Tue, 5 Jun 2018 20:35:03 +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 E4A60100194A; Tue, 5 Jun 2018 20:35:02 +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 EC5854CA80; Tue, 5 Jun 2018 20:34:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w55KYtiY019076 for ; Tue, 5 Jun 2018 16:34:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 445D717016; Tue, 5 Jun 2018 20:34:55 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-131.phx2.redhat.com [10.3.117.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFC9517003 for ; Tue, 5 Jun 2018 20:34:53 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 5 Jun 2018 16:34:47 -0400 Message-Id: <20180605203447.26598-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: Fix double free in qemuDomainSecretAESClear 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 05 Jun 2018 20:35:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Commit id 02b031a4 added a secondary path from which the incoming @secinfo would not be free'd until the private data was freed in qemuDomainStorageSourcePrivateDispose. However, by doing this the original intention to free @*secinfo afterwards is lost and thus the pass by value of the secinfo->s.aes (or secinfo->s.plain for its method) results in not keeping the NULL setting in the various secret.{username|iv|ciphertext} fields upon return to qemuDomainSecretInfoClear and eventually will result in a double free at domain destroy: raise () abort () __libc_message () malloc_printerr () _int_free () virFree qemuDomainSecretAESClear qemuDomainSecretInfoClear qemuDomainSecretInfoFree qemuDomainStorageSourcePrivateDispose virObjectUnref virStorageSourceClear virStorageSourceFree virDomainDiskDefFree virDomainDefFree virDomainObjRemoveTransientDef qemuProcessStop qemuDomainDestroyFlags virDomainDestroy Signed-off-by: John Ferlan --- src/qemu/qemu_domain.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) Domains w/ secrets weren't very happy when I went to destroy them today during testing... Fortunately issue is not in 4.4.0... I modified both Plain and AES just because it's probably best to avoid something like this in the future. diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f135117a95..1fb1ef1deb 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -945,23 +945,23 @@ qemuDomainMasterKeyCreate(virDomainObjPtr vm) =20 =20 static void -qemuDomainSecretPlainClear(qemuDomainSecretPlain secret) +qemuDomainSecretPlainClear(qemuDomainSecretPlainPtr secret) { - VIR_FREE(secret.username); - VIR_DISPOSE_N(secret.secret, secret.secretlen); + VIR_FREE(secret->username); + VIR_DISPOSE_N(secret->secret, secret->secretlen); } =20 =20 static void -qemuDomainSecretAESClear(qemuDomainSecretAES secret, +qemuDomainSecretAESClear(qemuDomainSecretAESPtr secret, bool keepAlias) { if (!keepAlias) - VIR_FREE(secret.alias); + VIR_FREE(secret->alias); =20 - VIR_FREE(secret.username); - VIR_FREE(secret.iv); - VIR_FREE(secret.ciphertext); + VIR_FREE(secret->username); + VIR_FREE(secret->iv); + VIR_FREE(secret->ciphertext); } =20 =20 @@ -974,11 +974,11 @@ qemuDomainSecretInfoClear(qemuDomainSecretInfoPtr sec= info, =20 switch ((qemuDomainSecretInfoType) secinfo->type) { case VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN: - qemuDomainSecretPlainClear(secinfo->s.plain); + qemuDomainSecretPlainClear(&secinfo->s.plain); break; =20 case VIR_DOMAIN_SECRET_INFO_TYPE_AES: - qemuDomainSecretAESClear(secinfo->s.aes, keepAlias); + qemuDomainSecretAESClear(&secinfo->s.aes, keepAlias); break; =20 case VIR_DOMAIN_SECRET_INFO_TYPE_LAST: --=20 2.14.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list