From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id A5F481FF17E for ; Thu, 13 Nov 2025 14:50:21 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 322DE1D062; Thu, 13 Nov 2025 14:51:06 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Thu, 13 Nov 2025 14:49:50 +0100 Message-ID: <20251113135023.1038305-3-c.heiss@proxmox.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251113135023.1038305-1-c.heiss@proxmox.com> References: <20251113135023.1038305-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1763041805637 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.047 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 Subject: [pve-devel] [PATCH installer 2/6] common: pinning: make interface name checks stricter 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" According to our `pve-iface` schema, names must be at least two characters long and start with a (latin) letter. Reported-by: Stoiko Ivanov Signed-off-by: Christoph Heiss --- proxmox-installer-common/src/lib.rs | 7 ++-- proxmox-installer-common/src/options.rs | 46 ++++++++++++++++++++----- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/proxmox-installer-common/src/lib.rs b/proxmox-installer-common/src/lib.rs index a85d5f8..b380f1c 100644 --- a/proxmox-installer-common/src/lib.rs +++ b/proxmox-installer-common/src/lib.rs @@ -11,8 +11,11 @@ pub mod http; pub mod cli; pub mod net { - /// Maximum length of the (primary) name of a network interface - pub const MAX_IFNAME_LEN: usize = 15; // IFNAMSIZ - 1 to account for NUL byte + /// As dictated by the `pve-iface` schema. + pub const MIN_IFNAME_LEN: usize = 2; + /// Maximum length of the (primary) name of a network interface. + /// IFNAMSIZ - 1 to account for NUL byte + pub const MAX_IFNAME_LEN: usize = 15; } pub const RUNTIME_DIR: &str = "/run/proxmox-installer"; diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs index 0d72f54..a07fe58 100644 --- a/proxmox-installer-common/src/options.rs +++ b/proxmox-installer-common/src/options.rs @@ -8,7 +8,7 @@ use std::sync::OnceLock; use std::{cmp, fmt}; use crate::disk_checks::check_raid_min_disks; -use crate::net::MAX_IFNAME_LEN; +use crate::net::{MAX_IFNAME_LEN, MIN_IFNAME_LEN}; use crate::setup::{LocaleInfo, NetworkInfo, RuntimeInfo, SetupInfo}; use crate::utils::{CidrAddress, Fqdn}; @@ -504,8 +504,10 @@ impl NetworkInterfacePinningOptions { pub fn verify(&self) -> Result<()> { let mut reverse_mapping = HashMap::::new(); for (mac, name) in self.mapping.iter() { - if name.is_empty() { - bail!("interface name for '{mac}' cannot be empty"); + if name.len() < MIN_IFNAME_LEN { + bail!( + "interface name for '{mac}' must be at least {MIN_IFNAME_LEN} characters long" + ); } if name.len() > MAX_IFNAME_LEN { @@ -522,9 +524,9 @@ impl NetworkInterfacePinningOptions { } // Mimicking the `pve-iface` schema verification - if name.starts_with(|c: char| c.is_ascii_digit()) { + if !name.starts_with(|c: char| c.is_ascii_alphabetic()) { bail!( - "interface name '{name}' for '{mac}' is invalid: name must not start with a number" + "interface name '{name}' for '{mac}' is invalid: name must start with a letter" ); } @@ -943,7 +945,22 @@ mod tests { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "interface name for 'ab:cd:ef:12:34:56' cannot be empty" + "interface name for 'ab:cd:ef:12:34:56' must be at least 2 characters long" + ) + } + + #[test] + fn network_interface_pinning_options_fail_on_too_short_name() { + let mut options = NetworkInterfacePinningOptions::default(); + options + .mapping + .insert("ab:cd:ef:12:34:56".to_owned(), "a".to_owned()); + + let res = options.verify(); + assert!(res.is_err()); + assert_eq!( + res.unwrap_err().to_string(), + "interface name for 'ab:cd:ef:12:34:56' must be at least 2 characters long" ) } @@ -1000,7 +1017,7 @@ mod tests { } #[test] - fn network_interface_pinning_options_fail_on_name_starting_with_number() { + fn network_interface_pinning_options_fail_on_nonletter_first_char() { let mut options = NetworkInterfacePinningOptions::default(); options .mapping @@ -1010,8 +1027,19 @@ mod tests { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "interface name '0nic' for 'ab:cd:ef:12:34:56' is invalid: name must not start with a number" - ) + "interface name '0nic' for 'ab:cd:ef:12:34:56' is invalid: name must start with a letter" + ); + + options + .mapping + .insert("ab:cd:ef:12:34:56".to_owned(), "_a".to_owned()); + + let res = options.verify(); + assert!(res.is_err()); + assert_eq!( + res.unwrap_err().to_string(), + "interface name '_a' for 'ab:cd:ef:12:34:56' is invalid: name must start with a letter" + ); } #[test] -- 2.51.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel