From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 865071FF164
	for <inbox@lore.proxmox.com>; Wed, 25 Sep 2024 13:39:59 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 5F06E1F1A8;
	Wed, 25 Sep 2024 13:40:14 +0200 (CEST)
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 25 Sep 2024 13:39:30 +0200
Message-Id: <20240925113930.92754-2-d.kral@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20240925113930.92754-1-d.kral@proxmox.com>
References: <20240925113930.92754-1-d.kral@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.003 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 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. [network.pm]
Subject: [pve-devel] [PATCH common 2/2] net: add name checks when creating
 bridge and veth interfaces
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>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Adds checks when creating interfaces with `veth_create`, which is used
when creating the veth interface for Linux firewall bridges, and
`iface_create`, which is used when creating Linux / OVS firewall bridges
and VLAN bridges.

There are no functional changes in `veth_create` except the added check.

Without these checks, the following cases:

- When creating more than 10 Linux firewall bridges on a VM with 9
  digits, e.g. 'fwbr999999999i10' is too long for an interface name
- When creating a VLAN bridge on a bridge that has already a long name,
  e.g. the bridge 'abcdefghjklm' will try to create 'abcdefghijklmv249'

will fail with a rather unhelpful error message from the kernel:

> Error: Attribute failed policy validation.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
This change was not part of the initial bug report #5454, which is why I
split it up. It is in no part essential for patch #1, but rather to add
preliminary checks at other places where similar errors could happen.

 src/PVE/Network.pm | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/PVE/Network.pm b/src/PVE/Network.pm
index dd627f2..cde7949 100644
--- a/src/PVE/Network.pm
+++ b/src/PVE/Network.pm
@@ -190,6 +190,10 @@ sub iface_delete :prototype($) {
 
 sub iface_create :prototype($$@) {
     my ($iface, $type, @args) = @_;
+
+    eval { check_iface_name($iface) };
+    die "failed to create interface '$iface' - $@" if $@;
+
     run_command(['/sbin/ip', 'link', 'add', $iface, 'type', $type, @args], noerr => 1)
 	== 0 or die "failed to create interface '$iface'\n";
     return;
@@ -376,17 +380,21 @@ sub veth_create {
 
     # create veth pair
     if (! -d "/sys/class/net/$veth") {
-	my $cmd = ['/sbin/ip', 'link', 'add'];
-	# veth device + MTU
-	push @$cmd, 'name', $veth;
-	push @$cmd, 'mtu', $bridgemtu;
-	push @$cmd, 'type', 'veth';
-	# peer device + MTU
-	push @$cmd, 'peer', 'name', $vethpeer, 'mtu', $bridgemtu;
+	eval {
+	    check_iface_name($veth);
 
-	push @$cmd, 'addr', $mac if $mac;
+	    my $cmd = ['/sbin/ip', 'link', 'add'];
+	    # veth device + MTU
+	    push @$cmd, 'name', $veth;
+	    push @$cmd, 'mtu', $bridgemtu;
+	    push @$cmd, 'type', 'veth';
+	    # peer device + MTU
+	    push @$cmd, 'peer', 'name', $vethpeer, 'mtu', $bridgemtu;
 
-	eval { run_command($cmd) };
+	    push @$cmd, 'addr', $mac if $mac;
+
+	    run_command($cmd);
+	};
 	die "can't create interface $veth - $@\n" if $@;
     }
 
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel