18c2ecf20Sopenharmony_ci#! /bin/sh
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# Randy Dunlap <rdunlap@infradead.org>, 2018
58c2ecf20Sopenharmony_ci# Thorsten Leemhuis <linux@leemhuis.info>, 2018
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciusage()
88c2ecf20Sopenharmony_ci{
98c2ecf20Sopenharmony_ci	cat <<EOF
108c2ecf20Sopenharmony_ciusage: ${0##*/}
118c2ecf20Sopenharmony_ci       ${0##*/} <int>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciCall without parameters to decode /proc/sys/kernel/tainted.
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciCall with a positive integer as parameter to decode a value you
168c2ecf20Sopenharmony_ciretrieved from /proc/sys/kernel/tainted on another system.
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciEOF
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciif [ "$1"x != "x" ]; then
228c2ecf20Sopenharmony_ci	if  [ "$1"x == "--helpx" ] || [ "$1"x == "-hx" ] ; then
238c2ecf20Sopenharmony_ci		usage
248c2ecf20Sopenharmony_ci		exit 1
258c2ecf20Sopenharmony_ci	elif  [ $1 -ge 0 ] 2>/dev/null ; then
268c2ecf20Sopenharmony_ci		taint=$1
278c2ecf20Sopenharmony_ci	else
288c2ecf20Sopenharmony_ci		echo "Error: Parameter '$1' not a positive interger. Aborting." >&2
298c2ecf20Sopenharmony_ci		exit 1
308c2ecf20Sopenharmony_ci	fi
318c2ecf20Sopenharmony_cielse
328c2ecf20Sopenharmony_ci	TAINTFILE="/proc/sys/kernel/tainted"
338c2ecf20Sopenharmony_ci	if [ ! -r $TAINTFILE ]; then
348c2ecf20Sopenharmony_ci		echo "No file: $TAINTFILE"
358c2ecf20Sopenharmony_ci		exit
368c2ecf20Sopenharmony_ci	fi
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	taint=`cat $TAINTFILE`
398c2ecf20Sopenharmony_cifi
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciif [ $taint -eq 0 ]; then
428c2ecf20Sopenharmony_ci	echo "Kernel not Tainted"
438c2ecf20Sopenharmony_ci	exit
448c2ecf20Sopenharmony_cielse
458c2ecf20Sopenharmony_ci	echo "Kernel is \"tainted\" for the following reasons:"
468c2ecf20Sopenharmony_cifi
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciT=$taint
498c2ecf20Sopenharmony_ciout=
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciaddout() {
528c2ecf20Sopenharmony_ci	out=$out$1
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
568c2ecf20Sopenharmony_ci	addout "G"
578c2ecf20Sopenharmony_cielse
588c2ecf20Sopenharmony_ci	addout "P"
598c2ecf20Sopenharmony_ci	echo " * proprietary module was loaded (#0)"
608c2ecf20Sopenharmony_cifi
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciT=`expr $T / 2`
638c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
648c2ecf20Sopenharmony_ci	addout " "
658c2ecf20Sopenharmony_cielse
668c2ecf20Sopenharmony_ci	addout "F"
678c2ecf20Sopenharmony_ci	echo " * module was force loaded (#1)"
688c2ecf20Sopenharmony_cifi
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciT=`expr $T / 2`
718c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
728c2ecf20Sopenharmony_ci	addout " "
738c2ecf20Sopenharmony_cielse
748c2ecf20Sopenharmony_ci	addout "S"
758c2ecf20Sopenharmony_ci	echo " * SMP kernel oops on an officially SMP incapable processor (#2)"
768c2ecf20Sopenharmony_cifi
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ciT=`expr $T / 2`
798c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
808c2ecf20Sopenharmony_ci	addout " "
818c2ecf20Sopenharmony_cielse
828c2ecf20Sopenharmony_ci	addout "R"
838c2ecf20Sopenharmony_ci	echo " * module was force unloaded (#3)"
848c2ecf20Sopenharmony_cifi
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciT=`expr $T / 2`
878c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
888c2ecf20Sopenharmony_ci	addout " "
898c2ecf20Sopenharmony_cielse
908c2ecf20Sopenharmony_ci	addout "M"
918c2ecf20Sopenharmony_ci	echo " * processor reported a Machine Check Exception (MCE) (#4)"
928c2ecf20Sopenharmony_cifi
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ciT=`expr $T / 2`
958c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
968c2ecf20Sopenharmony_ci	addout " "
978c2ecf20Sopenharmony_cielse
988c2ecf20Sopenharmony_ci	addout "B"
998c2ecf20Sopenharmony_ci	echo " * bad page referenced or some unexpected page flags (#5)"
1008c2ecf20Sopenharmony_cifi
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciT=`expr $T / 2`
1038c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1048c2ecf20Sopenharmony_ci	addout " "
1058c2ecf20Sopenharmony_cielse
1068c2ecf20Sopenharmony_ci	addout "U"
1078c2ecf20Sopenharmony_ci	echo " * taint requested by userspace application (#6)"
1088c2ecf20Sopenharmony_cifi
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ciT=`expr $T / 2`
1118c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1128c2ecf20Sopenharmony_ci	addout " "
1138c2ecf20Sopenharmony_cielse
1148c2ecf20Sopenharmony_ci	addout "D"
1158c2ecf20Sopenharmony_ci	echo " * kernel died recently, i.e. there was an OOPS or BUG (#7)"
1168c2ecf20Sopenharmony_cifi
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ciT=`expr $T / 2`
1198c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1208c2ecf20Sopenharmony_ci	addout " "
1218c2ecf20Sopenharmony_cielse
1228c2ecf20Sopenharmony_ci	addout "A"
1238c2ecf20Sopenharmony_ci	echo " * an ACPI table was overridden by user (#8)"
1248c2ecf20Sopenharmony_cifi
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciT=`expr $T / 2`
1278c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1288c2ecf20Sopenharmony_ci	addout " "
1298c2ecf20Sopenharmony_cielse
1308c2ecf20Sopenharmony_ci	addout "W"
1318c2ecf20Sopenharmony_ci	echo " * kernel issued warning (#9)"
1328c2ecf20Sopenharmony_cifi
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ciT=`expr $T / 2`
1358c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1368c2ecf20Sopenharmony_ci	addout " "
1378c2ecf20Sopenharmony_cielse
1388c2ecf20Sopenharmony_ci	addout "C"
1398c2ecf20Sopenharmony_ci	echo " * staging driver was loaded (#10)"
1408c2ecf20Sopenharmony_cifi
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ciT=`expr $T / 2`
1438c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1448c2ecf20Sopenharmony_ci	addout " "
1458c2ecf20Sopenharmony_cielse
1468c2ecf20Sopenharmony_ci	addout "I"
1478c2ecf20Sopenharmony_ci	echo " * workaround for bug in platform firmware applied (#11)"
1488c2ecf20Sopenharmony_cifi
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciT=`expr $T / 2`
1518c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1528c2ecf20Sopenharmony_ci	addout " "
1538c2ecf20Sopenharmony_cielse
1548c2ecf20Sopenharmony_ci	addout "O"
1558c2ecf20Sopenharmony_ci	echo " * externally-built ('out-of-tree') module was loaded  (#12)"
1568c2ecf20Sopenharmony_cifi
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ciT=`expr $T / 2`
1598c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1608c2ecf20Sopenharmony_ci	addout " "
1618c2ecf20Sopenharmony_cielse
1628c2ecf20Sopenharmony_ci	addout "E"
1638c2ecf20Sopenharmony_ci	echo " * unsigned module was loaded (#13)"
1648c2ecf20Sopenharmony_cifi
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ciT=`expr $T / 2`
1678c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1688c2ecf20Sopenharmony_ci	addout " "
1698c2ecf20Sopenharmony_cielse
1708c2ecf20Sopenharmony_ci	addout "L"
1718c2ecf20Sopenharmony_ci	echo " * soft lockup occurred (#14)"
1728c2ecf20Sopenharmony_cifi
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ciT=`expr $T / 2`
1758c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1768c2ecf20Sopenharmony_ci	addout " "
1778c2ecf20Sopenharmony_cielse
1788c2ecf20Sopenharmony_ci	addout "K"
1798c2ecf20Sopenharmony_ci	echo " * kernel has been live patched (#15)"
1808c2ecf20Sopenharmony_cifi
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ciT=`expr $T / 2`
1838c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1848c2ecf20Sopenharmony_ci	addout " "
1858c2ecf20Sopenharmony_cielse
1868c2ecf20Sopenharmony_ci	addout "X"
1878c2ecf20Sopenharmony_ci	echo " * auxiliary taint, defined for and used by distros (#16)"
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cifi
1908c2ecf20Sopenharmony_ciT=`expr $T / 2`
1918c2ecf20Sopenharmony_ciif [ `expr $T % 2` -eq 0 ]; then
1928c2ecf20Sopenharmony_ci	addout " "
1938c2ecf20Sopenharmony_cielse
1948c2ecf20Sopenharmony_ci	addout "T"
1958c2ecf20Sopenharmony_ci	echo " * kernel was built with the struct randomization plugin (#17)"
1968c2ecf20Sopenharmony_cifi
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ciecho "For a more detailed explanation of the various taint flags see"
1998c2ecf20Sopenharmony_ciecho " Documentation/admin-guide/tainted-kernels.rst in the the Linux kernel sources"
2008c2ecf20Sopenharmony_ciecho " or https://kernel.org/doc/html/latest/admin-guide/tainted-kernels.html"
2018c2ecf20Sopenharmony_ciecho "Raw taint value as int/string: $taint/'$out'"
2028c2ecf20Sopenharmony_ci#EOF#
203