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 9D7EB1FF066 for ; Tue, 24 Nov 2026 18:57:56 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id D44A12170B; Tue, 24 Nov 2026 18:57:31 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH pve-firewall 6/7] firewall: drop the traffic of guest network devices without MAC address Date: Tue, 24 Nov 2026 18:57:16 +0100 Message-ID: <20261124175718.512428-7-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261124175718.512428-1-s.hanreich@proxmox.com> References: <20261124175718.512428-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795543046957 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.177 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: 4DGHEMRKK4637ZRU5I4QYWI6A2RJMM2Z X-Message-ID-Hash: 4DGHEMRKK4637ZRU5I4QYWI6A2RJMM2Z 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 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: A guest network device can lack a MAC address, for example after a manual edit of the config. qemu-server and pve-container then use a random one, which the firewall cannot know. With the MAC filter enabled, drop all traffic of such a device, as the MAC filter drops the traffic from any MAC address that is not the one of the device. So far, the rule was skipped without a MAC address. Likewise, leave the link-local address out of the default IP filter, which then drops traffic from link-local addresses of the device. This changes nothing yet, as the parsers of the guest configs always generate a MAC address so far. Signed-off-by: Stefan Hanreich --- src/PVE/Firewall.pm | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm index 93af383..053b289 100644 --- a/src/PVE/Firewall.pm +++ b/src/PVE/Firewall.pm @@ -2839,8 +2839,9 @@ sub ruleset_create_vm_chain { } if ($direction eq 'OUT') { - if (defined($macaddr) && !(defined($options->{macfilter}) && $options->{macfilter} == 0)) { - ruleset_addrule($ruleset, $chain, "-m mac ! --mac-source $macaddr", "-j DROP"); + if (!(defined($options->{macfilter}) && $options->{macfilter} == 0)) { + my $match = defined($macaddr) ? "-m mac ! --mac-source $macaddr" : ''; + ruleset_addrule($ruleset, $chain, $match, "-j DROP"); } if ($ipversion == 6 && !$options->{radv}) { ruleset_addrule( @@ -4817,10 +4818,9 @@ sub compile_ipsets { } my $macaddr = $net->{macaddr}; - my $linklocal = mac_to_linklocal($macaddr); - $device_ips->{$netid} = [ - { cidr => $linklocal }, { cidr => 'fe80::/10', nomatch => 1 }, - ]; + my $set = $device_ips->{$netid} = [{ cidr => 'fe80::/10', nomatch => 1 }]; + # without a MAC address, the filter drops traffic from link-local addresses + push @$set, { cidr => mac_to_linklocal($macaddr) } if defined($macaddr); } generate_ipset_chains( @@ -4871,10 +4871,9 @@ sub compile_ipsets { } my $macaddr = $net->{hwaddr}; - my $linklocal = mac_to_linklocal($macaddr); - my $set = $device_ips->{$netid} = [ - { cidr => $linklocal }, { cidr => 'fe80::/10', nomatch => 1 }, - ]; + my $set = $device_ips->{$netid} = [{ cidr => 'fe80::/10', nomatch => 1 }]; + # without a MAC address, the filter drops traffic from link-local addresses + push @$set, { cidr => mac_to_linklocal($macaddr) } if defined($macaddr); if (defined($net->{ip}) && $net->{ip} =~ m!^($IPV4RE)(?:/\d+)?\z!) { my $address = $1; pve_verify_ip_or_cidr($net->{ip}); @@ -5042,14 +5041,17 @@ sub generate_tap_layer2filter { my $tapchain = $iface . "-OUT"; - # ebtables remove zeros from mac pairs - $macaddr =~ s/0([0-9a-f])/$1/ig; - $macaddr = lc($macaddr); - ruleset_create_chain($ruleset, $tapchain); - if (defined($macaddr) && !(defined($options->{macfilter}) && $options->{macfilter} == 0)) { - ruleset_addrule($ruleset, $tapchain, "-s ! $macaddr", '-j DROP'); + if (!(defined($options->{macfilter}) && $options->{macfilter} == 0)) { + if (defined($macaddr)) { + # ebtables remove zeros from mac pairs + $macaddr =~ s/0([0-9a-f])/$1/ig; + $macaddr = lc($macaddr); + ruleset_addrule($ruleset, $tapchain, "-s ! $macaddr", '-j DROP'); + } else { + ruleset_addrule($ruleset, $tapchain, '', '-j DROP'); + } } if (defined($arpfilter)) { -- 2.47.3