From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
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 [thread overview]
Message-ID: <20260721135407.372150-6-a.bied-charreton@proxmox.com> (raw)
In-Reply-To: <20260721135407.372150-1-a.bied-charreton@proxmox.com>
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 <a.bied-charreton@proxmox.com>
---
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<systemctl is-system-running>, returning C<1> if the system's running state is C<stopping>,
+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
next prev parent reply other threads:[~2026-07-21 13:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 13:53 [RFC firewall/manager/proxmox{,-firewall} 00/13] fix #5759: keep firewall rules up across boot and shutdown Arthur Bied-Charreton
2026-07-21 13:53 ` [PATCH pve-manager 01/13] network interface pinning: write new firewall config to local dir Arthur Bied-Charreton
2026-07-21 13:53 ` [PATCH pve-firewall 02/13] firewall: config: sort OPTIONS when serializing Arthur Bied-Charreton
2026-07-21 13:53 ` [PATCH pve-firewall 03/13] d/control: bump libpve-common-perl Arthur Bied-Charreton
2026-07-21 13:53 ` [PATCH pve-firewall 04/13] firewall: dump configs locally after applying Arthur Bied-Charreton
2026-07-21 13:53 ` Arthur Bied-Charreton [this message]
2026-07-21 13:54 ` [PATCH pve-firewall 06/13] firewall: add restore command Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH pve-firewall 07/13] fix #5759: firewall: restore from dumped config before network-pre Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox 08/13] systemd: systemctl: add is-system-running helper Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 09/13] firewall: fix clippy warnings Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 10/13] fix #5759: firewall: do not clear rules on system shutdown Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 11/13] firewall: dump config to local directory after apply Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 12/13] firewall: add restore command Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 13/13] fix #5759: firewall: restore from dumped config before network-pre Arthur Bied-Charreton
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=20260721135407.372150-6-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.