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 4C8DD74D15 for ; Tue, 22 Jun 2021 17:11:11 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3770129D85 for ; Tue, 22 Jun 2021 17:10:41 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 3294229D0D for ; Tue, 22 Jun 2021 17:10:39 +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 C02C046452 for ; Tue, 22 Jun 2021 17:10:23 +0200 (CEST) Date: Tue, 22 Jun 2021 17:10:22 +0200 From: Stoiko Ivanov To: Thomas Lamprecht Cc: Proxmox VE development discussion Message-ID: <20210622171022.23690ff6@rosa.proxmox.com> In-Reply-To: <5f4ba4d0-8092-0096-5b10-7f02d50fc865@proxmox.com> References: <20210622142824.18773-1-s.ivanov@proxmox.com> <5f4ba4d0-8092-0096-5b10-7f02d50fc865@proxmox.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.662 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 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. [proxmox.com, pbsplugin.pm, tools.pm, plugin.pm] Subject: Re: [pve-devel] [PATCH common] run_command: untaint end of buffer 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: Tue, 22 Jun 2021 15:11:11 -0000 On Tue, 22 Jun 2021 16:41:50 +0200 Thomas Lamprecht wrote: > On 22.06.21 16:28, Stoiko Ivanov wrote: > > The performance improvements added in > > cb9db10c1a9855cf40ff13e81f9dd97d6a9b2698 changed the output handling > > to not remove the taintedness (see perlsec (1)) of the complete output > > anymore. > > > > This results in a few bugs which show up every now and then, and are > > usually quite tedious to hunt down - usually they only occur when > > run via GUI (since pveproxy/pvedaemon run in taint-mode, whereas our > > CLI utilities usually do not) - see for example pve-storage commit > > 609f117ff24d2cff6b155e1d4b1175ceebe5bd7b > > > > or more recently the report in our community-forum: > > https://forum.proxmox.com/threads/cannot-clone-vm-or-move-disk-with-more-than-13-snapshots.89628/ > > (the magic number of 13 snapshots is the point where the output of > > `qemu-img info --output=json` grows to more than 4k) > > > > Given the doubtful security benefit of having to untaint output, only > > if it does not end in new-line or if it is longer than 4k (we read > > the output in 4k chunks) simply untaint the output unconditionally. > > > > Tested with the reproducer from the forum-thread > > > > this long message nowhere talks about what the actual issue is, can we rather > fix that in the clone call? You're right - sorry- the call chain leading to the error is move_vm_disk (PVE::API2::Qemu) -> PVE::QemuServer::clone_disk -> PVE::Storage::volume_size_info -> PVE::Storage::Plugin::volume_size_info (since it's a qcow2 image on a directory storage) -> file_size_info, which calls qemu-img info via run_command. The return of file_size_info is then used for PVE::Storage::vdisk_alloc -> PVE::Storage::Plugin::alloc_image -> qemu-img create via run_command. I had a patch for untainting the individual values in PVE::Storage::Plugin::volume_size_info but then went with this patch, since I expect the issue of output not ending in newline or being longer than 4k to linger in a few places in our code. For the volume_size_info calls of our storage plugins - a quick check says only PBSPlugin.pm and Plugin.pm could cause this issue (LVMPlugin returns a single value terminated with newline, RBDPlugin untaints the complete json before decode_json, ZFSPoolPlugin and ISCSIDirectPlugin untaint the return as well). > > > Signed-off-by: Stoiko Ivanov > > --- > > Huge thanks to Dominik who pointed me in the right direction, after I > > spend far more time than I'm proud to admit in the JSON::XS source, > > perlsec(1), perlguts(1) and the surprisingly unhelpful output of > > debugperl -Du > > > > src/PVE/Tools.pm | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm > > index 8946e93..eb140ae 100644 > > --- a/src/PVE/Tools.pm > > +++ b/src/PVE/Tools.pm > > @@ -516,7 +516,7 @@ sub run_command { > > &$outfunc($line) if $outfunc; > > &$logfunc($line) if $logfunc; > > } > > - $outlog .= $buf; > > + ($outlog) .= ($buf =~ /(.*)/); #untaint > > }; > > my $err = $@; > > if ($err) { > > @@ -537,7 +537,7 @@ sub run_command { > > &$errfunc($line) if $errfunc; > > &$logfunc($line) if $logfunc; > > } > > - $errlog .= $buf; > > + ($errlog) .= ($buf =~ /(.*)/); #untaint > > }; > > my $err = $@; > > if ($err) { > > >