Blame SOURCES/0052-fix-rich-icmptype-verify-rule-and-icmptype-families-.patch

00cd46
From 5c18dbc41a2f59364fb495ef164dcc3c9147e408 Mon Sep 17 00:00:00 2001
00cd46
From: Eric Garver <eric@garver.life>
00cd46
Date: Fri, 28 Aug 2020 11:44:33 -0400
00cd46
Subject: [PATCH 52/62] fix(rich icmptype): verify rule and icmptype families
00cd46
 don't conflict
00cd46
00cd46
Fixes: rhbz 1855140
00cd46
(cherry picked from commit 11aac7755d9c8e338f72b5350329255937efd8e8)
00cd46
(cherry picked from commit b49a88095b05bcf1bce36e989d7003948f1ee6f7)
00cd46
---
00cd46
 src/firewall/core/fw_zone.py |  6 ++++++
00cd46
 src/firewall/core/io/zone.py | 17 ++++++++++++++++-
00cd46
 2 files changed, 22 insertions(+), 1 deletion(-)
00cd46
00cd46
diff --git a/src/firewall/core/fw_zone.py b/src/firewall/core/fw_zone.py
00cd46
index bd026222dce5..129306b6f969 100644
00cd46
--- a/src/firewall/core/fw_zone.py
00cd46
+++ b/src/firewall/core/fw_zone.py
00cd46
@@ -1703,6 +1703,12 @@ class FirewallZone(object):
00cd46
                  type(rule.element) == Rich_IcmpType:
00cd46
                 ict = self._fw.config.get_icmptype(rule.element.name)
00cd46
 
00cd46
+                if rule.family and ict.destination and \
00cd46
+                   rule.family not in ict.destination:
00cd46
+                    raise FirewallError(errors.INVALID_ICMPTYPE,
00cd46
+                                        "rich rule family '%s' conflicts with icmp type '%s'" % \
00cd46
+                                        (rule.family, rule.element.name))
00cd46
+
00cd46
                 if type(rule.element) == Rich_IcmpBlock and \
00cd46
                    rule.action and type(rule.action) == Rich_Accept:
00cd46
                     # icmp block might have reject or drop action, but not accept
00cd46
diff --git a/src/firewall/core/io/zone.py b/src/firewall/core/io/zone.py
00cd46
index 68b2a7c9567c..529b92c25b62 100644
00cd46
--- a/src/firewall/core/io/zone.py
00cd46
+++ b/src/firewall/core/io/zone.py
00cd46
@@ -232,7 +232,22 @@ class Zone(IO_Object):
00cd46
                     raise FirewallError(errors.INVALID_ADDR, source)
00cd46
         elif item == "rules_str":
00cd46
             for rule in config:
00cd46
-                rich.Rich_Rule(rule_str=rule)
00cd46
+                obj_rich = rich.Rich_Rule(rule_str=rule)
00cd46
+                if self.fw_config and obj_rich.element and (isinstance(obj_rich.element, rich.Rich_IcmpBlock) or
00cd46
+                                                           isinstance(obj_rich.element, rich.Rich_IcmpType)):
00cd46
+                    existing_icmptypes = self.fw_config.get_icmptypes()
00cd46
+                    if obj_rich.element.name not in existing_icmptypes:
00cd46
+                        raise FirewallError(errors.INVALID_ICMPTYPE,
00cd46
+                                            "'%s' not among existing icmp types" % \
00cd46
+                                            obj_rich.element.name)
00cd46
+
00cd46
+                    elif obj_rich.family:
00cd46
+                        ict = self.fw_config.get_icmptype(obj_rich.element.name)
00cd46
+                        if ict.destination and obj_rich.family not in ict.destination:
00cd46
+                            raise FirewallError(errors.INVALID_ICMPTYPE,
00cd46
+                                                "rich rule family '%s' conflicts with icmp type '%s'" % \
00cd46
+                                                (obj_rich.family, obj_rich.element.name))
00cd46
+
00cd46
 
00cd46
     def check_name(self, name):
00cd46
         super(Zone, self).check_name(name)
00cd46
-- 
00cd46
2.28.0
00cd46