summaryrefslogtreecommitdiff
path: root/bin
diff options
authorPMR <pmr@pmr-lander>2020-06-15 16:40:49 +0000
committerPMR <pmr@pmr-lander>2020-06-15 16:40:49 +0000
commitbdb430320d194edbf25c3326c5d19189ab891db2 (patch)
treef54110f765f70768e2fed8b8189fecfacf1c07bf /bin
parent0bbfcaadd20e6e4f2e641e2d93fef57743a980be (diff)
parentb8b2d8b76c5ace5f37917c7bdc2bf1747bff3aa2 (diff)
Merge #385756 from ~bladernr/plainbox-provider-checkbox:1876977-improve-kernel-taint-check
bin/kernel_taint_test: Improve output to identify proprietary and non-intree drivers. LP:1876977
Diffstat (limited to 'bin')
-rwxr-xr-xbin/kernel_taint_test37
1 files changed, 36 insertions, 1 deletions
diff --git a/bin/kernel_taint_test b/bin/kernel_taint_test
index 976ccb6..cbceaf6 100755
--- a/bin/kernel_taint_test
+++ b/bin/kernel_taint_test
@@ -29,8 +29,9 @@ returns a value of 1. The script also returns a value of 1 if
import sys
+import shlex
from argparse import ArgumentParser
-
+from subprocess import check_output
# Note: If max_taints is increased, add descriptions to taint_meanings in
# report_failures()
@@ -49,6 +50,35 @@ def find_taints(taint_file):
return(taints)
+def get_modules():
+ lsmod_output = check_output('lsmod', universal_newlines=True).split('\n')
+ # get only the module names
+ modules = []
+ for line in lsmod_output:
+ if line and 'Module' not in line:
+ modules.append(line.split()[0])
+ return(modules)
+
+
+def print_out_of_tree_modules(modules):
+ print(" Modules not in-tree:")
+ for mod in modules:
+ cmd = 'modinfo -F intree %s' % mod
+ if not check_output(shlex.split(cmd),
+ universal_newlines=True):
+ print(" %s" % mod)
+
+
+def print_GPL_incompatible_modules(modules):
+ print(" Modules with GPL Incompatible Licenses:")
+ for mod in modules:
+ cmd = 'modinfo -F license %s' % mod
+ license = check_output(shlex.split(cmd),
+ universal_newlines=True).strip()
+ if "GPL" not in license and "MIT" not in license:
+ print(" %s: %s" % (mod, license))
+
+
def report_failures(taints):
"""Report the failure code and its meaning(s)."""
# Below meaning strings are taken from
@@ -73,7 +103,12 @@ def report_failures(taints):
"kernel was built with the struct randomization plugin"]
for i in range(max_taints+1):
if (taints & (2 ** i)):
+ modules = get_modules()
print("Taint bit value: {} ({})".format(i, taint_meanings[i]))
+ if i == 0: # List GPL incompatible modules and licenses
+ print_GPL_incompatible_modules(modules)
+ if i == 12: # List out-of-tree modules
+ print_out_of_tree_modules(modules)
if taints == 0:
print("No kernel taints detected.")