From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.ivanov@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) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 304AC6102C
 for <pve-devel@lists.proxmox.com>; Mon, 12 Oct 2020 17:35:50 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 1A868273AB
 for <pve-devel@lists.proxmox.com>; Mon, 12 Oct 2020 17:35:20 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (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 82956273A2
 for <pve-devel@lists.proxmox.com>; Mon, 12 Oct 2020 17:35:19 +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 4DBD4458F3
 for <pve-devel@lists.proxmox.com>; Mon, 12 Oct 2020 17:35:19 +0200 (CEST)
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Mon, 12 Oct 2020 17:34:57 +0200
Message-Id: <20201012153458.18685-2-s.ivanov@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20201012153458.18685-1-s.ivanov@proxmox.com>
References: <20201012153458.18685-1-s.ivanov@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.049 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH storage 1/2] LIO: untaint values read from
 remote config
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: Mon, 12 Oct 2020 15:35:50 -0000

The LIO backend for ZFS over iSCSI fetches the json-config periodically from
the target.
This patch reduces the stored config values to those which are actually used
and additonally untaints the values read from the remote host's config-file.

Since the LUN index is used in calls to targetcli on the remote host (via
run_command), untainting prevents the call to crash when run with '-T'.

Tested by creating a zfs over iscsi backed VM, starting it, adding disks,
resizing disks, removing disks, creating snapshots, rolling back to a snapshot.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 PVE/Storage/LunCmd/LIO.pm | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/PVE/Storage/LunCmd/LIO.pm b/PVE/Storage/LunCmd/LIO.pm
index 15ddabf..f9e7143 100644
--- a/PVE/Storage/LunCmd/LIO.pm
+++ b/PVE/Storage/LunCmd/LIO.pm
@@ -154,8 +154,22 @@ my $parser = sub {
 	# find correct TPG
 	foreach my $tpg (@{$target->{tpgs}}) {
 	    if ($tpg->{tag} == $tpg_tag) {
+		my $res = [];
+		foreach my $lun (@{$tpg->{luns}}) {
+		    my ($idx, $storage_object);
+		    if ($lun->{index} =~ /^(\d+)$/) {
+			$idx = $1;
+		    }
+		    if ($lun->{storage_object} =~ m|^($BACKSTORE/.*)$|) {
+			$storage_object = $1;
+		    }
+		    die "Invalid lun definition in config!\n"
+			if !(defined($idx) && defined($storage_object));
+		    push @$res, { index => $idx, storage_object => $storage_object };
+		}
+
 		my $id = "$scfg->{portal}.$scfg->{target}";
-		$SETTINGS->{$id} = $tpg;
+		$SETTINGS->{$id}->{luns} = $res;
 		$haveTarget = 1;
 		last;
 	    }
-- 
2.20.1