From nobody Thu Nov 12 15:08:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1793876103; cv=none; d=zohomail.com; s=zohoarc; b=M2ulGuTJMMq/HZDKzYUavZSpDMHwMAr9eZpdxA4y1KzBHxxSxqeSEtW3nz1TRo6vzfn/25ZgHmUTkgQSmlA0oSkexQOTJyhznbL9JXkBNtDle2CpfqRJPMX2XckldAkEiAfL7z4qIi2vJwHAGYeZ6k8GbKKGVIJDLSur6p5oXlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793876103; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=jXcyCn6KvOJ827Nsv4sVdCWOEx/DgIq5Bm2Sq4i+k4k=; b=M01cYAJzyHGtcUGkQdDlDGWvTnQIEqML4Aa+EKVJpjHX85gaqaF7yXPDU0XWgWI0Aqi/+X7EfDylTUoM8btXPidgTT2xus0X/yTSkCVks9HtQ+/tWTF4lz07W9x7CcrdPpNyixC69+Cag+QVSSKKQPz/QLo3MS11brtyyUL0EzY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1793876103008615.6076041072323; Thu, 5 Nov 2026 02:55:03 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id C038841ADC; Thu, 5 Nov 2026 05:55:01 -0500 (EST) Received: from [172.19.199.19] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id EAD5E3F36B; Thu, 5 Nov 2026 05:53:51 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 1EFE23F321; Thu, 5 Nov 2026 05:53:43 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 092B53F302 for ; Thu, 5 Nov 2026 05:53:40 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-Emfi4p-ZPbeEWPL8PPbdjg-1; Thu, 05 Nov 2026 05:53:39 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7BEC818004F8 for ; Thu, 5 Nov 2026 10:53:38 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.24.8]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B1C351956089 for ; Thu, 5 Nov 2026 10:53:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793876020; h=from:from: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; bh=jXcyCn6KvOJ827Nsv4sVdCWOEx/DgIq5Bm2Sq4i+k4k=; b=B7p4CkT0Ttcheto6Vi8bTIJMgPvoEMKh9lAUBHCPG7PzDkkxqopo/eTibnuJX5+/6MA+an 3VVdJ61vvhODEev563zleLCwq+r5h2bUTgmJVTwydu4Egig0p40zfDPUN1nngucPA6X2c0 Wt/228MFi1bSOxFDokJBSVJKQJzoAxE= X-MC-Unique: Emfi4p-ZPbeEWPL8PPbdjg-1 X-Mimecast-MFC-AGG-ID: Emfi4p-ZPbeEWPL8PPbdjg_1793876018 To: devel@lists.libvirt.org Subject: [PATCH] qemu: migration: Ensure that compression program error buffer is in scope during runtime Date: Thu, 5 Nov 2026 11:53:36 +0100 Message-ID: <5a3991ce660397fbb2462a26479881958bdd8e36.1793876016.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zpuSVoRCzvI4ixhuqjhzCW1KCKiD0sd0Vqsmrb1CgA4_1793876018 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: IOD3E6AIABWG5XJU3H34IEXW6OPEBBC5 X-Message-ID-Hash: IOD3E6AIABWG5XJU3H34IEXW6OPEBBC5 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793876111523158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa 'virCommand' requires that the error buffer is available while the process is running. In 'qemuMigrationSrcToLegacyFile' a stack'd variable for the buffer pointer is registered, and the command is started, but it may continue executing even after return to the caller 'qemuMigrationSrcToFile' where 'virCommandWait' is called and thus if the command generates stderr after that it can overwrite the stack variable. This happens since the function was split into multiple parts in c2518f7bc7dd4f8ab8655a12ec3a000e1eb5b232. Fix it by moving the error buffer to 'qemuMigrationSrcToFile'. It's used for a debug message so we can move it up. Fixes: c2518f7bc7dd4f8ab8655a12ec3a000e1eb5b232 Closes: https://gitlab.com/libvirt/libvirt/-/work_items/932 Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/qemu/qemu_migration.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 76661de09a..5d4d8b5a32 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -7225,7 +7225,6 @@ qemuMigrationSrcToLegacyFile(virDomainObj *vm, qemuDomainObjPrivate *priv =3D vm->privateData; int ret =3D -1; int pipeFD[2] =3D { -1, -1 }; - char *errbuf =3D NULL; if (compressor && virPipe(pipeFD) < 0) return -1; @@ -7246,7 +7245,6 @@ qemuMigrationSrcToLegacyFile(virDomainObj *vm, } else { virCommandSetInputFD(compressor, pipeFD[0]); virCommandSetOutputFD(compressor, &fd); - virCommandSetErrorBuffer(compressor, &errbuf); virCommandDoAsyncIO(compressor); if (virSetCloseExec(pipeFD[1]) < 0) { virReportSystemError(errno, "%s", @@ -7269,11 +7267,6 @@ qemuMigrationSrcToLegacyFile(virDomainObj *vm, VIR_FORCE_CLOSE(pipeFD[0]); VIR_FORCE_CLOSE(pipeFD[1]); - if (errbuf) { - VIR_DEBUG("Compression binary stderr: %s", NULLSTR(errbuf)); - VIR_FREE(errbuf); - } - return ret; } @@ -7342,6 +7335,7 @@ qemuMigrationSrcToFile(virDomainObj *vm, int ret =3D -1; unsigned long saveMigBandwidth =3D priv->migMaxBandwidth; virErrorPtr orig_err =3D NULL; + g_autofree char *compressor_errbuf =3D NULL; if (qemuMigrationSetDBusVMState(vm) < 0) return -1; @@ -7367,10 +7361,12 @@ qemuMigrationSrcToFile(virDomainObj *vm, } if (migParams && - qemuMigrationParamsCapEnabled(migParams, QEMU_MIGRATION_CAP_MAPPED= _RAM)) + qemuMigrationParamsCapEnabled(migParams, QEMU_MIGRATION_CAP_MAPPED= _RAM)) { rc =3D qemuMigrationSrcToSparseFile(vm, path, fd, bypassCache, asy= ncJob); - else + } else { + virCommandSetErrorBuffer(compressor, &compressor_errbuf); rc =3D qemuMigrationSrcToLegacyFile(vm, *fd, compressor, asyncJob); + } if (rc < 0) goto cleanup; @@ -7397,6 +7393,9 @@ qemuMigrationSrcToFile(virDomainObj *vm, if (ret < 0 && !orig_err) virErrorPreserveLast(&orig_err); + if (compressor_errbuf) + VIR_DEBUG("Compression binary stderr: %s", compressor_errbuf); + /* Remove fdset passed to qemu and restore max migration bandwidth */ if (qemuDomainObjIsActive(vm)) { if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) =3D=3D 0) { --=20 2.56.0