all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common 1/2] fix #5454: net: check names for vlan bridge slave interfaces
Date: Wed, 25 Sep 2024 13:39:29 +0200	[thread overview]
Message-ID: <20240925113930.92754-1-d.kral@proxmox.com> (raw)

Adds a check for the name of VLAN bridge slave interfaces, which are
created on non VLAN-aware bridges. These checks mimics what is done when
parsing an interface name in iproute2 [0], which includes a name size
check, an empty string check and checking for invalid characters.

Without this check, creating a VLAN bridge slave interface, where the
length of the string "<iface>.<vlanid>" will be greater than or equal to
16 characters, resulted in the following error message from `ip` itself:

> Error: argument "<iface>.<vlanid>" is wrong: "name" not a valid ifname

[0] https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/lib/utils.c?h=v6.1.0#n825

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
 src/PVE/Network.pm | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/PVE/Network.pm b/src/PVE/Network.pm
index a4f5ba9..dd627f2 100644
--- a/src/PVE/Network.pm
+++ b/src/PVE/Network.pm
@@ -165,6 +165,22 @@ my $compute_fwbr_names = sub {
     return ($fwbr, $vethfw, $vethfwpeer, $ovsintport);
 };
 
+sub check_iface_name : prototype($) {
+    my ($name) = @_;
+
+    my $name_len = length($name);
+
+    # iproute2 / kernel have a strict interface name size limit
+    die "the interface name $name is too long"
+	if $name_len >= PVE::ProcFSTools::IFNAMSIZ;
+
+    # iproute2 checks with isspace(3), which includes vertical tabs (not catched with perl's '\s')
+    die "the interface name $name is empty or contains invalid characters"
+	if $name_len == 0 || $name =~ /\s|\v|\//;
+
+    return 1;
+}
+
 sub iface_delete :prototype($) {
     my ($iface) = @_;
     run_command(['/sbin/ip', 'link', 'delete', 'dev', $iface], noerr => 1)
@@ -561,6 +577,8 @@ sub activate_bridge_vlan_slave {
     # create vlan on $iface is not already exist
     if (! -d "/sys/class/net/$ifacevlan") {
 	eval {
+	    check_iface_name($ifacevlan);
+
 	    my $cmd = ['/sbin/ip', 'link', 'add'];
 	    push @$cmd, 'link', $iface;
 	    push @$cmd, 'name', $ifacevlan;
-- 
2.39.5



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


             reply	other threads:[~2024-09-25 11:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-25 11:39 Daniel Kral [this message]
2024-09-25 11:39 ` [pve-devel] [PATCH common 2/2] net: add name checks when creating bridge and veth interfaces Daniel Kral
2024-11-11 18:36 ` [pve-devel] applied: [PATCH common 1/2] fix #5454: net: check names for vlan bridge slave interfaces Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240925113930.92754-1-d.kral@proxmox.com \
    --to=d.kral@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal