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 D031C1FF0A3 for ; Thu, 01 Oct 2026 14:26:59 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A73B621734; Thu, 01 Oct 2026 14:26:45 +0200 (CEST) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH pve-firewall v2 04/12] fix #5759: firewall: do not remove chains when host is shutting down Date: Thu, 1 Oct 2026 14:26:17 +0200 Message-ID: <20261001122625.348730-5-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261001122625.348730-1-a.bied-charreton@proxmox.com> References: <20261001122625.348730-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1790857599809 X-SPAM-LEVEL: Spam detection results: 0 AWL 1.247 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: 5YI2YKPDVCP2K3LVTVWWZZDWCAQMFHEY X-Message-ID-Hash: 5YI2YKPDVCP2K3LVTVWWZZDWCAQMFHEY 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: 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. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=5759 Signed-off-by: Arthur Bied-Charreton Reviewed-by: Thomas Ellmenreich Tested-by: Thomas Ellmenreich --- 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 f9fa1dd..b39fea7 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_if_owned(); - }; - 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_if_owned(); + }; + warn $@ if $@; + } $self->exit_daemon(0); } -- 2.47.3