From nobody Sun May 5 13:34:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1614191455; cv=none; d=zohomail.com; s=zohoarc; b=RwJFICGkMdyKqLnI7B/1lEJTdxUazCrwhbc+PosBjpcsn3iEKhiIWBD5rauxJQD0NSnHA5ywnEFHYsaAMNqmwvFsO+wG/bNy3I1fB6Rd+whLbs/6ObnPNq5sizp9s3xTFYN+6iHhLkpHEdVZlPQhZlRpFuxNJMKHR/x4c19gv50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614191455; 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=zor0u+Rj0GmuEDzpsurd4O5PId2MU7lWVIF8u5CANg4=; b=gyXbj4VOFsInLSwfaaXPEh5OLPEV0UH/0U+wR7yFFZ3DviPd9e/KF9goyEv+EQgB/3U3qWa7Fpa9nQ5mfO+HqWcqO2UqCZLcJa2CuEVmrvflUrOpjOGymRCMrbzPMH1vovqxOKoS1yKjlweavEYPG9FfRqiM7oNPUHVxyNbQpPU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1614191455956897.2645248057183; Wed, 24 Feb 2021 10:30:55 -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-265-ObOfXwo3Os6i93y5m_BI8Q-1; Wed, 24 Feb 2021 13:30:51 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A43C1E561; Wed, 24 Feb 2021 18:30: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 5C9D810016F6; Wed, 24 Feb 2021 18:30: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 87ECF18095CB; Wed, 24 Feb 2021 18:30:40 +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 11OIUdhU006926 for ; Wed, 24 Feb 2021 13:30:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 484C260BF3; Wed, 24 Feb 2021 18:30:39 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.40.193.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BA3B60BE5 for ; Wed, 24 Feb 2021 18:30:33 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id D7ED4241AB0; Wed, 24 Feb 2021 19:30:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614191454; 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=zor0u+Rj0GmuEDzpsurd4O5PId2MU7lWVIF8u5CANg4=; b=O6943eh+yniBJdEjv/atDuyvdOqx7NY+qyLQfzjbWY3Y+FdIk2fXJvRCUDwv8SScwBBlOF 78tl/fuoWTyHCWLBlnemQFAjvEuADW9t4EiRNU9XKnv0EUO1jYFR7g8u8Lg44G1u7gChDG EBkb9TvKJT9aVzfNoLPIdv/zmLIY6BE= X-MC-Unique: ObOfXwo3Os6i93y5m_BI8Q-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH] qemu_domainjob: Make copy of owner API Date: Wed, 24 Feb 2021 19:30:20 +0100 Message-Id: <718bfef15fdf80b56a0b8f6e3f1370497a6f9309.1614191420.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.84 on 10.5.11.22 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Using the job owner API name directly works fine as long as it is a static string or the owner's thread is still running. However, this is not always the case. For example, when the owner API name is filled in a job when we're reconnecting to existing domains after daemon restart, the dynamically allocated owner name will disappear with the reconnecting thread. Any follow up usage of the pointer will read random memory. Signed-off-by: Jiri Denemark Reviewed-by: Peter Krempa --- src/qemu/qemu_domainjob.c | 12 ++++++------ src/qemu/qemu_process.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c index 3c2c6b9179..b58d6837ad 100644 --- a/src/qemu/qemu_domainjob.c +++ b/src/qemu/qemu_domainjob.c @@ -190,7 +190,7 @@ qemuDomainObjResetJob(qemuDomainJobObjPtr job) { job->active =3D QEMU_JOB_NONE; job->owner =3D 0; - job->ownerAPI =3D NULL; + g_clear_pointer(&job->ownerAPI, g_free); job->started =3D 0; } =20 @@ -200,7 +200,7 @@ qemuDomainObjResetAgentJob(qemuDomainJobObjPtr job) { job->agentActive =3D QEMU_AGENT_JOB_NONE; job->agentOwner =3D 0; - job->agentOwnerAPI =3D NULL; + g_clear_pointer(&job->agentOwnerAPI, g_free); job->agentStarted =3D 0; } =20 @@ -210,7 +210,7 @@ qemuDomainObjResetAsyncJob(qemuDomainJobObjPtr job) { job->asyncJob =3D QEMU_ASYNC_JOB_NONE; job->asyncOwner =3D 0; - job->asyncOwnerAPI =3D NULL; + g_clear_pointer(&job->asyncOwnerAPI, g_free); job->asyncStarted =3D 0; job->phase =3D 0; job->mask =3D QEMU_JOB_DEFAULT_MASK; @@ -890,7 +890,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, obj, obj->def->name); priv->job.active =3D job; priv->job.owner =3D virThreadSelfID(); - priv->job.ownerAPI =3D virThreadJobGet(); + priv->job.ownerAPI =3D g_strdup(virThreadJobGet()); priv->job.started =3D now; } else { VIR_DEBUG("Started async job: %s (vm=3D%p name=3D%s)", @@ -901,7 +901,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, priv->job.current->status =3D QEMU_DOMAIN_JOB_STATUS_ACTIVE; priv->job.asyncJob =3D asyncJob; priv->job.asyncOwner =3D virThreadSelfID(); - priv->job.asyncOwnerAPI =3D virThreadJobGet(); + priv->job.asyncOwnerAPI =3D g_strdup(virThreadJobGet()); priv->job.asyncStarted =3D now; priv->job.current->started =3D now; } @@ -917,7 +917,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, qemuDomainAsyncJobTypeToString(priv->job.asyncJob)); priv->job.agentActive =3D agentJob; priv->job.agentOwner =3D virThreadSelfID(); - priv->job.agentOwnerAPI =3D virThreadJobGet(); + priv->job.agentOwnerAPI =3D g_strdup(virThreadJobGet()); priv->job.agentStarted =3D now; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index bfa742577f..398f63282e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3732,7 +3732,7 @@ qemuProcessRecoverJob(virQEMUDriverPtr driver, /* Restore the config of the async job which is not persisted */ priv->jobs_queued++; priv->job.asyncJob =3D QEMU_ASYNC_JOB_BACKUP; - priv->job.asyncOwnerAPI =3D virThreadJobGet(); + priv->job.asyncOwnerAPI =3D g_strdup(virThreadJobGet()); priv->job.asyncStarted =3D now; =20 qemuDomainObjSetAsyncJobMask(vm, (QEMU_JOB_DEFAULT_MASK | --=20 2.30.0