From nobody Sun Apr 28 08:38:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611335332; cv=none; d=zohomail.com; s=zohoarc; b=GXKvf+GcOGJofiYQXqwtuK3Vf4aIEe4RU0PYb7CktvItnzwf3BmTGjH984YYc6mrucjnWisACMU0SRh9t4sDWWM0fj6MNRS3k8rthvp+6qLgdBcPiAxX5gose7/TeUn7qKQidfSdAlSbhStMoMIMJA8QrfmX7Tv+Sgkmww9Uj4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611335332; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=4zWPwLH0VAvYAsQM5Xg+lVMRoZh88G8HIVWmmUciWeo=; b=ide9xG/UIekkLiY86CjefJrzFHWUxGdKCr2ii757HGggjcHviMBriinD2os5eDG6mZeBxXcylSW0wNcHcyUuXsBvxip35iReYFaMVM0+kqOW8+G2QVUaemjFIHN0Vd2iuCrtkwJ1vqEzcOu+KXf/eWxoYkMCwPU08Nwx12e6++U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611335332982262.95188310684307; Fri, 22 Jan 2021 09:08:52 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-e0FV-QAIMjmLT1G6FXQofA-1; Fri, 22 Jan 2021 12:08:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12A7E804034; Fri, 22 Jan 2021 17:08:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCD045C230; Fri, 22 Jan 2021 17:08:43 +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 99BD91809CA2; Fri, 22 Jan 2021 17:08:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10MH8g07007773 for ; Fri, 22 Jan 2021 12:08:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 327011042A41; Fri, 22 Jan 2021 17:08:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-108.ams2.redhat.com [10.36.115.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BA9A1042A40; Fri, 22 Jan 2021 17:08:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611335331; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4zWPwLH0VAvYAsQM5Xg+lVMRoZh88G8HIVWmmUciWeo=; b=IixmVxSZmX8oJzuKLsJaVVJegipS/K9vmxfPLj2uYqKB4lzCoDgRX+PG4Q8z7ClNaPqKGX eX5NPQHA6c1x8cKXusxuXQsNGnmYUarrM1FYbMQwrYfMueybMx3rqepMVMIEEB/FlLVm0m GCRubvCdIJ18qx+hPRJKSFamR9jXUPA= X-MC-Unique: e0FV-QAIMjmLT1G6FXQofA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH] qemu: fix release of virDomainObjPtr in SSH key APIs Date: Fri, 22 Jan 2021 17:08:35 +0000 Message-Id: <20210122170835.3522453-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) The qemuDomainObjFromDomain() API must be paired with the virDomainObjEndAPI API. The qemuDomainAuthorizedSSHKeysGet method simply did 'return -1' leaking a reference in two paths. The qemuDomainAuthorizedSSHKeysSet method marked the object as an autoptr while also have some code paths that will call virDomainObjEndAPI, resulting in attempted double free. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Daniel Henrique Barboza Reviewed-by: Michal Privoznik --- src/qemu/qemu_driver.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 027617deef..05e021cce4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20254,10 +20254,10 @@ qemuDomainAuthorizedSSHKeysGet(virDomainPtr dom, return -1; =20 if (virDomainAuthorizedSshKeysGetEnsureACL(dom->conn, vm->def) < 0) - return -1; + goto cleanup; =20 if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_QUERY) < 0) - return -1; + goto cleanup; =20 if (!qemuDomainAgentAvailable(vm, true)) goto endagentjob; @@ -20268,6 +20268,7 @@ qemuDomainAuthorizedSSHKeysGet(virDomainPtr dom, =20 endagentjob: qemuDomainObjEndAgentJob(vm); + cleanup: virDomainObjEndAPI(&vm); return rv; } @@ -20281,7 +20282,7 @@ qemuDomainAuthorizedSSHKeysSet(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver =3D dom->conn->privateData; - g_autoptr(virDomainObj) vm =3D NULL; + virDomainObjPtr vm =3D NULL; qemuAgentPtr agent; const bool append =3D flags & VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_APPEN= D; const bool remove =3D flags & VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOV= E; @@ -20294,10 +20295,10 @@ qemuDomainAuthorizedSSHKeysSet(virDomainPtr dom, return -1; =20 if (virDomainAuthorizedSshKeysSetEnsureACL(dom->conn, vm->def) < 0) - return -1; + goto cleanup; =20 if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_QUERY) < 0) - return -1; + goto cleanup; =20 if (!qemuDomainAgentAvailable(vm, true)) goto endagentjob; @@ -20311,6 +20312,7 @@ qemuDomainAuthorizedSSHKeysSet(virDomainPtr dom, =20 endagentjob: qemuDomainObjEndAgentJob(vm); + cleanup: virDomainObjEndAPI(&vm); return rv; } --=20 2.29.2