From nobody Sat Oct 11 12:20:38 2025 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=1688982769; cv=none; d=zohomail.com; s=zohoarc; b=UGIHVLBrlAz6a1g0XY5DmF3d21iFnm1W/cXD0EP4OGQ2Skl2qxko0+b6Q++TWEnXmdMxqsDektwIyXwS6ZUHSC78Zy707v1AjlljeqGFRmlXIMTdO239WP1A6FfWQZd96kryjoPtQmNKrRGWsekqUya+xcWcwffraeDcpM4ZQ/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688982769; 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=XOiNN60KMyRDc/hxXgER13iY2XX+yjtjIffijDZicf0=; b=gS0dYmokEAfp0EV7JRTQXTpK49NTrMCAXKa8kVWPIfJNEIzvBX4dAKk7UP6ZbO4EiCPZv9t5h3xX8FENpJPBiRen8sGH1L5nQmnLmxP/fuogH8kfW+zD1Ul9cblJkPOPfqWHtifjnKdyHmAuROE9x+TbOB5WlC24uF6g0s/PdjQ= 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 1688982769587524.2596009508919; Mon, 10 Jul 2023 02:52:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qInZ7-0005uD-2u; Mon, 10 Jul 2023 05:52:21 -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 1qInYc-0005LA-FF for qemu-devel@nongnu.org; Mon, 10 Jul 2023 05:51:59 -0400 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 1qInYZ-0004ge-9B for qemu-devel@nongnu.org; Mon, 10 Jul 2023 05:51:48 -0400 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-616-zRsJ-PZ2OT2e53CiW_4uKA-1; Mon, 10 Jul 2023 05:51:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2B528022EF; Mon, 10 Jul 2023 09:51:41 +0000 (UTC) Received: from kostyanf14nb.redhat.com (unknown [10.45.225.233]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D73D840C206F; Mon, 10 Jul 2023 09:51:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688982705; 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=XOiNN60KMyRDc/hxXgER13iY2XX+yjtjIffijDZicf0=; b=URqlFLn9A7vA8VDZzzcok8Ur4oc7C3TR4Wc7pxSumqwY12rWUzRedBuPBQbf6nTA8HvKW3 X41WrT0b+8pdXb6ouWXO6ngZUjpmZKcGTAz5CJ0Rx+yPamp89NHzrUWV1tf1vvCo5sxU+N 4i76Fh0Ylyy1OFIlNlepBuOzyujFd2E= X-MC-Unique: zRsJ-PZ2OT2e53CiW_4uKA-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Subject: [PATCH v2 2/3] qga: Add new option --allow-rpcs Date: Mon, 10 Jul 2023 12:51:35 +0300 Message-Id: <20230710095136.1022704-3-kkostiuk@redhat.com> In-Reply-To: <20230710095136.1022704-1-kkostiuk@redhat.com> References: <20230710095136.1022704-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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=kkostiuk@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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1688982770324100001 Content-Type: text/plain; charset="utf-8" The allow-rpcs option accepts a comma-separated list of RPCs to enable. This option is opposite to --block-rpcs. Using --block-rpcs and --allow-rpcs at the same time is not allowed. resolves: https://gitlab.com/qemu-project/qemu/-/issues/1505 Signed-off-by: Konstantin Kostiuk Reviewed-by: Marc-Andr=C3=A9 Lureau --- docs/interop/qemu-ga.rst | 5 +++ qga/main.c | 85 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 84 insertions(+), 6 deletions(-) diff --git a/docs/interop/qemu-ga.rst b/docs/interop/qemu-ga.rst index a9183802d1..461c5a35ee 100644 --- a/docs/interop/qemu-ga.rst +++ b/docs/interop/qemu-ga.rst @@ -84,6 +84,11 @@ Options Comma-separated list of RPCs to disable (no spaces, use ``help`` to list available RPCs). =20 +.. option:: -a, --allow-rpcs=3DLIST + + Comma-separated list of RPCs to enable (no spaces, use ``help`` to + list available RPCs). + .. option:: -D, --dump-conf =20 Dump the configuration in a format compatible with ``qemu-ga.conf`` diff --git a/qga/main.c b/qga/main.c index 121ff7a748..002161a0cc 100644 --- a/qga/main.c +++ b/qga/main.c @@ -87,6 +87,7 @@ struct GAState { bool delimit_response; bool frozen; GList *blockedrpcs; + GList *allowedrpcs; char *state_filepath_isfrozen; struct { const char *log_filepath; @@ -261,6 +262,8 @@ QEMU_COPYRIGHT "\n" #endif " -b, --block-rpcs comma-separated list of RPCs to disable (no spaces,\n" " use \"help\" to list available RPCs)\n" +" -a, --allow-rpcs comma-separated list of RPCs to enable (no spaces,\n" +" use \"help\" to list available RPCs)\n" " -D, --dump-conf dump a qemu-ga config file based on current config\n" " options / command-line parameters to stdout\n" " -r, --retry-path attempt re-opening path if it's unavailable or closed= \n" @@ -416,16 +419,38 @@ static void ga_disable_not_allowed_freeze(const QmpCo= mmand *cmd, void *opaque) /* [re-]enable all commands, except those explicitly blocked by user */ static void ga_enable_non_blocked(const QmpCommand *cmd, void *opaque) { - GList *blockedrpcs =3D opaque; + GAState *s =3D opaque; + GList *blockedrpcs =3D s->blockedrpcs; + GList *allowedrpcs =3D s->allowedrpcs; const char *name =3D qmp_command_name(cmd); =20 - if (g_list_find_custom(blockedrpcs, name, ga_strcmp) =3D=3D NULL && - !qmp_command_is_enabled(cmd)) { + if (g_list_find_custom(blockedrpcs, name, ga_strcmp) =3D=3D NULL) { + if (qmp_command_is_enabled(cmd)) { + return; + } + + if (allowedrpcs && + g_list_find_custom(allowedrpcs, name, ga_strcmp) =3D=3D NULL) { + return; + } + g_debug("enabling command: %s", name); qmp_enable_command(&ga_commands, name); } } =20 +/* disable commands that aren't allowed */ +static void ga_disable_not_allowed(const QmpCommand *cmd, void *opaque) +{ + GList *allowedrpcs =3D opaque; + const char *name =3D qmp_command_name(cmd); + + if (g_list_find_custom(allowedrpcs, name, ga_strcmp) =3D=3D NULL) { + g_debug("disabling command: %s", name); + qmp_disable_command(&ga_commands, name, "the command is not allowe= d"); + } +} + static bool ga_create_file(const char *path) { int fd =3D open(path, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR); @@ -497,8 +522,8 @@ void ga_unset_frozen(GAState *s) s->deferred_options.pid_filepath =3D NULL; } =20 - /* enable all disabled, non-blocked commands */ - qmp_for_each_command(&ga_commands, ga_enable_non_blocked, s->blockedrp= cs); + /* enable all disabled, non-blocked and allowed commands */ + qmp_for_each_command(&ga_commands, ga_enable_non_blocked, s); s->frozen =3D false; if (!ga_delete_file(s->state_filepath_isfrozen)) { g_warning("unable to delete %s, fsfreeze may not function properly= ", @@ -984,7 +1009,9 @@ struct GAConfig { const char *service; #endif gchar *bliststr; /* blockedrpcs may point to this string */ + gchar *aliststr; /* allowedrpcs may point to this string */ GList *blockedrpcs; + GList *allowedrpcs; int daemonize; GLogLevelFlags log_level; int dumpconf; @@ -1055,6 +1082,19 @@ static void config_load(GAConfig *config) config->blockedrpcs =3D g_list_concat(config->blockedrpcs, split_list(config->bliststr, ","= )); } + if (g_key_file_has_key(keyfile, "general", "allow-rpcs", NULL)) { + config->aliststr =3D + g_key_file_get_string(keyfile, "general", "allow-rpcs", &gerr); + config->allowedrpcs =3D g_list_concat(config->allowedrpcs, + split_list(config->aliststr, ","= )); + } + + if (g_key_file_has_key(keyfile, "general", blockrpcs_key, NULL) && + g_key_file_has_key(keyfile, "general", "allow-rpcs", NULL)) { + g_critical("wrong config, using 'block-rpcs' and 'allow-rpcs' keys= at" + " the same time is not allowed"); + exit(EXIT_FAILURE); + } =20 end: g_key_file_free(keyfile); @@ -1115,6 +1155,9 @@ static void config_dump(GAConfig *config) tmp =3D list_join(config->blockedrpcs, ','); g_key_file_set_string(keyfile, "general", "block-rpcs", tmp); g_free(tmp); + tmp =3D list_join(config->allowedrpcs, ','); + g_key_file_set_string(keyfile, "general", "allow-rpcs", tmp); + g_free(tmp); =20 tmp =3D g_key_file_to_data(keyfile, NULL, &error); if (error) { @@ -1130,8 +1173,9 @@ static void config_dump(GAConfig *config) =20 static void config_parse(GAConfig *config, int argc, char **argv) { - const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:Dr"; + const char *sopt =3D "hVvdm:p:l:f:F::b:a:s:t:Dr"; int opt_ind =3D 0, ch; + bool block_rpcs =3D false, allow_rpcs =3D false; const struct option lopt[] =3D { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, @@ -1147,6 +1191,7 @@ static void config_parse(GAConfig *config, int argc, = char **argv) { "daemonize", 0, NULL, 'd' }, { "block-rpcs", 1, NULL, 'b' }, { "blacklist", 1, NULL, 'b' }, /* deprecated alias for 'block-rpc= s' */ + { "allow-rpcs", 1, NULL, 'a' }, #ifdef _WIN32 { "service", 1, NULL, 's' }, #endif @@ -1206,6 +1251,17 @@ static void config_parse(GAConfig *config, int argc,= char **argv) } config->blockedrpcs =3D g_list_concat(config->blockedrpcs, split_list(optarg, ",")); + block_rpcs =3D true; + break; + } + case 'a': { + if (is_help_option(optarg)) { + qmp_for_each_command(&ga_commands, ga_print_cmd, NULL); + exit(EXIT_SUCCESS); + } + config->allowedrpcs =3D g_list_concat(config->allowedrpcs, + split_list(optarg, ",")); + allow_rpcs =3D true; break; } #ifdef _WIN32 @@ -1246,6 +1302,12 @@ static void config_parse(GAConfig *config, int argc,= char **argv) exit(EXIT_FAILURE); } } + + if (block_rpcs && allow_rpcs) { + g_critical("wrong commandline, using --block-rpcs and --allow-rpcs= at the" + " same time is not allowed"); + exit(EXIT_FAILURE); + } } =20 static void config_free(GAConfig *config) @@ -1256,10 +1318,12 @@ static void config_free(GAConfig *config) g_free(config->state_dir); g_free(config->channel_path); g_free(config->bliststr); + g_free(config->aliststr); #ifdef CONFIG_FSFREEZE g_free(config->fsfreeze_hook); #endif g_list_free_full(config->blockedrpcs, g_free); + g_list_free_full(config->allowedrpcs, g_free); g_free(config); } =20 @@ -1374,6 +1438,15 @@ static GAState *initialize_agent(GAConfig *config, i= nt socket_activation) return NULL; } =20 + if (config->allowedrpcs) { + qmp_for_each_command(&ga_commands, ga_disable_not_allowed, config-= >allowedrpcs); + s->allowedrpcs =3D config->allowedrpcs; + } + + /* + * Some commands can be blocked due to system limitation. + * Initialize blockedrpcs list even if allowedrpcs specified. + */ config->blockedrpcs =3D ga_command_init_blockedrpcs(config->blockedrpc= s); if (config->blockedrpcs) { GList *l =3D config->blockedrpcs; --=20 2.34.1