From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C814791775 for ; Wed, 28 Sep 2022 14:51:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3882C28737 for ; Wed, 28 Sep 2022 14:51:24 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 28 Sep 2022 14:51:20 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7465044636 for ; Wed, 28 Sep 2022 14:51:20 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Wed, 28 Sep 2022 14:50:59 +0200 Message-Id: <20220928125059.1139296-14-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220928125059.1139296-1-f.gruenbichler@proxmox.com> References: <20220928125059.1139296-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.144 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_SHORT 0.001 Use of a URL Shortener for very short URL SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [storage.pm, pvesm.pm, gnu.org] Subject: [pve-devel] [PATCH v6 storage 1/1] (remote) export: check and untaint format X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Sep 2022 12:51:54 -0000 this format comes from the remote cluster, so it might not be supported on the source side - checking whether it's known (as additional safeguard) and untainting (to avoid open3 failure) is required. Signed-off-by: Fabian Grünbichler --- Notes: v6: new PVE/CLI/pvesm.pm | 6 ++---- PVE/Storage.pm | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm index 003b019..9b9676b 100755 --- a/PVE/CLI/pvesm.pm +++ b/PVE/CLI/pvesm.pm @@ -30,8 +30,6 @@ use PVE::CLIHandler; use base qw(PVE::CLIHandler); -my $KNOWN_EXPORT_FORMATS = ['raw+size', 'tar+size', 'qcow2+size', 'vmdk+size', 'zfs', 'btrfs']; - my $nodename = PVE::INotify::nodename(); sub param_mapping { @@ -269,7 +267,7 @@ __PACKAGE__->register_method ({ format => { description => "Export stream format", type => 'string', - enum => $KNOWN_EXPORT_FORMATS, + enum => $PVE::Storage::KNOWN_EXPORT_FORMATS, }, filename => { description => "Destination file name", @@ -355,7 +353,7 @@ __PACKAGE__->register_method ({ format => { description => "Import stream format", type => 'string', - enum => $KNOWN_EXPORT_FORMATS, + enum => $PVE::Storage::KNOWN_EXPORT_FORMATS, }, filename => { description => "Source file name. For '-' stdin is used, the " . diff --git a/PVE/Storage.pm b/PVE/Storage.pm index b9c53a1..ce61fee 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -48,6 +48,8 @@ use constant APIVER => 10; # see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html use constant APIAGE => 1; +our $KNOWN_EXPORT_FORMATS = ['raw+size', 'tar+size', 'qcow2+size', 'vmdk+size', 'zfs', 'btrfs']; + # load standard plugins PVE::Storage::DirPlugin->register(); PVE::Storage::LVMPlugin->register(); @@ -1949,6 +1951,13 @@ sub volume_import_start { sub volume_export_start { my ($cfg, $volid, $format, $log, $opts) = @_; + my $known_format = [ grep { $_ eq $format } $KNOWN_EXPORT_FORMATS->@* ]; + if (!$known_format->@*) { + die "Cannot export '$volid' using unknown export format '$format'\n"; + } + + $format = ($known_format->@*)[0]; + my $run_command_params = delete $opts->{cmd} // {}; my $cmds = $volume_export_prepare->($cfg, $volid, $format, $log, $opts); -- 2.30.2