Blame SOURCES/0003-nftables-fix-panic-mode-not-filtering-output-packets.patch

c8bceb
From 1bb4312264f71a91c9afd22bf2b9c1fdbd00dc7a Mon Sep 17 00:00:00 2001
c8bceb
From: Eric Garver <e@erig.me>
c8bceb
Date: Mon, 3 Dec 2018 12:40:41 -0500
c8bceb
Subject: [PATCH 03/23] nftables: fix panic mode not filtering output packets
c8bceb
c8bceb
This simplifies policy in the nftables backend by filtering only on the
c8bceb
prerouting and output hooks. The others hooks are unnecessary since
c8bceb
we're using a higher precedence.
c8bceb
c8bceb
Also fixes an issue when re-enabling panic mode multiple times. Due to
c8bceb
rule de-duplication the policy drop rule was not being re-added.
c8bceb
c8bceb
Fixes: rhbz 1579740
c8bceb
Fixes: a0f683dfef2c ("nftables: fix policy")
c8bceb
(cherry picked from commit 2f5608b4897ff99afbb1c2425a94df035031c1a2)
c8bceb
---
c8bceb
 src/firewall/core/nftables.py | 36 +++++++++--------------------------
c8bceb
 1 file changed, 9 insertions(+), 27 deletions(-)
c8bceb
c8bceb
diff --git a/src/firewall/core/nftables.py b/src/firewall/core/nftables.py
c8bceb
index 69236a9600c2..44cd4f9e1752 100644
c8bceb
--- a/src/firewall/core/nftables.py
c8bceb
+++ b/src/firewall/core/nftables.py
c8bceb
@@ -314,38 +314,20 @@ class nftables(object):
c8bceb
         # packets while initially starting and for panic mode. As such, using
c8bceb
         # hooks with a higher priority than our base chains is sufficient.
c8bceb
         #
c8bceb
-        table_chains = []
c8bceb
-        for table in list(IPTABLES_TO_NFT_HOOK.keys()):
c8bceb
-            for chain in IPTABLES_TO_NFT_HOOK[table]:
c8bceb
-                table_chains.append((table, chain))
c8bceb
-
c8bceb
         table_name = TABLE_NAME + "_" + "policy_drop"
c8bceb
 
c8bceb
-        def _policy_drop_helper(table, chain, family, rules):
c8bceb
-            _chain = "%s_%s" % (table, chain)
c8bceb
-            _hook = IPTABLES_TO_NFT_HOOK[table][chain][0]
c8bceb
-            # add hooks with priority -1, only contain drop rule
c8bceb
-            _priority = IPTABLES_TO_NFT_HOOK[table][chain][1] - 1
c8bceb
-            _add_chain = "add chain %s %s %s '{ type filter hook %s priority %d ; }'" % \
c8bceb
-                         (family, table_name, _chain, _hook, _priority)
c8bceb
-            rules.append(splitArgs(_add_chain))
c8bceb
-            rules.append(["add", "rule", family, table_name, _chain, "drop"])
c8bceb
-
c8bceb
         rules = []
c8bceb
         if policy == "DROP":
c8bceb
-            for family in ["inet", "ip", "ip6"]:
c8bceb
-                rules.append(["add", "table", family, table_name])
c8bceb
-
c8bceb
-            for table,chain in table_chains:
c8bceb
-                if table == "nat":
c8bceb
-                    # nat requires two families
c8bceb
-                    for family in ["ip", "ip6"]:
c8bceb
-                        _policy_drop_helper(table, chain, family, rules)
c8bceb
-                else:
c8bceb
-                    _policy_drop_helper(table, chain, "inet", rules)
c8bceb
+            rules.append(["add", "table", "inet", table_name])
c8bceb
+
c8bceb
+            # To drop everything we need to use the "raw" priority. These occur
c8bceb
+            # before conntrack, mangle, nat, etc
c8bceb
+            for hook in ["prerouting", "output"]:
c8bceb
+                _add_chain = "add chain inet %s %s_%s '{ type filter hook %s priority %d ; policy drop ; }'" % \
c8bceb
+                             (table_name, "raw", hook, hook, -300 + NFT_HOOK_OFFSET - 1)
c8bceb
+                rules.append(splitArgs(_add_chain))
c8bceb
         elif policy == "ACCEPT":
c8bceb
-            for family in ["inet", "ip", "ip6"]:
c8bceb
-                rules.append(["delete", "table", family, table_name])
c8bceb
+            rules.append(["delete", "table", "inet", table_name])
c8bceb
         else:
c8bceb
             FirewallError(UNKNOWN_ERROR, "not implemented")
c8bceb
 
c8bceb
-- 
c8bceb
2.20.1
c8bceb