all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
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	[thread overview]
Message-ID: <20261103121014.169908-1-a.bied-charreton@proxmox.com> (raw)

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 <a.bied-charreton@proxmox.com>
---
 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)(/(?<prefix>\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)(/(?<prefix>\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





             reply	other threads:[~2026-11-03 12:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 12:10 Arthur Bied-Charreton [this message]
2026-11-03 14:47 ` applied: [PATCH pve-firewall] fix #8261: config parser: check prefix length without Net::IP 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=20261103121014.169908-1-a.bied-charreton@proxmox.com \
    --to=a.bied-charreton@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