|
|
bb602c |
From 8c2a4bc33d0c60a9fb84f01f360c524c9f725e03 Mon Sep 17 00:00:00 2001
|
|
|
bb602c |
From: Eric Garver <eric@garver.life>
|
|
|
bb602c |
Date: Thu, 24 Oct 2019 12:47:36 -0400
|
|
|
bb602c |
Subject: [PATCH 116/122] fix: don't probe for available kernel modules
|
|
|
bb602c |
|
|
|
bb602c |
Trust what's specified by the helper definitions. This also completely
|
|
|
bb602c |
removes our dependency on modinfo. modinfo becomes very problematic if
|
|
|
bb602c |
the kernel modules are builtin.
|
|
|
bb602c |
|
|
|
bb602c |
Fixes: #517
|
|
|
bb602c |
Closes: #518
|
|
|
bb602c |
(cherry picked from commit adbf3476b7533ef3a2c002db62f76614a9f0f6c1)
|
|
|
bb602c |
(cherry picked from commit 7065561488166bbcb16cf8b9e8a2731b0c0379d8)
|
|
|
bb602c |
---
|
|
|
bb602c |
configure.ac | 1 -
|
|
|
bb602c |
src/firewall/config/__init__.py.in | 1 -
|
|
|
bb602c |
src/firewall/core/fw.py | 24 -----------
|
|
|
bb602c |
src/firewall/core/fw_zone.py | 40 +++++-------------
|
|
|
bb602c |
src/firewall/functions.py | 66 +-----------------------------
|
|
|
bb602c |
src/firewall/server/firewalld.py | 4 +-
|
|
|
bb602c |
6 files changed, 15 insertions(+), 121 deletions(-)
|
|
|
bb602c |
|
|
|
bb602c |
diff --git a/configure.ac b/configure.ac
|
|
|
bb602c |
index d1c365e29986..1f8f8dff07ae 100644
|
|
|
bb602c |
--- a/configure.ac
|
|
|
bb602c |
+++ b/configure.ac
|
|
|
bb602c |
@@ -30,7 +30,6 @@ AM_PATH_PYTHON
|
|
|
bb602c |
AC_PATH_PROG([XSLTPROC], [xsltproc])
|
|
|
bb602c |
AC_PATH_PROG([KILL], [kill], [/usr/bin/kill])
|
|
|
bb602c |
|
|
|
bb602c |
-AC_PATH_PROG([MODINFO], [modinfo], [/sbin/modinfo])
|
|
|
bb602c |
AC_PATH_PROG([MODPROBE], [modprobe], [/sbin/modprobe])
|
|
|
bb602c |
AC_PATH_PROG([RMMOD], [rmmod], [/sbin/rmmod])
|
|
|
bb602c |
AC_PATH_PROG([SYSCTL], [sysctl], [/sbin/sysctl])
|
|
|
bb602c |
diff --git a/src/firewall/config/__init__.py.in b/src/firewall/config/__init__.py.in
|
|
|
bb602c |
index 20e4979062d8..1b2168bde44d 100644
|
|
|
bb602c |
--- a/src/firewall/config/__init__.py.in
|
|
|
bb602c |
+++ b/src/firewall/config/__init__.py.in
|
|
|
bb602c |
@@ -110,7 +110,6 @@ COMMANDS = {
|
|
|
bb602c |
"eb": "@EBTABLES@",
|
|
|
bb602c |
"eb-restore": "@EBTABLES_RESTORE@",
|
|
|
bb602c |
"ipset": "@IPSET@",
|
|
|
bb602c |
- "modinfo": "@MODINFO@",
|
|
|
bb602c |
"modprobe": "@MODPROBE@",
|
|
|
bb602c |
"rmmod": "@RMMOD@",
|
|
|
bb602c |
"nft": "@NFT@",
|
|
|
bb602c |
diff --git a/src/firewall/core/fw.py b/src/firewall/core/fw.py
|
|
|
bb602c |
index 2c4325966a19..b1643a1ebff4 100644
|
|
|
bb602c |
--- a/src/firewall/core/fw.py
|
|
|
bb602c |
+++ b/src/firewall/core/fw.py
|
|
|
bb602c |
@@ -114,8 +114,6 @@ class Firewall(object):
|
|
|
bb602c |
self._automatic_helpers = config.FALLBACK_AUTOMATIC_HELPERS
|
|
|
bb602c |
self._firewall_backend = config.FALLBACK_FIREWALL_BACKEND
|
|
|
bb602c |
self.nf_conntrack_helper_setting = 0
|
|
|
bb602c |
- self.nf_conntrack_helpers = { }
|
|
|
bb602c |
- self.nf_nat_helpers = { }
|
|
|
bb602c |
|
|
|
bb602c |
def individual_calls(self):
|
|
|
bb602c |
return self._individual_calls
|
|
|
bb602c |
@@ -198,28 +196,6 @@ class Firewall(object):
|
|
|
bb602c |
log.debug1("ebtables-restore is not supporting the --noflush "
|
|
|
bb602c |
"option, will therefore not be used")
|
|
|
bb602c |
|
|
|
bb602c |
- if os.path.exists(config.COMMANDS["modinfo"]):
|
|
|
bb602c |
- self.nf_conntrack_helpers = functions.get_nf_conntrack_helpers()
|
|
|
bb602c |
- if len(self.nf_conntrack_helpers) > 0:
|
|
|
bb602c |
- log.debug1("Conntrack helpers supported by the kernel:")
|
|
|
bb602c |
- for key,values in self.nf_conntrack_helpers.items():
|
|
|
bb602c |
- log.debug1(" %s: %s", key, ", ".join(values))
|
|
|
bb602c |
- else:
|
|
|
bb602c |
- log.debug1("No conntrack helpers supported by the kernel.")
|
|
|
bb602c |
-
|
|
|
bb602c |
- self.nf_nat_helpers = functions.get_nf_nat_helpers()
|
|
|
bb602c |
- if len(self.nf_nat_helpers) > 0:
|
|
|
bb602c |
- log.debug1("NAT helpers supported by the kernel:")
|
|
|
bb602c |
- for key,values in self.nf_nat_helpers.items():
|
|
|
bb602c |
- log.debug1(" %s: %s", key, ", ".join(values))
|
|
|
bb602c |
- else:
|
|
|
bb602c |
- log.debug1("No NAT helpers supported by the kernel.")
|
|
|
bb602c |
-
|
|
|
bb602c |
- else:
|
|
|
bb602c |
- self.nf_conntrack_helpers = { }
|
|
|
bb602c |
- self.nf_nat_helpers = { }
|
|
|
bb602c |
- log.warning("modinfo command is missing, not able to detect conntrack helpers.")
|
|
|
bb602c |
-
|
|
|
bb602c |
def _start(self, reload=False, complete_reload=False):
|
|
|
bb602c |
# initialize firewall
|
|
|
bb602c |
default_zone = config.FALLBACK_ZONE
|
|
|
bb602c |
diff --git a/src/firewall/core/fw_zone.py b/src/firewall/core/fw_zone.py
|
|
|
bb602c |
index e7be779ebc8c..b1dcce240063 100644
|
|
|
bb602c |
--- a/src/firewall/core/fw_zone.py
|
|
|
bb602c |
+++ b/src/firewall/core/fw_zone.py
|
|
|
bb602c |
@@ -846,20 +846,16 @@ class FirewallZone(object):
|
|
|
bb602c |
helper = self._fw.helper.get_helper(module)
|
|
|
bb602c |
except FirewallError:
|
|
|
bb602c |
raise FirewallError(errors.INVALID_HELPER, module)
|
|
|
bb602c |
- if helper.module not in self._fw.nf_conntrack_helpers:
|
|
|
bb602c |
- raise FirewallError(
|
|
|
bb602c |
- errors.INVALID_HELPER,
|
|
|
bb602c |
- "'%s' is not available" % helper.module)
|
|
|
bb602c |
if self._fw.nf_conntrack_helper_setting == 0 and \
|
|
|
bb602c |
len(helper.ports) < 1:
|
|
|
bb602c |
- for mod in self._fw.nf_conntrack_helpers[helper.module]:
|
|
|
bb602c |
- try:
|
|
|
bb602c |
- _helper = self._fw.helper.get_helper(mod)
|
|
|
bb602c |
- except FirewallError:
|
|
|
bb602c |
- if enable:
|
|
|
bb602c |
- log.warning("Helper '%s' is not available" % mod)
|
|
|
bb602c |
- continue
|
|
|
bb602c |
+ _module_short_name = get_nf_conntrack_short_name(helper.module)
|
|
|
bb602c |
+ try:
|
|
|
bb602c |
+ _helper = self._fw.helper.get_helper(_module_short_name)
|
|
|
bb602c |
_helpers.append(_helper)
|
|
|
bb602c |
+ except FirewallError:
|
|
|
bb602c |
+ if enable:
|
|
|
bb602c |
+ log.warning("Helper '%s' is not available" % _module_short_name)
|
|
|
bb602c |
+ continue
|
|
|
bb602c |
else:
|
|
|
bb602c |
_helpers.append(helper)
|
|
|
bb602c |
return _helpers
|
|
|
bb602c |
@@ -1611,14 +1607,8 @@ class FirewallZone(object):
|
|
|
bb602c |
module = helper.module
|
|
|
bb602c |
_module_short_name = get_nf_conntrack_short_name(module)
|
|
|
bb602c |
if self._fw.nf_conntrack_helper_setting == 0:
|
|
|
bb602c |
- if _module_short_name not in \
|
|
|
bb602c |
- self._fw.nf_conntrack_helpers[module]:
|
|
|
bb602c |
- raise FirewallError(
|
|
|
bb602c |
- errors.INVALID_HELPER,
|
|
|
bb602c |
- "'%s' not available in kernel" % module)
|
|
|
bb602c |
nat_module = module.replace("conntrack", "nat")
|
|
|
bb602c |
- if nat_module in self._fw.nf_nat_helpers:
|
|
|
bb602c |
- modules.append(nat_module)
|
|
|
bb602c |
+ modules.append(nat_module)
|
|
|
bb602c |
if helper.family != "" and not backend.is_ipv_supported(helper.family):
|
|
|
bb602c |
# no support for family ipv, continue
|
|
|
bb602c |
continue
|
|
|
bb602c |
@@ -1634,8 +1624,7 @@ class FirewallZone(object):
|
|
|
bb602c |
if helper.module not in modules:
|
|
|
bb602c |
modules.append(helper.module)
|
|
|
bb602c |
nat_module = helper.module.replace("conntrack", "nat")
|
|
|
bb602c |
- if nat_module in self._fw.nf_nat_helpers:
|
|
|
bb602c |
- modules.append(nat_module)
|
|
|
bb602c |
+ modules.append(nat_module)
|
|
|
bb602c |
zone_transaction.add_modules(modules)
|
|
|
bb602c |
|
|
|
bb602c |
# create rules
|
|
|
bb602c |
@@ -1796,8 +1785,7 @@ class FirewallZone(object):
|
|
|
bb602c |
for helper in helpers:
|
|
|
bb602c |
modules.append(helper.module)
|
|
|
bb602c |
nat_module = helper.module.replace("conntrack", "nat")
|
|
|
bb602c |
- if nat_module in self._fw.nf_nat_helpers:
|
|
|
bb602c |
- modules.append(nat_module)
|
|
|
bb602c |
+ modules.append(nat_module)
|
|
|
bb602c |
zone_transaction.add_modules(modules)
|
|
|
bb602c |
zone_transaction.add_chain("filter", "INPUT")
|
|
|
bb602c |
|
|
|
bb602c |
@@ -1821,14 +1809,8 @@ class FirewallZone(object):
|
|
|
bb602c |
for helper in helpers:
|
|
|
bb602c |
module = helper.module
|
|
|
bb602c |
_module_short_name = get_nf_conntrack_short_name(module)
|
|
|
bb602c |
- if _module_short_name not in \
|
|
|
bb602c |
- self._fw.nf_conntrack_helpers[module]:
|
|
|
bb602c |
- raise FirewallError(
|
|
|
bb602c |
- errors.INVALID_HELPER,
|
|
|
bb602c |
- "'%s' is not available in kernel" % module)
|
|
|
bb602c |
nat_module = helper.module.replace("conntrack", "nat")
|
|
|
bb602c |
- if nat_module in self._fw.nf_nat_helpers:
|
|
|
bb602c |
- zone_transaction.add_module(nat_module)
|
|
|
bb602c |
+ zone_transaction.add_module(nat_module)
|
|
|
bb602c |
if helper.family != "" and not backend.is_ipv_supported(helper.family):
|
|
|
bb602c |
# no support for family ipv, continue
|
|
|
bb602c |
continue
|
|
|
bb602c |
diff --git a/src/firewall/functions.py b/src/firewall/functions.py
|
|
|
bb602c |
index ad2166905d1d..8793ac3dbf21 100644
|
|
|
bb602c |
--- a/src/firewall/functions.py
|
|
|
bb602c |
+++ b/src/firewall/functions.py
|
|
|
bb602c |
@@ -24,8 +24,7 @@ __all__ = [ "PY2", "getPortID", "getPortRange", "portStr", "getServiceName",
|
|
|
bb602c |
"checkProtocol", "checkInterface", "checkUINT32",
|
|
|
bb602c |
"firewalld_is_active", "tempFile", "readfile", "writefile",
|
|
|
bb602c |
"enable_ip_forwarding", "get_nf_conntrack_helper_setting",
|
|
|
bb602c |
- "set_nf_conntrack_helper_setting", "get_nf_conntrack_helpers",
|
|
|
bb602c |
- "get_nf_nat_helpers", "check_port", "check_address",
|
|
|
bb602c |
+ "set_nf_conntrack_helper_setting", "check_port", "check_address",
|
|
|
bb602c |
"check_single_address", "check_mac", "uniqify", "ppid_of_pid",
|
|
|
bb602c |
"max_zone_name_len", "checkUser", "checkUid", "checkCommand",
|
|
|
bb602c |
"checkContext", "joinArgs", "splitArgs",
|
|
|
bb602c |
@@ -40,8 +39,7 @@ import string
|
|
|
bb602c |
import sys
|
|
|
bb602c |
import tempfile
|
|
|
bb602c |
from firewall.core.logger import log
|
|
|
bb602c |
-from firewall.core.prog import runProg
|
|
|
bb602c |
-from firewall.config import FIREWALLD_TEMPDIR, FIREWALLD_PIDFILE, COMMANDS
|
|
|
bb602c |
+from firewall.config import FIREWALLD_TEMPDIR, FIREWALLD_PIDFILE
|
|
|
bb602c |
|
|
|
bb602c |
PY2 = sys.version < '3'
|
|
|
bb602c |
|
|
|
bb602c |
@@ -348,66 +346,6 @@ def enable_ip_forwarding(ipv):
|
|
|
bb602c |
def get_nf_conntrack_short_name(module):
|
|
|
bb602c |
return module.replace("_","-").replace("nf-conntrack-", "")
|
|
|
bb602c |
|
|
|
bb602c |
-def get_nf_conntrack_helpers():
|
|
|
bb602c |
- kver = os.uname()[2]
|
|
|
bb602c |
- path = "/lib/modules/%s/kernel/net/netfilter/" % kver
|
|
|
bb602c |
- helpers = { }
|
|
|
bb602c |
- if os.path.isdir(path):
|
|
|
bb602c |
- for filename in sorted(os.listdir(path)):
|
|
|
bb602c |
- if not filename.startswith("nf_conntrack_"):
|
|
|
bb602c |
- continue
|
|
|
bb602c |
- module = filename.split(".")[0]
|
|
|
bb602c |
- (status, ret) = runProg(COMMANDS["modinfo"], [ module, ])
|
|
|
bb602c |
- if status != 0:
|
|
|
bb602c |
- continue
|
|
|
bb602c |
- # If module name matches "nf_conntrack_proto_*"
|
|
|
bb602c |
- # the we add it to helpers list and goto next module
|
|
|
bb602c |
- if filename.startswith("nf_conntrack_proto_"):
|
|
|
bb602c |
- helper = filename.split(".")[0].strip()
|
|
|
bb602c |
- helper = get_nf_conntrack_short_name(helper)
|
|
|
bb602c |
- helpers.setdefault(module, [ ]).append(helper)
|
|
|
bb602c |
- continue
|
|
|
bb602c |
- # Else we get module alias and if "-helper" in the "alias:" line of modinfo
|
|
|
bb602c |
- # then we add it to helpers list and goto next module
|
|
|
bb602c |
- for line in ret.split("\n"):
|
|
|
bb602c |
- if line.startswith("alias:") and "-helper-" in line:
|
|
|
bb602c |
- helper = line.split(":")[1].strip()
|
|
|
bb602c |
- helper = helper.replace("nfct-helper-", "")
|
|
|
bb602c |
- helper = helper.replace("_", "-")
|
|
|
bb602c |
- helpers.setdefault(module, [ ]).append(helper)
|
|
|
bb602c |
- return helpers
|
|
|
bb602c |
-
|
|
|
bb602c |
-def get_nf_nat_helpers():
|
|
|
bb602c |
- kver = os.uname()[2]
|
|
|
bb602c |
- helpers = { }
|
|
|
bb602c |
- for path in ["/lib/modules/%s/kernel/net/netfilter/" % kver,
|
|
|
bb602c |
- "/lib/modules/%s/kernel/net/ipv4/netfilter/" % kver,
|
|
|
bb602c |
- "/lib/modules/%s/kernel/net/ipv6/netfilter/" % kver]:
|
|
|
bb602c |
- if os.path.isdir(path):
|
|
|
bb602c |
- for filename in sorted(os.listdir(path)):
|
|
|
bb602c |
- if not filename.startswith("nf_nat_"):
|
|
|
bb602c |
- continue
|
|
|
bb602c |
- module = filename.split(".")[0]
|
|
|
bb602c |
- (status, ret) = runProg(COMMANDS["modinfo"], [ module, ])
|
|
|
bb602c |
- if status != 0:
|
|
|
bb602c |
- continue
|
|
|
bb602c |
- # If module name matches "nf_nat_proto_*"
|
|
|
bb602c |
- # the we add it to helpers list and goto next module
|
|
|
bb602c |
- if filename.startswith("nf_nat_proto_"):
|
|
|
bb602c |
- helper = filename.split(".")[0].strip()
|
|
|
bb602c |
- helper = helper.replace("_", "-")
|
|
|
bb602c |
- helper = helper.replace("nf-nat-", "")
|
|
|
bb602c |
- helpers.setdefault(module, [ ]).append(helper)
|
|
|
bb602c |
- continue
|
|
|
bb602c |
- # Else we get module alias and if "NAT helper" in "description:" line of modinfo
|
|
|
bb602c |
- # then we add it to helpers list and goto next module
|
|
|
bb602c |
- for line in ret.split("\n"):
|
|
|
bb602c |
- if line.startswith("description:") and "NAT helper" in line:
|
|
|
bb602c |
- helper = module.replace("nf_nat_", "")
|
|
|
bb602c |
- helper = helper.replace("_", "-")
|
|
|
bb602c |
- helpers.setdefault(module, [ ]).append(helper)
|
|
|
bb602c |
- return helpers
|
|
|
bb602c |
-
|
|
|
bb602c |
def get_nf_conntrack_helper_setting():
|
|
|
bb602c |
try:
|
|
|
bb602c |
return int(readfile("/proc/sys/net/netfilter/nf_conntrack_helper")[0])
|
|
|
bb602c |
diff --git a/src/firewall/server/firewalld.py b/src/firewall/server/firewalld.py
|
|
|
bb602c |
index bc04f2d0f4c3..265c58bc3dcc 100644
|
|
|
bb602c |
--- a/src/firewall/server/firewalld.py
|
|
|
bb602c |
+++ b/src/firewall/server/firewalld.py
|
|
|
bb602c |
@@ -186,10 +186,10 @@ class FirewallD(slip.dbus.service.Object):
|
|
|
bb602c |
return dbus.Boolean(self.fw.nf_conntrack_helper_setting == 1)
|
|
|
bb602c |
|
|
|
bb602c |
elif prop == "nf_conntrack_helpers":
|
|
|
bb602c |
- return dbus.Dictionary(self.fw.nf_conntrack_helpers, "sas")
|
|
|
bb602c |
+ return dbus.Dictionary({}, "sas")
|
|
|
bb602c |
|
|
|
bb602c |
elif prop == "nf_nat_helpers":
|
|
|
bb602c |
- return dbus.Dictionary(self.fw.nf_nat_helpers, "sas")
|
|
|
bb602c |
+ return dbus.Dictionary({}, "sas")
|
|
|
bb602c |
|
|
|
bb602c |
else:
|
|
|
bb602c |
raise dbus.exceptions.DBusException(
|
|
|
bb602c |
--
|
|
|
bb602c |
2.23.0
|
|
|
bb602c |
|