Skip to content

Commit 4ab5a5d

Browse files
knurdJonathan Corbet
authored and
Jonathan Corbet
committed
tools: add a kernel-chktaint to tools/debugging
Add a script to the tools/ directory that shows if or why the running kernel was tainted. The script was mostly written by Randy Dunlap; I enhanced the script a bit. There does not appear to be a good home for this script. so create tools/debugging for tools of this nature. Signed-off-by: Randy Dunlap <[email protected]> Signed-off-by: Thorsten Leemhuis <[email protected]> [ jc: fixed conflicts, rewrote changelog ] Signed-off-by: Jonathan Corbet <[email protected]>
1 parent 8fe28cb commit 4ab5a5d

File tree

3 files changed

+226
-6
lines changed

3 files changed

+226
-6
lines changed

tools/Makefile

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ help:
1212
@echo ' acpi - ACPI tools'
1313
@echo ' cgroup - cgroup tools'
1414
@echo ' cpupower - a tool for all things x86 CPU power'
15+
@echo ' debugging - tools for debugging'
1516
@echo ' firewire - the userspace part of nosy, an IEEE-1394 traffic sniffer'
1617
@echo ' freefall - laptop accelerometer program for disk protection'
1718
@echo ' gpio - GPIO tools'
@@ -60,7 +61,7 @@ acpi: FORCE
6061
cpupower: FORCE
6162
$(call descend,power/$@)
6263

63-
cgroup firewire hv guest spi usb virtio vm bpf iio gpio objtool leds wmi pci: FORCE
64+
cgroup firewire hv guest spi usb virtio vm bpf iio gpio objtool leds wmi pci debugging: FORCE
6465
$(call descend,$@)
6566

6667
liblockdep: FORCE
@@ -95,15 +96,16 @@ kvm_stat: FORCE
9596
all: acpi cgroup cpupower gpio hv firewire liblockdep \
9697
perf selftests spi turbostat usb \
9798
virtio vm bpf x86_energy_perf_policy \
98-
tmon freefall iio objtool kvm_stat wmi pci
99+
tmon freefall iio objtool kvm_stat wmi \
100+
pci debugging
99101

100102
acpi_install:
101103
$(call descend,power/$(@:_install=),install)
102104

103105
cpupower_install:
104106
$(call descend,power/$(@:_install=),install)
105107

106-
cgroup_install firewire_install gpio_install hv_install iio_install perf_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install:
108+
cgroup_install firewire_install gpio_install hv_install iio_install perf_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install debugging_install:
107109
$(call descend,$(@:_install=),install)
108110

109111
liblockdep_install:
@@ -129,15 +131,15 @@ install: acpi_install cgroup_install cpupower_install gpio_install \
129131
perf_install selftests_install turbostat_install usb_install \
130132
virtio_install vm_install bpf_install x86_energy_perf_policy_install \
131133
tmon_install freefall_install objtool_install kvm_stat_install \
132-
wmi_install pci_install
134+
wmi_install pci_install debugging_install
133135

134136
acpi_clean:
135137
$(call descend,power/acpi,clean)
136138

137139
cpupower_clean:
138140
$(call descend,power/cpupower,clean)
139141

140-
cgroup_clean hv_clean firewire_clean spi_clean usb_clean virtio_clean vm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean pci_clean:
142+
cgroup_clean hv_clean firewire_clean spi_clean usb_clean virtio_clean vm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean pci_clean debugging_clean:
141143
$(call descend,$(@:_clean=),clean)
142144

143145
liblockdep_clean:
@@ -175,6 +177,6 @@ clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean \
175177
perf_clean selftests_clean turbostat_clean spi_clean usb_clean virtio_clean \
176178
vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
177179
freefall_clean build_clean libbpf_clean libsubcmd_clean liblockdep_clean \
178-
gpio_clean objtool_clean leds_clean wmi_clean pci_clean
180+
gpio_clean objtool_clean leds_clean wmi_clean pci_clean debugging_clean
179181

180182
.PHONY: FORCE

tools/debugging/Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# Makefile for debugging tools
3+
4+
PREFIX ?= /usr
5+
BINDIR ?= bin
6+
INSTALL ?= install
7+
8+
TARGET = kernel-chktaint
9+
10+
all: $(TARGET)
11+
12+
clean:
13+
14+
install: kernel-chktaint
15+
$(INSTALL) -D -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/$(BINDIR)/$(TARGET)
16+

tools/debugging/kernel-chktaint

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#! /bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Randy Dunlap <[email protected]>, 2018
5+
# Thorsten Leemhuis <[email protected]>, 2018
6+
7+
usage()
8+
{
9+
cat <<EOF
10+
usage: ${0##*/}
11+
${0##*/} <int>
12+
13+
Call without parameters to decode /proc/sys/kernel/tainted.
14+
15+
Call with a positive integer as parameter to decode a value you
16+
retrieved from /proc/sys/kernel/tainted on another system.
17+
18+
EOF
19+
}
20+
21+
if [ "$1"x != "x" ]; then
22+
if [ "$1"x == "--helpx" ] || [ "$1"x == "-hx" ] ; then
23+
usage
24+
exit 1
25+
elif [ $1 -ge 0 ] 2>/dev/null ; then
26+
taint=$1
27+
else
28+
echo "Error: Parameter '$1' not a positive interger. Aborting." >&2
29+
exit 1
30+
fi
31+
else
32+
TAINTFILE="/proc/sys/kernel/tainted"
33+
if [ ! -r $TAINTFILE ]; then
34+
echo "No file: $TAINTFILE"
35+
exit
36+
fi
37+
38+
taint=`cat $TAINTFILE`
39+
fi
40+
41+
if [ $taint -eq 0 ]; then
42+
echo "Kernel not Tainted"
43+
exit
44+
else
45+
echo "Kernel is \"tainted\" for the following reasons:"
46+
fi
47+
48+
T=$taint
49+
out=
50+
51+
addout() {
52+
out=$out$1
53+
}
54+
55+
if [ `expr $T % 2` -eq 0 ]; then
56+
addout "G"
57+
else
58+
addout "P"
59+
echo " * proprietary module was loaded (#0)"
60+
fi
61+
62+
T=`expr $T / 2`
63+
if [ `expr $T % 2` -eq 0 ]; then
64+
addout " "
65+
else
66+
addout "F"
67+
echo " * module was force loaded (#1)"
68+
fi
69+
70+
T=`expr $T / 2`
71+
if [ `expr $T % 2` -eq 0 ]; then
72+
addout " "
73+
else
74+
addout "S"
75+
echo " * SMP kernel oops on an officially SMP incapable processor (#2)"
76+
fi
77+
78+
T=`expr $T / 2`
79+
if [ `expr $T % 2` -eq 0 ]; then
80+
addout " "
81+
else
82+
addout "R"
83+
echo " * module was force unloaded (#3)"
84+
fi
85+
86+
T=`expr $T / 2`
87+
if [ `expr $T % 2` -eq 0 ]; then
88+
addout " "
89+
else
90+
addout "M"
91+
echo " * processor reported a Machine Check Exception (MCE) (#4)"
92+
fi
93+
94+
T=`expr $T / 2`
95+
if [ `expr $T % 2` -eq 0 ]; then
96+
addout " "
97+
else
98+
addout "B"
99+
echo " * bad page referenced or some unexpected page flags (#5)"
100+
fi
101+
102+
T=`expr $T / 2`
103+
if [ `expr $T % 2` -eq 0 ]; then
104+
addout " "
105+
else
106+
addout "U"
107+
echo " * taint requested by userspace application (#6)"
108+
fi
109+
110+
T=`expr $T / 2`
111+
if [ `expr $T % 2` -eq 0 ]; then
112+
addout " "
113+
else
114+
addout "D"
115+
echo " * kernel died recently, i.e. there was an OOPS or BUG (#7)"
116+
fi
117+
118+
T=`expr $T / 2`
119+
if [ `expr $T % 2` -eq 0 ]; then
120+
addout " "
121+
else
122+
addout "A"
123+
echo " * an ACPI table was overridden by user (#8)"
124+
fi
125+
126+
T=`expr $T / 2`
127+
if [ `expr $T % 2` -eq 0 ]; then
128+
addout " "
129+
else
130+
addout "W"
131+
echo " * kernel issued warning (#9)"
132+
fi
133+
134+
T=`expr $T / 2`
135+
if [ `expr $T % 2` -eq 0 ]; then
136+
addout " "
137+
else
138+
addout "C"
139+
echo " * staging driver was loaded (#10)"
140+
fi
141+
142+
T=`expr $T / 2`
143+
if [ `expr $T % 2` -eq 0 ]; then
144+
addout " "
145+
else
146+
addout "I"
147+
echo " * workaround for bug in platform firmware applied (#11)"
148+
fi
149+
150+
T=`expr $T / 2`
151+
if [ `expr $T % 2` -eq 0 ]; then
152+
addout " "
153+
else
154+
addout "O"
155+
echo " * externally-built ('out-of-tree') module was loaded (#12)"
156+
fi
157+
158+
T=`expr $T / 2`
159+
if [ `expr $T % 2` -eq 0 ]; then
160+
addout " "
161+
else
162+
addout "E"
163+
echo " * unsigned module was loaded (#13)"
164+
fi
165+
166+
T=`expr $T / 2`
167+
if [ `expr $T % 2` -eq 0 ]; then
168+
addout " "
169+
else
170+
addout "L"
171+
echo " * soft lockup occurred (#14)"
172+
fi
173+
174+
T=`expr $T / 2`
175+
if [ `expr $T % 2` -eq 0 ]; then
176+
addout " "
177+
else
178+
addout "K"
179+
echo " * kernel has been live patched (#15)"
180+
fi
181+
182+
T=`expr $T / 2`
183+
if [ `expr $T % 2` -eq 0 ]; then
184+
addout " "
185+
else
186+
addout "X"
187+
echo " * auxiliary taint, defined for and used by distros (#16)"
188+
189+
fi
190+
T=`expr $T / 2`
191+
if [ `expr $T % 2` -eq 0 ]; then
192+
addout " "
193+
else
194+
addout "T"
195+
echo " * kernel was built with the struct randomization plugin (#17)"
196+
fi
197+
198+
echo "For a more detailed explanation of the various taint flags see"
199+
echo " Documentation/admin-guide/tainted-kernels.rst in the the Linux kernel sources"
200+
echo " or https://kernel.org/doc/html/latest/admin-guide/tainted-kernels.html"
201+
echo "Raw taint value as int/string: $taint/'$out'"
202+
#EOF#

0 commit comments

Comments
 (0)