14ab5a5d2SThorsten Leemhuis#! /bin/sh 24ab5a5d2SThorsten Leemhuis# SPDX-License-Identifier: GPL-2.0 34ab5a5d2SThorsten Leemhuis# 44ab5a5d2SThorsten Leemhuis# Randy Dunlap <rdunlap@infradead.org>, 2018 54ab5a5d2SThorsten Leemhuis# Thorsten Leemhuis <linux@leemhuis.info>, 2018 64ab5a5d2SThorsten Leemhuis 74ab5a5d2SThorsten Leemhuisusage() 84ab5a5d2SThorsten Leemhuis{ 94ab5a5d2SThorsten Leemhuis cat <<EOF 104ab5a5d2SThorsten Leemhuisusage: ${0##*/} 114ab5a5d2SThorsten Leemhuis ${0##*/} <int> 124ab5a5d2SThorsten Leemhuis 134ab5a5d2SThorsten LeemhuisCall without parameters to decode /proc/sys/kernel/tainted. 144ab5a5d2SThorsten Leemhuis 154ab5a5d2SThorsten LeemhuisCall with a positive integer as parameter to decode a value you 164ab5a5d2SThorsten Leemhuisretrieved from /proc/sys/kernel/tainted on another system. 174ab5a5d2SThorsten Leemhuis 184ab5a5d2SThorsten LeemhuisEOF 194ab5a5d2SThorsten Leemhuis} 204ab5a5d2SThorsten Leemhuis 214ab5a5d2SThorsten Leemhuisif [ "$1"x != "x" ]; then 224ab5a5d2SThorsten Leemhuis if [ "$1"x == "--helpx" ] || [ "$1"x == "-hx" ] ; then 234ab5a5d2SThorsten Leemhuis usage 244ab5a5d2SThorsten Leemhuis exit 1 254ab5a5d2SThorsten Leemhuis elif [ $1 -ge 0 ] 2>/dev/null ; then 264ab5a5d2SThorsten Leemhuis taint=$1 274ab5a5d2SThorsten Leemhuis else 2884de8154SMasanari Iida echo "Error: Parameter '$1' not a positive integer. Aborting." >&2 294ab5a5d2SThorsten Leemhuis exit 1 304ab5a5d2SThorsten Leemhuis fi 314ab5a5d2SThorsten Leemhuiselse 324ab5a5d2SThorsten Leemhuis TAINTFILE="/proc/sys/kernel/tainted" 334ab5a5d2SThorsten Leemhuis if [ ! -r $TAINTFILE ]; then 344ab5a5d2SThorsten Leemhuis echo "No file: $TAINTFILE" 354ab5a5d2SThorsten Leemhuis exit 364ab5a5d2SThorsten Leemhuis fi 374ab5a5d2SThorsten Leemhuis 384ab5a5d2SThorsten Leemhuis taint=`cat $TAINTFILE` 394ab5a5d2SThorsten Leemhuisfi 404ab5a5d2SThorsten Leemhuis 414ab5a5d2SThorsten Leemhuisif [ $taint -eq 0 ]; then 424ab5a5d2SThorsten Leemhuis echo "Kernel not Tainted" 434ab5a5d2SThorsten Leemhuis exit 444ab5a5d2SThorsten Leemhuiselse 454ab5a5d2SThorsten Leemhuis echo "Kernel is \"tainted\" for the following reasons:" 464ab5a5d2SThorsten Leemhuisfi 474ab5a5d2SThorsten Leemhuis 484ab5a5d2SThorsten LeemhuisT=$taint 494ab5a5d2SThorsten Leemhuisout= 504ab5a5d2SThorsten Leemhuis 514ab5a5d2SThorsten Leemhuisaddout() { 524ab5a5d2SThorsten Leemhuis out=$out$1 534ab5a5d2SThorsten Leemhuis} 544ab5a5d2SThorsten Leemhuis 554ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 564ab5a5d2SThorsten Leemhuis addout "G" 574ab5a5d2SThorsten Leemhuiselse 584ab5a5d2SThorsten Leemhuis addout "P" 594ab5a5d2SThorsten Leemhuis echo " * proprietary module was loaded (#0)" 604ab5a5d2SThorsten Leemhuisfi 614ab5a5d2SThorsten Leemhuis 624ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 634ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 644ab5a5d2SThorsten Leemhuis addout " " 654ab5a5d2SThorsten Leemhuiselse 664ab5a5d2SThorsten Leemhuis addout "F" 674ab5a5d2SThorsten Leemhuis echo " * module was force loaded (#1)" 684ab5a5d2SThorsten Leemhuisfi 694ab5a5d2SThorsten Leemhuis 704ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 714ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 724ab5a5d2SThorsten Leemhuis addout " " 734ab5a5d2SThorsten Leemhuiselse 744ab5a5d2SThorsten Leemhuis addout "S" 75547f574fSMathieu Chouquet-Stringer echo " * kernel running on an out of specification system (#2)" 764ab5a5d2SThorsten Leemhuisfi 774ab5a5d2SThorsten Leemhuis 784ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 794ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 804ab5a5d2SThorsten Leemhuis addout " " 814ab5a5d2SThorsten Leemhuiselse 824ab5a5d2SThorsten Leemhuis addout "R" 834ab5a5d2SThorsten Leemhuis echo " * module was force unloaded (#3)" 844ab5a5d2SThorsten Leemhuisfi 854ab5a5d2SThorsten Leemhuis 864ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 874ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 884ab5a5d2SThorsten Leemhuis addout " " 894ab5a5d2SThorsten Leemhuiselse 904ab5a5d2SThorsten Leemhuis addout "M" 914ab5a5d2SThorsten Leemhuis echo " * processor reported a Machine Check Exception (MCE) (#4)" 924ab5a5d2SThorsten Leemhuisfi 934ab5a5d2SThorsten Leemhuis 944ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 954ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 964ab5a5d2SThorsten Leemhuis addout " " 974ab5a5d2SThorsten Leemhuiselse 984ab5a5d2SThorsten Leemhuis addout "B" 994ab5a5d2SThorsten Leemhuis echo " * bad page referenced or some unexpected page flags (#5)" 1004ab5a5d2SThorsten Leemhuisfi 1014ab5a5d2SThorsten Leemhuis 1024ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1034ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1044ab5a5d2SThorsten Leemhuis addout " " 1054ab5a5d2SThorsten Leemhuiselse 1064ab5a5d2SThorsten Leemhuis addout "U" 1074ab5a5d2SThorsten Leemhuis echo " * taint requested by userspace application (#6)" 1084ab5a5d2SThorsten Leemhuisfi 1094ab5a5d2SThorsten Leemhuis 1104ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1114ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1124ab5a5d2SThorsten Leemhuis addout " " 1134ab5a5d2SThorsten Leemhuiselse 1144ab5a5d2SThorsten Leemhuis addout "D" 1154ab5a5d2SThorsten Leemhuis echo " * kernel died recently, i.e. there was an OOPS or BUG (#7)" 1164ab5a5d2SThorsten Leemhuisfi 1174ab5a5d2SThorsten Leemhuis 1184ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1194ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1204ab5a5d2SThorsten Leemhuis addout " " 1214ab5a5d2SThorsten Leemhuiselse 1224ab5a5d2SThorsten Leemhuis addout "A" 1234ab5a5d2SThorsten Leemhuis echo " * an ACPI table was overridden by user (#8)" 1244ab5a5d2SThorsten Leemhuisfi 1254ab5a5d2SThorsten Leemhuis 1264ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1274ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1284ab5a5d2SThorsten Leemhuis addout " " 1294ab5a5d2SThorsten Leemhuiselse 1304ab5a5d2SThorsten Leemhuis addout "W" 1314ab5a5d2SThorsten Leemhuis echo " * kernel issued warning (#9)" 1324ab5a5d2SThorsten Leemhuisfi 1334ab5a5d2SThorsten Leemhuis 1344ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1354ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1364ab5a5d2SThorsten Leemhuis addout " " 1374ab5a5d2SThorsten Leemhuiselse 1384ab5a5d2SThorsten Leemhuis addout "C" 1394ab5a5d2SThorsten Leemhuis echo " * staging driver was loaded (#10)" 1404ab5a5d2SThorsten Leemhuisfi 1414ab5a5d2SThorsten Leemhuis 1424ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1434ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1444ab5a5d2SThorsten Leemhuis addout " " 1454ab5a5d2SThorsten Leemhuiselse 1464ab5a5d2SThorsten Leemhuis addout "I" 1474ab5a5d2SThorsten Leemhuis echo " * workaround for bug in platform firmware applied (#11)" 1484ab5a5d2SThorsten Leemhuisfi 1494ab5a5d2SThorsten Leemhuis 1504ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1514ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1524ab5a5d2SThorsten Leemhuis addout " " 1534ab5a5d2SThorsten Leemhuiselse 1544ab5a5d2SThorsten Leemhuis addout "O" 1554ab5a5d2SThorsten Leemhuis echo " * externally-built ('out-of-tree') module was loaded (#12)" 1564ab5a5d2SThorsten Leemhuisfi 1574ab5a5d2SThorsten Leemhuis 1584ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1594ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1604ab5a5d2SThorsten Leemhuis addout " " 1614ab5a5d2SThorsten Leemhuiselse 1624ab5a5d2SThorsten Leemhuis addout "E" 1634ab5a5d2SThorsten Leemhuis echo " * unsigned module was loaded (#13)" 1644ab5a5d2SThorsten Leemhuisfi 1654ab5a5d2SThorsten Leemhuis 1664ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1674ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1684ab5a5d2SThorsten Leemhuis addout " " 1694ab5a5d2SThorsten Leemhuiselse 1704ab5a5d2SThorsten Leemhuis addout "L" 1714ab5a5d2SThorsten Leemhuis echo " * soft lockup occurred (#14)" 1724ab5a5d2SThorsten Leemhuisfi 1734ab5a5d2SThorsten Leemhuis 1744ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1754ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1764ab5a5d2SThorsten Leemhuis addout " " 1774ab5a5d2SThorsten Leemhuiselse 1784ab5a5d2SThorsten Leemhuis addout "K" 1794ab5a5d2SThorsten Leemhuis echo " * kernel has been live patched (#15)" 1804ab5a5d2SThorsten Leemhuisfi 1814ab5a5d2SThorsten Leemhuis 1824ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1834ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1844ab5a5d2SThorsten Leemhuis addout " " 1854ab5a5d2SThorsten Leemhuiselse 1864ab5a5d2SThorsten Leemhuis addout "X" 1874ab5a5d2SThorsten Leemhuis echo " * auxiliary taint, defined for and used by distros (#16)" 1884ab5a5d2SThorsten Leemhuis 1894ab5a5d2SThorsten Leemhuisfi 190*2a2dfc86SJoe Fradley 1914ab5a5d2SThorsten LeemhuisT=`expr $T / 2` 1924ab5a5d2SThorsten Leemhuisif [ `expr $T % 2` -eq 0 ]; then 1934ab5a5d2SThorsten Leemhuis addout " " 1944ab5a5d2SThorsten Leemhuiselse 1954ab5a5d2SThorsten Leemhuis addout "T" 1964ab5a5d2SThorsten Leemhuis echo " * kernel was built with the struct randomization plugin (#17)" 1974ab5a5d2SThorsten Leemhuisfi 1984ab5a5d2SThorsten Leemhuis 199*2a2dfc86SJoe FradleyT=`expr $T / 2` 200*2a2dfc86SJoe Fradleyif [ `expr $T % 2` -eq 0 ]; then 201*2a2dfc86SJoe Fradley addout " " 202*2a2dfc86SJoe Fradleyelse 203*2a2dfc86SJoe Fradley addout "N" 204*2a2dfc86SJoe Fradley echo " * an in-kernel test (such as a KUnit test) has been run (#18)" 205*2a2dfc86SJoe Fradleyfi 206*2a2dfc86SJoe Fradley 2074ab5a5d2SThorsten Leemhuisecho "For a more detailed explanation of the various taint flags see" 208c098564dSColin Ian Kingecho " Documentation/admin-guide/tainted-kernels.rst in the Linux kernel sources" 2094ab5a5d2SThorsten Leemhuisecho " or https://kernel.org/doc/html/latest/admin-guide/tainted-kernels.html" 2104ab5a5d2SThorsten Leemhuisecho "Raw taint value as int/string: $taint/'$out'" 2114ab5a5d2SThorsten Leemhuis#EOF# 212