From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 298D81FF0BC for ; Thu, 15 Oct 2026 14:45:47 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 9E002214CD; Thu, 15 Oct 2026 14:45:37 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [PATCH pve-firewall v2 04/12] fix #5759: firewall: do not remove chains when host is shutting down From: Stefan Hanreich To: Arthur Bied-Charreton In-Reply-To: <20261001122625.348730-5-a.bied-charreton@proxmox.com> References: <20261001122625.348730-1-a.bied-charreton@proxmox.com> <20261001122625.348730-5-a.bied-charreton@proxmox.com> Date: Thu, 15 Oct 2026 14:45:23 +0200 Message-Id: <179206832307.200960.16160107779714540627.b4-review@b4> X-Mailer: b4 0.16-dev-fbf84 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1792068331135 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.511 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: ISKGOWPKHWQE2PZ7XTDQF67CBNBULI7M X-Message-ID-Hash: ISKGOWPKHWQE2PZ7XTDQF67CBNBULI7M X-MailFrom: s.hanreich@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 CC: pve-devel@lists.proxmox.com 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 > > 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, > + ); While it is an alias, I think newer code should use the dedicated Cmd module. Using eval instead of noerr should catch any general errors with run_command and allow handling them instead of relying on $state. It'd also give a better indication of *why* this failed and we can log it. -- Stefan Hanreich