Bug 2061942

Summary: Prevent port-shadow attacks in sample nat config
Product: Red Hat Enterprise Linux 8 Reporter: Phil Sutter <psutter>
Component: nftablesAssignee: Phil Sutter <psutter>
Status: CLOSED CURRENTRELEASE QA Contact: Tomas Dolezal <todoleza>
Severity: unspecified Docs Contact: Marc Muehlfeld <mmuehlfe>
Priority: unspecified    
Version: 8.7CC: extras-qa, jpeska, kevin, psutter, qe-baseos-daemons, todoleza
Target Milestone: rcKeywords: TestOnly, Triaged
Target Release: 8.8Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: nftables-1.0.4-2.el8 Doc Type: Enhancement
Doc Text:
.Security improvement of the default `nftables` service configuration This enhancement adds the `do_masquerade` chain to the default `nftables` service configuration in the `/etc/sysconfig/nftables/nat.nft` file. This reduces the risk of a port shadow attack, which is described in link:https://access.redhat.com/security/cve/CVE-2021-3773[CVE-2021-3773]. The first rule in the `do_masquerade` chain detects suitable packets and enforces source port randomization to reduce the risk of port shadow attacks.
Story Points: ---
Clone Of: 2061940 Environment:
Last Closed: 2023-09-08 07:28:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2061917, 2061940, 2211076    
Bug Blocks:    

Description Phil Sutter 2022-03-08 18:30:12 UTC
+++ This bug was initially created as a clone of Bug #2061940 +++

+++ This bug was initially created as a clone of Bug #2061917 +++

The respective kernel commit is about to be reverted as it might break a corner-case:

https://lore.kernel.org/netfilter-devel/20220308125924.6708-1-fw@strlen.de/

Deploy an equivalent mitigation in user space so at least new setups are fine once the revert reaches distribution kernels:

@@ -18,13 +18,21 @@ table ip nftables_svc {
                elements = { 192.168.122.0/24 }
        }
 
+       # force port randomization for non-locally originated connections using
+       # suspicious port values to prevent port-shadow attacks, i.e.
+       # accidental matching of new inbound connections vs. existing ones
+       chain do_masquerade {
+               meta iif > 0 th sport < 16384 th dport >= 32768 masquerade random
+               masquerade
+       }
+
        # base-chain to manipulate conntrack in postrouting,
        # will see packets for new or related traffic only
        chain POSTROUTING {
                type nat hook postrouting priority srcnat + 20
                policy accept
 
-               iifname @masq_interfaces oifname != @masq_interfaces masquerade
-               ip saddr @masq_ips masquerade
+               iifname @masq_interfaces oifname != @masq_interfaces jump do_masquerade
+               ip saddr @masq_ips jump do_masquerade
        }
 }

--- Additional comment from Phil Sutter on 2022-03-08 18:22:30 UTC ---

For reference, this is about CVE-2021-3773:

https://access.redhat.com/security/cve/CVE-2021-3773
https://www.openwall.com/lists/oss-security/2021/09/08/3
https://breakpointingbad.com/2021/09/08/Port-Shadows-via-Network-Alchemy.html

Comment 1 Phil Sutter 2022-08-31 17:02:52 UTC
Missed RHEL8.7, proposing for RHEL8.8.

Comment 2 Phil Sutter 2023-02-22 08:55:39 UTC
Missed RHEL8.8, proposing for RHEL8.9.

Comment 4 Phil Sutter 2023-08-24 11:53:13 UTC
Required sample config changes inherited from package rebase, marking as TestOnly.

Comment 5 RHEL Program Management 2023-09-08 07:28:40 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.

Comment 6 Phil Sutter 2023-09-08 16:56:26 UTC
Fixing closed reason to reflect that the change is there.

Marc, will this be picked up if I fill out the doc text? I don't think testing is really necessary (given that it's just about a default config), but it would be nice to document the improvements.

Comment 7 Marc Muehlfeld 2023-09-11 06:14:27 UTC
Yes. If this ticket needs a release note, please set the Doc Type, enter the relevant information in the Doc Text field, and I'll prepare a RN.

Comment 9 Phil Sutter 2023-09-19 11:37:02 UTC
Hi Marc,

The sentence "This reduces the risk of port shadow attacks." is kind of redundant given the following text. Maybe use it to define the attack and write it as "This reduces the risk of a port shadow attack as per CVE-2021-3773." and maybe link to the Access page: https://access.redhat.com/security/cve/CVE-2021-3773