From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 6C75E1FF0AA for ; Tue, 03 Nov 2026 13:10:34 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id D41682177D; Tue, 03 Nov 2026 13:10:29 +0100 (CET) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH pve-firewall] fix #8261: config parser: check prefix length without Net::IP Date: Tue, 3 Nov 2026 13:10:14 +0100 Message-ID: <20261103121014.169908-1-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1793707821812 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.464 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) 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 Message-ID-Hash: GE3QMFD2WZ6CEWIZXXZRTGEXGORVE5VH X-Message-ID-Hash: GE3QMFD2WZ6CEWIZXXZRTGEXGORVE5VH X-MailFrom: a.bied-charreton@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 99343fe ("firewall: reject cidrs with invalid netmask") made parse_ip_or_cidr call pve_verify_ip_or_cidr. That function masks the host bits and constructs a Net::IP object for every alias and IPSet entry, which is very expensive. As noted in the linked bug, a cluster config with about 30k IPSet entries took 6 seconds to parse vs. 0.4 before this call was introduced. The address syntax is already checked by the IPV4RE and IPV6RE matches in parse_ip_or_cidr and the host bits are masked away before being passed to Net::IP in pve_verify_ip_or_cidr, so the only thing that call really added is the prefix length bound. Check that bound directly on the prefix instead. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=8261 Signed-off-by: Arthur Bied-Charreton --- src/PVE/Firewall.pm | 10 ++++++---- src/test/test_compile_ipsets.pl | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm index 20e0250..467815c 100644 --- a/src/PVE/Firewall.pm +++ b/src/PVE/Firewall.pm @@ -3584,12 +3584,14 @@ sub parse_ip_or_cidr { my $ipversion; - pve_verify_ip_or_cidr($cidr); - - if ($cidr =~ m!^(?:$IPV6RE)(/(\d+))?$!) { + if ($cidr =~ m!^(?:$IPV6RE)(/(?\d+))?$!) { + die "prefix length $+{prefix} is longer than IP address (128)\n" + if defined($+{prefix}) && $+{prefix} > 128; $cidr =~ s|/128$||; $ipversion = 6; - } elsif ($cidr =~ m!^(?:$IPV4RE)(/(\d+))?$!) { + } elsif ($cidr =~ m!^(?:$IPV4RE)(/(?\d+))?$!) { + die "prefix length $+{prefix} is longer than IP address (32)\n" + if defined($+{prefix}) && $+{prefix} > 32; $cidr =~ s|/32$||; $ipversion = 4; } else { diff --git a/src/test/test_compile_ipsets.pl b/src/test/test_compile_ipsets.pl index 593f5ee..4c7c446 100755 --- a/src/test/test_compile_ipsets.pl +++ b/src/test/test_compile_ipsets.pl @@ -9,11 +9,24 @@ use Test::More; use PVE::Firewall; -for my $cidr ('192.0.2.0/99', '2001:db8::/129') { +for my $cidr ('192.0.2.0/99', '10.0.0.0/33', '2001:db8::/129', '::/129') { eval { PVE::Firewall::parse_ip_or_cidr($cidr) }; ok($@, "reject invalid CIDR $cidr"); } +my $valid = { + '10.0.0.0/0' => ['10.0.0.0/0', 4], + '10.0.0.1/32' => ['10.0.0.1', 4], + '10.0.0.1/032' => ['10.0.0.1/032', 4], + '::/0' => ['::/0', 6], + '::1/128' => ['::1', 6], + '::1/0128' => ['::1/0128', 6], +}; +for my $cidr (sort keys $valid->%*) { + my @parsed = eval { PVE::Firewall::parse_ip_or_cidr($cidr) }; + is_deeply(\@parsed, $valid->{$cidr}, "accept CIDR $cidr"); +} + subtest 'container IP filters' => sub { plan skip_all => 'PVE::LXC::Config is not installed' if !eval { require PVE::LXC::Config; 1 }; -- 2.47.3