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