From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <t.lamprecht@proxmox.com>
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 30FC274D0C
 for <pve-devel@lists.proxmox.com>; Tue, 22 Jun 2021 16:42:04 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 206EA29AD2
 for <pve-devel@lists.proxmox.com>; Tue, 22 Jun 2021 16:42:04 +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 id 7049F29AC4
 for <pve-devel@lists.proxmox.com>; Tue, 22 Jun 2021 16:42:00 +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 3DD3C457EA
 for <pve-devel@lists.proxmox.com>; Tue, 22 Jun 2021 16:42:00 +0200 (CEST)
Message-ID: <5f4ba4d0-8092-0096-5b10-7f02d50fc865@proxmox.com>
Date: Tue, 22 Jun 2021 16:41:50 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:90.0) Gecko/20100101
 Thunderbird/90.0
Content-Language: en-US
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Stoiko Ivanov <s.ivanov@proxmox.com>
References: <20210622142824.18773-1-s.ivanov@proxmox.com>
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
In-Reply-To: <20210622142824.18773-1-s.ivanov@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.695 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
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 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, tools.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 <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 22 Jun 2021 14:42:04 -0000

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?

> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
> 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) {
>