From nobody Mon Dec 15 23:13:57 2025 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 150004109962484.7793147583169; Fri, 14 Jul 2017 07:04:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5CABC65983; Fri, 14 Jul 2017 14:04:55 +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 2792F7DE1E; Fri, 14 Jul 2017 14:04:55 +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 81CBC4E987; Fri, 14 Jul 2017 14:04:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6EE4riY026885 for ; Fri, 14 Jul 2017 10:04:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2C05467CE7; Fri, 14 Jul 2017 14:04:53 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7AC267CF2 for ; Fri, 14 Jul 2017 14:04:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5CABC65983 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5CABC65983 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 14 Jul 2017 10:04:41 -0400 Message-Id: <20170714140442.21315-4-jferlan@redhat.com> In-Reply-To: <20170714140442.21315-1-jferlan@redhat.com> References: <20170714140442.21315-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/4] secret: Properly handle @def after virSecretObjAdd in driver 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 14 Jul 2017 14:04:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the virSecretObjListAdd technically consumes @def on success, the secretDefineXML should set @def =3D NULL immediately and process the remaining calls using a new @objdef variable. We can use use VIR_STEAL_PTR since we know the Add function just stores @def in obj->def. This fixes a possible double free of @def if the code jumps to restore_backup: and calls virSecretObjListRemove without setting def =3D NULL. In this case, the subsequent call to DefFree would succeed and free @def; however, the call to EndAPI would also call DefFree because the Unref done would be the last one for the @obj meaning the obj->def would be used to call DefFree, but it's already been free'd because @def wasn't managed right within this error path. Signed-off-by: John Ferlan --- src/secret/secret_driver.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 30124b4..77351d8 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -210,6 +210,7 @@ secretDefineXML(virConnectPtr conn, { virSecretPtr ret =3D NULL; virSecretObjPtr obj =3D NULL; + virSecretDefPtr objdef; virSecretDefPtr backup =3D NULL; virSecretDefPtr def; virObjectEventPtr event =3D NULL; @@ -225,8 +226,9 @@ secretDefineXML(virConnectPtr conn, if (!(obj =3D virSecretObjListAdd(driver->secrets, def, driver->configDir, &backup))) goto cleanup; + VIR_STEAL_PTR(objdef, def); =20 - if (!def->isephemeral) { + if (!objdef->isephemeral) { if (backup && backup->isephemeral) { if (virSecretObjSaveData(obj) < 0) goto restore_backup; @@ -248,22 +250,21 @@ secretDefineXML(virConnectPtr conn, /* Saved successfully - drop old values */ virSecretDefFree(backup); =20 - event =3D virSecretEventLifecycleNew(def->uuid, - def->usage_type, - def->usage_id, + event =3D virSecretEventLifecycleNew(objdef->uuid, + objdef->usage_type, + objdef->usage_id, VIR_SECRET_EVENT_DEFINED, 0); =20 ret =3D virGetSecret(conn, - def->uuid, - def->usage_type, - def->usage_id); - def =3D NULL; + objdef->uuid, + objdef->usage_type, + objdef->usage_id); goto cleanup; =20 restore_backup: /* If we have a backup, then secret was defined before, so just restore - * the backup. The current def will be handled below. + * the backup. The current def will be Free'd below. * Otherwise, this is a new secret, thus remove it. */ if (backup) --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list