From nobody Sun May 5 08:02:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1677774067; cv=none; d=zohomail.com; s=zohoarc; b=MHTs67hzIj4bz6WdQdLnJd1IYIM5eAkB5YZ63bz6R9UK3DSmnxh3LhHtvAIT7VbRDKRPkGyFF73zWBcxYF8lnZICan/VYUNCyMDub3+PZnD5Qbo1oLqAeLUNwuShLB/IBeDy+okiB13aDX/XFGW93eBQcYvDNqfhOAsB198sIeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677774067; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IYN329bJ7ibLK+t2XJFb42rTpmxv73ale4cqgW7vI+w=; b=PbBay+GzpmUlJlgNBTCv1EvBY+Zmqy9jfAgCkVjc5a/eT1UrkCZ9jsl5bOMFJRfVsE2xrUYY0PRg2E5GCiYR+IoL7aDIeUQzm78DDJuti/yxHJDHCeQjHxZts40rmmtsKvBs/SZ7bCMLCJBRACWMKcx7msep/NZ1issMdFAc0Qs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677774067524882.4630919094201; Thu, 2 Mar 2023 08:21:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXlfA-00063h-BE; Thu, 02 Mar 2023 11:20:12 -0500 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 1pXlf6-0005rK-Mr for qemu-devel@nongnu.org; Thu, 02 Mar 2023 11:20:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXlf4-0001K9-0o for qemu-devel@nongnu.org; Thu, 02 Mar 2023 11:20:08 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-435-W50ra_6_Pki9VqQKh5wT7w-1; Thu, 02 Mar 2023 11:20:03 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2D4B28027FD for ; Thu, 2 Mar 2023 16:20:03 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4E3540C6EC4; Thu, 2 Mar 2023 16:20:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677774004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IYN329bJ7ibLK+t2XJFb42rTpmxv73ale4cqgW7vI+w=; b=iblHcKgPD5Q1DwTdSkfkuJN5zmDvAA7V8/1l8hmGyvp0tjpcBoArunok5HE7zvQl88FvgI shyIbVU3G9jTqZshL9s/tujGhAGR8KvTdpaT9qGRgF572SKZPqMqSnizwiRgXncYFGP2li TcHW9AqQwfnzkkXnDS0Fb2SGdlxtidM= X-MC-Unique: W50ra_6_Pki9VqQKh5wT7w-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: "Dr. David Alan Gilbert" , Juan Quintela , Eric Auger , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Richard W . M . Jones" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 1/2] test-vmstate: fix bad GTree usage, use-after-free Date: Thu, 2 Mar 2023 17:19:58 +0100 Message-Id: <20230302161959.9844-2-quintela@redhat.com> In-Reply-To: <20230302161959.9844-1-quintela@redhat.com> References: <20230302161959.9844-1-quintela@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677774068795100001 From: Eric Auger According to g_tree_foreach() documentation: "The tree may not be modified while iterating over it (you can't add/remove items)." compare_trees()/diff_tree() fail to respect this rule. Historically GLib2 used a slice allocator for the GTree APIs which did not immediately release the memory back to the system allocator. As a result QEMU's use-after-free bug was not visible. With GLib > 2.75.3 however, GLib2 has switched to using malloc and now a SIGSEGV can be observed while running test-vmstate. Get rid of the node removal within the tree traversal. Also check the trees have the same number of nodes before the actual diff. Fixes: 9a85e4b8f6 ("migration: Support gtree migration") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1518 Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Eric Auger Reported-by: Richard W.M. Jones Tested-by: Richard W.M. Jones Reviewed-by: Richard W.M. Jones Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- tests/unit/test-vmstate.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c index 79357b29ca..0b7d5ecd68 100644 --- a/tests/unit/test-vmstate.c +++ b/tests/unit/test-vmstate.c @@ -1073,7 +1073,6 @@ static gboolean diff_tree(gpointer key, gpointer valu= e, gpointer data) struct match_node_data d =3D {tp->tree2, key, value}; =20 g_tree_foreach(tp->tree2, tp->match_node, &d); - g_tree_remove(tp->tree1, key); return false; } =20 @@ -1082,9 +1081,9 @@ static void compare_trees(GTree *tree1, GTree *tree2, { struct tree_cmp_data tp =3D {tree1, tree2, function}; =20 + assert(g_tree_nnodes(tree1) =3D=3D g_tree_nnodes(tree2)); g_tree_foreach(tree1, diff_tree, &tp); - assert(g_tree_nnodes(tree1) =3D=3D 0); - assert(g_tree_nnodes(tree2) =3D=3D 0); + g_tree_destroy(g_tree_ref(tree1)); } =20 static void diff_domain(TestGTreeDomain *d1, TestGTreeDomain *d2) --=20 2.39.2 From nobody Sun May 5 08:02:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1677774071; cv=none; d=zohomail.com; s=zohoarc; b=WooJCgTfQhBMnnLyws5T0bnWL9MaM7yUti/bEDGTNh+/9cGeTqI0wVwLY6gbN9mUbnujHTqYUDOBdduXQinkpvHqJtBUNiV7Db3kvDpzuHCWTj+GX/ZcEUrYpA2MUieIem4l2yeBp7Jz5XdDYB1DkM9LyHFms4Ueixy8nlMsjPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677774071; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AXsmp13+L/pl0ri4cE1J2JNq9k9keXfcyCbDzLs9IX4=; b=JzqNVhy5Gczn71ZANXsW1e4Ad6NDbXuGIF3zEMfrcLle3S9soWvrdX4N00BVtvZSKNy1aqOMw9gm20Nr11fzsLQ8FZinD9fPkiSAx4QqJrpkePvo/VpnqjX7GF57YccMa9+3AtMsn6tKgGZpZeUPd8LlABDzVetwc9SROtV8hqc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16777740717102.572625569839829; Thu, 2 Mar 2023 08:21:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXlfD-0006JC-Dw; Thu, 02 Mar 2023 11:20:15 -0500 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 1pXlf8-0005x2-3k for qemu-devel@nongnu.org; Thu, 02 Mar 2023 11:20:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXlf6-0001Ny-Dl for qemu-devel@nongnu.org; Thu, 02 Mar 2023 11:20:09 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-292-65V_3RmWP-y6NH5YLKUbnA-1; Thu, 02 Mar 2023 11:20:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C90E8021BB; Thu, 2 Mar 2023 16:20:04 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 723D1400D79D; Thu, 2 Mar 2023 16:20:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677774007; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AXsmp13+L/pl0ri4cE1J2JNq9k9keXfcyCbDzLs9IX4=; b=UASOzErblZbZDTMxC3RlXxfsynL57cbWTHzjX30O05rHHRKwbOgEgEZunxobayprwmMlSB fjzKjEs9AvtaWMamqjIlfaK8MAcI3K1BFKb3rZpxskzQkYPu0oozyP2d4LqD+b9731Ld7s aNoLJn/mbUc3qBcib0oxOZfy+0U8KgM= X-MC-Unique: 65V_3RmWP-y6NH5YLKUbnA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: "Dr. David Alan Gilbert" , Juan Quintela , "John Berberian, Jr" Subject: [PULL 2/2] Fix exec migration on Windows (w32+w64). Date: Thu, 2 Mar 2023 17:19:59 +0100 Message-Id: <20230302161959.9844-3-quintela@redhat.com> In-Reply-To: <20230302161959.9844-1-quintela@redhat.com> References: <20230302161959.9844-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677774072833100009 Content-Type: text/plain; charset="utf-8" From: "John Berberian, Jr" * Use cmd instead of /bin/sh on Windows. * Try to auto-detect cmd.exe's path, but default to a hard-coded path. Note that this will require that gspawn-win[32|64]-helper.exe and gspawn-win[32|64]-helper-console.exe are included in the Windows binary distributions (cc: Stefan Weil). Signed-off-by: "John Berberian, Jr" Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/exec.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/migration/exec.c b/migration/exec.c index 375d2e1b54..38604d73a6 100644 --- a/migration/exec.c +++ b/migration/exec.c @@ -23,12 +23,31 @@ #include "migration.h" #include "io/channel-command.h" #include "trace.h" +#include "qemu/cutils.h" =20 +#ifdef WIN32 +const char *exec_get_cmd_path(void); +const char *exec_get_cmd_path(void) +{ + g_autofree char *detected_path =3D g_new(char, MAX_PATH); + if (GetSystemDirectoryA(detected_path, MAX_PATH) =3D=3D 0) { + warn_report("Could not detect cmd.exe path, using default."); + return "C:\\Windows\\System32\\cmd.exe"; + } + pstrcat(detected_path, MAX_PATH, "\\cmd.exe"); + return g_steal_pointer(&detected_path); +} +#endif =20 void exec_start_outgoing_migration(MigrationState *s, const char *command,= Error **errp) { QIOChannel *ioc; + +#ifdef WIN32 + const char *argv[] =3D { exec_get_cmd_path(), "/c", command, NULL }; +#else const char *argv[] =3D { "/bin/sh", "-c", command, NULL }; +#endif =20 trace_migration_exec_outgoing(command); ioc =3D QIO_CHANNEL(qio_channel_command_new_spawn(argv, @@ -55,7 +74,12 @@ static gboolean exec_accept_incoming_migration(QIOChanne= l *ioc, void exec_start_incoming_migration(const char *command, Error **errp) { QIOChannel *ioc; + +#ifdef WIN32 + const char *argv[] =3D { exec_get_cmd_path(), "/c", command, NULL }; +#else const char *argv[] =3D { "/bin/sh", "-c", command, NULL }; +#endif =20 trace_migration_exec_incoming(command); ioc =3D QIO_CHANNEL(qio_channel_command_new_spawn(argv, --=20 2.39.2