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

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