From nobody Fri May 17 07:08:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696185606335585.5778890003264; Sun, 1 Oct 2023 11:40:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qn1LK-0002m3-Vh; Sun, 01 Oct 2023 14:39:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qn1LJ-0002ls-Og for qemu-devel@nongnu.org; Sun, 01 Oct 2023 14:39:01 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qn1LI-0006OW-AX for qemu-devel@nongnu.org; Sun, 01 Oct 2023 14:39:01 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id BEAC83200EB8; Sun, 1 Oct 2023 14:38:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 01 Oct 2023 14:38:59 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 1 Oct 2023 14:38:57 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1696185538; x= 1696271938; bh=Fk1bg7pCh2iGJ3mNqVOFCielk9qFNKxDe70Z8Ragk3E=; b=P yShKqubcFhwAiIIJuzriLXXZ5E/0nyrDguCnf/fMPt+QDv0yQhtRmF883ImBYfsS iOalqO2t89UjBGccqaS7TcDGi6lkxufbpj99w3uC9y8GXLh/iF7gnPzZ/dAzS4bE Eaivu/YjuCas49z4MDaeZijCOQj6+gu7gY+T8ZI1muFAJilQYk7Eb5j9cIVCZcb2 t1DSvyFQT5ICDsEp5BEfK+qaCZtAmLpzCDGu4CaDI2egrZE5QgMoUK8zYhsWvVkY wvHIHeZO3griZDzd7E2KcvepHaRAhaLWEWuHGmjZ0BVTG5lOD/3/wcMnqDY7gqkR x379JLwKcUauQGeP4bUwQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1696185538; x= 1696271938; bh=Fk1bg7pCh2iGJ3mNqVOFCielk9qFNKxDe70Z8Ragk3E=; b=C r337AGhvZU3jtNAaBlS+BasyedukfdeSOY6YIwGFGNYeBUvR4VIJftcAJIVp8zOZ fuis0JYozNeFL++ECZm7rv5LW5oUf8ujCvzk8Wx3PE0o7+N+QfLhPoCcO4efJ9zH iupXq2TofP+eEnbz7m14dxQLQG6N/gTbfI2B0GoEoiksYJjJux9DHbh+BdD7gxaE RqF+qdundFFAhaYrux2ZivQGwYDZULZDY9Byb5N07MaPkv0TCoAOeSWA83VPqnEN 8djfF69QGOQ7vdv0UcfAlHKqJwJ9qRILYpxIt6FdNgEyJMHJvq4xL57SBbjB1udk BO1hA3LjG6DDeTsUP/iRw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdefucetufdoteggodetrfdotffvucfrrh hofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfeehmdenucfjughrpefhvfevufffkf fojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceougiguhes ugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeikedvueetff elieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail From: Daniel Xu To: michael.roth@amd.com, kkostiuk@redhat.com, armbru@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org Subject: [PATCH 1/2] qga: Fix memory leak when output stream is unused Date: Sun, 1 Oct 2023 12:38:25 -0600 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=64.147.123.20; envelope-from=dxu@dxuuu.xyz; helo=wout4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1696185607218100001 Content-Type: text/plain; charset="utf-8" If capture-output is requested but one of the channels goes unused (eg. we attempt to capture stderr but the command never writes to stderr), we can leak memory. guest_exec_output_watch() is (from what I understand) unconditionally called for both streams if output capture is requested. The first call will always pass the `p->size =3D=3D p->length` check b/c both values are 0. Then GUEST_EXEC_IO_SIZE bytes will be allocated for the stream. But when we reap the exited process there's a `gei->err.length > 0` check to actually free the buffer. Which does not get run if the command doesn't write to the stream. Fix by making free() unconditional. Reviewed-by: Konstantin Kostiuk Signed-off-by: Daniel Xu --- qga/commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qga/commands.c b/qga/commands.c index 09c683e263..ce172edd2d 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -206,15 +206,15 @@ GuestExecStatus *qmp_guest_exec_status(int64_t pid, E= rror **errp) #endif if (gei->out.length > 0) { ges->out_data =3D g_base64_encode(gei->out.data, gei->out.leng= th); - g_free(gei->out.data); ges->has_out_truncated =3D gei->out.truncated; } + g_free(gei->out.data); =20 if (gei->err.length > 0) { ges->err_data =3D g_base64_encode(gei->err.data, gei->err.leng= th); - g_free(gei->err.data); ges->has_err_truncated =3D gei->err.truncated; } + g_free(gei->err.data); =20 QTAILQ_REMOVE(&guest_exec_state.processes, gei, next); g_free(gei); --=20 2.42.0 From nobody Fri May 17 07:08:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696185606385256.93720206237265; Sun, 1 Oct 2023 11:40:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qn1LM-0002mU-ES; Sun, 01 Oct 2023 14:39:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qn1LL-0002mL-Ld for qemu-devel@nongnu.org; Sun, 01 Oct 2023 14:39:03 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qn1LK-0006Qp-7p for qemu-devel@nongnu.org; Sun, 01 Oct 2023 14:39:03 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id AB3463200EBB; Sun, 1 Oct 2023 14:39:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 01 Oct 2023 14:39:01 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 1 Oct 2023 14:38:59 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1696185540; x= 1696271940; bh=BiH8F8J+Usfp2OTAGkqTcECSCj+UFE/E2rKabqN4Lfo=; b=e 9RuYRKod8F2UnyGi20k2xqJN8YvlPzOw3rtStFOxfbMTl/D0WUUXssrQPDSTYYvf yt7PGuanfT/jvwP+XHVa1PC+x9bU8Q1vo8PgTbUD1suTbJP0pw2w7ejobWHk+dt7 tg2xAgJ2tiEhlcFoGQWWjqpldb2b+5rz/i+aM5q/jXIg91IFVV+ClNj4w6tXCvKV CufdtMvBUQ9r33uuOXaydmvIreDMCoz7oScFuLaMsniXiWBvSqLZZg7Gu7Q40oeD qA4/TEjmQTmgwR+ZAm2/sn1h1FmCwq6UkRolfuaBUxfSEdQ9sWIHD17zOo4zJkqr Z9SBEa4tGJhPSFL0TxQ/A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1696185540; x= 1696271940; bh=BiH8F8J+Usfp2OTAGkqTcECSCj+UFE/E2rKabqN4Lfo=; b=D Aj7oMSGBHOwGJM0Tr3crEhs4tpXqu84lcVMKlfsnxv9DjdxXYNHjVQeAVYNzgD1t ztxzTfrOBSZePO5jDAdFv1n05ilY4TWcT23N54tito2ElyupKPGRfDIrh6iuGFUN /8gYweHLGc+4p5BTxVc3xQtsK7Tmz8FD3oWcRcQoGDvgC9gtDZS1VgmxV3IgRq3h t9KbRtuCuk4pmu0XDQenTbzI6rdd6j+TeR5rF0AdG+Rqs4o9dC6PIuYkRPl3saBH cB0JhBg7orG3moXB8Fly4zpai4K6kCaNGMQj2ikfwHeqkzGUxyvBHzJ4jhiHDxr7 22HOxDG5f0lLRUaYaDnIw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdefucetufdoteggodetrfdotffvucfrrh hofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvfevufffkf fojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceougiguhes ugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeikedvueetff elieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail From: Daniel Xu To: michael.roth@amd.com, kkostiuk@redhat.com, armbru@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org Subject: [PATCH 2/2] qapi: qga: Clarify when out-data and err-data are populated Date: Sun, 1 Oct 2023 12:38:26 -0600 Message-ID: <935735389830bbe8407d95ebf89632792bf11a30.1696185261.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=64.147.123.20; envelope-from=dxu@dxuuu.xyz; helo=wout4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1696185607663100005 Content-Type: text/plain; charset="utf-8" If output is being captured for a guest-exec invocation, the out-data and err-data fields of guest-exec-status are only populated after the process is reaped. This is somewhat counter intuitive and too late to change. Thus, it would be good to document the behavior. Signed-off-by: Daniel Xu Acked-by: Markus Armbruster Reviewed-by: Konstantin Kostiuk --- qga/qapi-schema.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index b720dd4379..876e2a8ea8 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1220,11 +1220,13 @@ # @signal: signal number (linux) or unhandled exception code (windows) # if the process was abnormally terminated. # -# @out-data: base64-encoded stdout of the process +# @out-data: base64-encoded stdout of the process. This field will only +# be populated after the process exits. # -# @err-data: base64-encoded stderr of the process Note: @out-data and +# @err-data: base64-encoded stderr of the process. Note: @out-data and # @err-data are present only if 'capture-output' was specified for -# 'guest-exec' +# 'guest-exec'. This field will only be populated after the process +# exits. # # @out-truncated: true if stdout was not fully captured due to size # limitation. --=20 2.42.0