[Crash-utility] [PATCH 2/3] kernel: Introduce is_kernel_tainted()

Aaron Tomlin atomlin at redhat.com
Mon Nov 1 11:39:33 UTC 2021


Provide a quick way to test if the given Linux kernel is "tainted".
Support for Linux-2.6.12 and above, to date.

Signed-off-by: Aaron Tomlin <atomlin at redhat.com>
---
 kernel.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/kernel.c b/kernel.c
index 1310f98..553849c 100644
--- a/kernel.c
+++ b/kernel.c
@@ -5482,6 +5482,24 @@ cmd_sys(void)
         } while (args[optind]);
 }
 
+static int
+is_kernel_tainted(void)
+{
+	ulong tainted_mask;
+	int tainted;
+
+	if (kernel_symbol_exists("tainted")) {
+		get_symbol_data("tainted", sizeof(int), &tainted);
+		if (tainted)
+			return TRUE;
+	} else if (kernel_symbol_exists("tainted_mask")) {
+		get_symbol_data("tainted_mask", sizeof(ulong), &tainted_mask);
+		if (tainted_mask)
+			return TRUE;
+	}
+	return FALSE;
+}
+
 static int
 is_livepatch(void)
 {
-- 
2.31.1




More information about the Crash-utility mailing list