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