aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2021-04-19 11:58:52 -0400
committerJake Hunsaker <jhunsake@redhat.com>2021-05-05 09:54:51 -0400
commit31f70706fe0f6f54ea8a0abb055a5b8975113213 (patch)
tree65637a5e0f6c0f06ec50efadff75dce3f9e14db8
parent17ce8a7027c19019831796f4b016601019cfb725 (diff)
downloadsos-31f70706fe0f6f54ea8a0abb055a5b8975113213.tar.gz
[policies] Improve kernel module loading to include builtins
Adds determination of builtin modules to extend the list of kernel modules that are loaded via our parsing of `lsmod`. This is first done by parsing `/usr/lib/modules/$(uname -r)/modules.builtin`, and then by further inspecting `/boot/config-$(uname -r)` for specific kconfig strings that are well-known to build kernel modules into the running kernel, but for those that do not appear in the modules.builtin file above. Closes: #2500 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/policies/distros/__init__.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/sos/policies/distros/__init__.py b/sos/policies/distros/__init__.py
index a24a0e5b..dd378733 100644
--- a/sos/policies/distros/__init__.py
+++ b/sos/policies/distros/__init__.py
@@ -133,8 +133,45 @@ class LinuxPolicy(Policy):
"""Obtain a list of loaded kernel modules to reference later for plugin
enablement and SoSPredicate checks
"""
+ self.kernel_mods = []
+
+ # first load modules from lsmod
lines = shell_out("lsmod", timeout=0).splitlines()
- self.kernel_mods = [line.split()[0].strip() for line in lines]
+ self.kernel_mods.extend([
+ line.split()[0].strip() for line in lines[1:]
+ ])
+
+ # next, include kernel builtins
+ builtins = "/usr/lib/modules/%s/modules.builtin" % os.uname().release
+ try:
+ with open(builtins, "r") as mfile:
+ for line in mfile:
+ kmod = line.split('/')[-1].split('.ko')[0]
+ self.kernel_mods.append(kmod)
+ except IOError:
+ pass
+
+ # finally, parse kconfig looking for specific kconfig strings that
+ # have been verified to not appear in either lsmod or modules.builtin
+ # regardless of how they are built
+ config_strings = {
+ 'devlink': 'CONFIG_NET_DEVLINK',
+ 'dm_mod': 'CONFIG_BLK_DEV_DM'
+ }
+
+ booted_config = "/boot/config-%s" % os.uname().release
+ kconfigs = []
+ try:
+ with open(booted_config, "r") as kfile:
+ for line in kfile:
+ if '=y' in line:
+ kconfigs.append(line.split('=y')[0])
+ except IOError:
+ pass
+
+ for builtin in config_strings:
+ if config_strings[builtin] in kconfigs:
+ self.kernel_mods.append(builtin)
def pre_work(self):
# this method will be called before the gathering begins