aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--LICENSE22
-rw-r--r--Makefile14
-rw-r--r--main.c81
-rw-r--r--taint_flags.h35
5 files changed, 154 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..31849ba
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.o
+/taint-info
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..bb13611
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2018 Cynthia Revstrom
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..3ab6ba2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+CC = gcc
+
+CFLAGS = -c
+LDFLAGS =
+
+LIBS = -lm
+
+OBJS = main.o
+
+%.o: %.c
+ $(CC) $(CFLAGS) -o $@ $<
+
+taint-info: $(OBJS)
+ $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..b397b8a
--- /dev/null
+++ b/main.c
@@ -0,0 +1,81 @@
+/*
+ *
+ * This is a part of taint-info.
+ * Copyright (C) 2018 Cynthia Revstrom <me@cynthia.re>
+ *
+ * taint-info is licensed under the MIT License.
+ * For a full license please refer to the LICENSE file in the root of the taint-info repository.
+ *
+ * The taint flag info in this file is from the Linux kernel documentation, available at: https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "taint_flags.h"
+
+void check_taint_flag(int taintval, int flag, char* flag_name, char* msg) {
+ if(taintval & flag) {
+ printf("%s: %s\n", flag_name, msg);
+ }
+}
+
+int main(int argc, char** argv) {
+ // Help with -h or --help
+ if (argc > 2) {
+ if(argv[1] == "-h" || argv[1] == "--help") {
+ printf("taint-info - Linux Kernel Taint Info\n");
+ printf("Copyright (C) 2018 Cynthia Revström <me@cynthia.re>\n");
+ printf("just run %s :)", argv[0]);
+ }
+ }
+
+ char buf[2048];
+ FILE* fh;
+ size_t size;
+
+ // Read /proc/sys/kernel/tainted
+ fh = fopen("/proc/sys/kernel/tainted", "r");
+ size = fread(&buf, 1, sizeof(buf), fh);
+ fclose(fh);
+
+ buf[size] = '\0';
+
+ // Parse the string from tainted to an int
+ char* end;
+ long l = strtol(buf, &end, 10);
+ int taintval = (int) l;
+
+
+ // Check the taint
+ if(taintval != 0) {
+ printf("Kernel is tainted :(\n");
+ printf("Taint value: %d\n", taintval);
+
+ // Check for taint flags
+ printf("Taint flags: \n");
+
+ check_taint_flag(taintval, TAINT_NON_GPL, "NON_GPL", "Non-GPL module loaded");
+ check_taint_flag(taintval, TAINT_FORCE_LOAD, "FORCE_LOAD", "Kernel module force loaded with insmod -f");
+ check_taint_flag(taintval, TAINT_UNSAFE_SMP, "UNSAFE_SMP", "SMP with CPU not designed for SMP");
+ check_taint_flag(taintval, TAINT_FORCE_UNLOAD, "FORCE_UNLOAD", "Kernel module force unloaded with rmmod -f");
+ check_taint_flag(taintval, TAINT_HW_CHECK_ERR, "HW_CHECK_ERR", "Hardware check error");
+ check_taint_flag(taintval, TAINT_BAD_PAGE, "BAD_PAGE", "A bad page was discovered on the system");
+ check_taint_flag(taintval, TAINT_MARK_TAINT, "MARK_TAINT", "The user has marked the software as tainted");
+ check_taint_flag(taintval, TAINT_SYSTEM_DIED, "SYSTEM_DIED", "The system has died");
+ check_taint_flag(taintval, TAINT_ACPI_DSDT_OVERRIDE, "ACPI_DSDT_OVERRIDE", "The ACPI DSDT has been overridden");
+ check_taint_flag(taintval, TAINT_KERNEL_WARN, "KERNEL_WARN", "A kernel warning has occured");
+ check_taint_flag(taintval, TAINT_MOD_STAGING, "MOD_STAGING", "A module from drivers/staging was loaded");
+ check_taint_flag(taintval, TAINT_SYS_FW_BUG, "SYS_FW_BUG", "The system is working around a severe firmware bug");
+ check_taint_flag(taintval, TAINT_OOT_MOD, "OOT_MOD", "An out-of-tree-module has been loaded");
+ check_taint_flag(taintval, TAINT_UNSIGNED, "UNSIGNED", "An unsigned module has been loaded into a kernel supporting module signatures");
+ check_taint_flag(taintval, TAINT_SOFT_LOCKUP, "SOFT_LOCKUP", "A soft lockup has previously occured on the system");
+ check_taint_flag(taintval, TAINT_LIVE_PATCHED, "LIVE_PATCHED", "The kernel has been live patched");
+ check_taint_flag(taintval, TAINT_AUX, "AUX", "Auxiliary taint, defined and used by distros");
+ check_taint_flag(taintval, TAINT_STRUCT_RANDOM, "STRUCT_RANDOM", "The kernel was built with the struct randomization plugin");
+ } else {
+ printf("Kernel is not tainted :)");
+ }
+
+ return 0;
+}
diff --git a/taint_flags.h b/taint_flags.h
new file mode 100644
index 0000000..db81ca5
--- /dev/null
+++ b/taint_flags.h
@@ -0,0 +1,35 @@
+/*
+ *
+ * This is a part of taint-info.
+ * Copyright (C) 2018 Cynthia Revstrom <me@cynthia.re>
+ *
+ * taint-info is licensed under the MIT License.
+ * For a full license please refer to the LICENSE file in the root of the taint-info repository.
+ *
+ * The taint flag info in this file is from the Linux kernel documentation, available at: https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
+ *
+ */
+
+#ifndef __TAINT_INFO_FLAGS_H
+#define __TAINT_INFO_FLAGS_H
+
+#define TAINT_NON_GPL 1
+#define TAINT_FORCE_LOAD 2
+#define TAINT_UNSAFE_SMP 4
+#define TAINT_FORCE_UNLOAD 8
+#define TAINT_HW_CHECK_ERR 16
+#define TAINT_BAD_PAGE 32
+#define TAINT_MARK_TAINT 64
+#define TAINT_SYSTEM_DIED 128
+#define TAINT_ACPI_DSDT_OVERRIDE 256
+#define TAINT_KERNEL_WARN 512
+#define TAINT_MOD_STAGING 1024
+#define TAINT_SYS_FW_BUG 2048
+#define TAINT_OOT_MOD 4096
+#define TAINT_UNSIGNED 8192
+#define TAINT_SOFT_LOCKUP 16384
+#define TAINT_LIVE_PATCHED 32768
+#define TAINT_AUX 65536
+#define TAINT_STRUCT_RANDOM 131072
+
+#endif