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 6C3E61FF0E3 for ; Tue, 21 Jul 2026 15:54:22 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 855F621502; Tue, 21 Jul 2026 15:54:11 +0200 (CEST) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH pve-firewall 05/13] fix #5759: firewall: do not remove chains when host is shutting down Date: Tue, 21 Jul 2026 15:53:59 +0200 Message-ID: <20260721135407.372150-6-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260721135407.372150-1-a.bied-charreton@proxmox.com> References: <20260721135407.372150-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 2 DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Message-ID-Hash: LJKIIJEGGQVLBKMFBM6GLFCHMD47JWLN X-Message-ID-Hash: LJKIIJEGGQVLBKMFBM6GLFCHMD47JWLN X-MailFrom: abied-charreton@jett.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: The assumption until now was that the firewall rules should always be cleared when the daemon is shutting down. This is correct when the shutdown happens as the result of `systemctl stop`, should however not be handled the same way in case of a system shutdown. Because of the way pve-firewall is ordered, it comes down before the network does. Clearing the rules in the host shutdown case creates a window where the network is up without firewall protection. When shutting down, check the operational state of the system and only remove the chains if the system is _not_ currently shutting down. Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=5759 Signed-off-by: Arthur Bied-Charreton --- src/PVE/Service/pve_firewall.pm | 40 +++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/PVE/Service/pve_firewall.pm b/src/PVE/Service/pve_firewall.pm index 9c64442..2fe68cc 100755 --- a/src/PVE/Service/pve_firewall.pm +++ b/src/PVE/Service/pve_firewall.pm @@ -41,6 +41,29 @@ my $updatetime = 10; my $initial_memory_usage; +=head3 is_host_shutdown() + +Query C, returning C<1> if the system's running state is C, +C<0> otherwise. + +Note that C<1> is also returned if the running state of the system could not be determined, in order +to fail closed. + +=cut + +sub is_host_shutdown { + my $state = undef; + + PVE::Tools::run_command( + ['systemctl', 'is-system-running'], + outfunc => sub { $state = PVE::Tools::trim(shift) }, + noerr => 1, + ); + + return 1 if !defined($state) || $state eq ''; + return $state eq 'stopping'; +} + sub shutdown { my ($self) = @_; @@ -49,13 +72,16 @@ sub shutdown { # wait for children 1 while (waitpid(-1, POSIX::WNOHANG()) > 0); - syslog('info', "clear PVE-generated firewall rules"); - - eval { - PVE::Firewall::remove_pvefw_chains(); - PVE::Firewall::delete_dumps(); - }; - warn $@ if $@; + if (is_host_shutdown()) { + syslog('info', "system is stopping, not removing firewall rules\n"); + } else { + syslog('info', "clear PVE-generated firewall rules"); + eval { + PVE::Firewall::remove_pvefw_chains(); + PVE::Firewall::delete_dumps(); + }; + warn $@ if $@; + } $self->exit_daemon(0); } -- 2.47.3