1*4882a593SmuzhiyunTainted kernels 2*4882a593Smuzhiyun--------------- 3*4882a593Smuzhiyun 4*4882a593SmuzhiyunThe kernel will mark itself as 'tainted' when something occurs that might be 5*4882a593Smuzhiyunrelevant later when investigating problems. Don't worry too much about this, 6*4882a593Smuzhiyunmost of the time it's not a problem to run a tainted kernel; the information is 7*4882a593Smuzhiyunmainly of interest once someone wants to investigate some problem, as its real 8*4882a593Smuzhiyuncause might be the event that got the kernel tainted. That's why bug reports 9*4882a593Smuzhiyunfrom tainted kernels will often be ignored by developers, hence try to reproduce 10*4882a593Smuzhiyunproblems with an untainted kernel. 11*4882a593Smuzhiyun 12*4882a593SmuzhiyunNote the kernel will remain tainted even after you undo what caused the taint 13*4882a593Smuzhiyun(i.e. unload a proprietary kernel module), to indicate the kernel remains not 14*4882a593Smuzhiyuntrustworthy. That's also why the kernel will print the tainted state when it 15*4882a593Smuzhiyunnotices an internal problem (a 'kernel bug'), a recoverable error 16*4882a593Smuzhiyun('kernel oops') or a non-recoverable error ('kernel panic') and writes debug 17*4882a593Smuzhiyuninformation about this to the logs ``dmesg`` outputs. It's also possible to 18*4882a593Smuzhiyuncheck the tainted state at runtime through a file in ``/proc/``. 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunTainted flag in bugs, oops or panics messages 22*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunYou find the tainted state near the top in a line starting with 'CPU:'; if or 25*4882a593Smuzhiyunwhy the kernel was tainted is shown after the Process ID ('PID:') and a shortened 26*4882a593Smuzhiyunname of the command ('Comm:') that triggered the event:: 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 29*4882a593Smuzhiyun Oops: 0002 [#1] SMP PTI 30*4882a593Smuzhiyun CPU: 0 PID: 4424 Comm: insmod Tainted: P W O 4.20.0-0.rc6.fc30 #1 31*4882a593Smuzhiyun Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 32*4882a593Smuzhiyun RIP: 0010:my_oops_init+0x13/0x1000 [kpanic] 33*4882a593Smuzhiyun [...] 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunYou'll find a 'Not tainted: ' there if the kernel was not tainted at the 36*4882a593Smuzhiyuntime of the event; if it was, then it will print 'Tainted: ' and characters 37*4882a593Smuzhiyuneither letters or blanks. In above example it looks like this:: 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun Tainted: P W O 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunThe meaning of those characters is explained in the table below. In this case 42*4882a593Smuzhiyunthe kernel got tainted earlier because a proprietary Module (``P``) was loaded, 43*4882a593Smuzhiyuna warning occurred (``W``), and an externally-built module was loaded (``O``). 44*4882a593SmuzhiyunTo decode other letters use the table below. 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunDecoding tainted state at runtime 48*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 49*4882a593Smuzhiyun 50*4882a593SmuzhiyunAt runtime, you can query the tainted state by reading 51*4882a593Smuzhiyun``cat /proc/sys/kernel/tainted``. If that returns ``0``, the kernel is not 52*4882a593Smuzhiyuntainted; any other number indicates the reasons why it is. The easiest way to 53*4882a593Smuzhiyundecode that number is the script ``tools/debugging/kernel-chktaint``, which your 54*4882a593Smuzhiyundistribution might ship as part of a package called ``linux-tools`` or 55*4882a593Smuzhiyun``kernel-tools``; if it doesn't you can download the script from 56*4882a593Smuzhiyun`git.kernel.org <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/tools/debugging/kernel-chktaint>`_ 57*4882a593Smuzhiyunand execute it with ``sh kernel-chktaint``, which would print something like 58*4882a593Smuzhiyunthis on the machine that had the statements in the logs that were quoted earlier:: 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun Kernel is Tainted for following reasons: 61*4882a593Smuzhiyun * Proprietary module was loaded (#0) 62*4882a593Smuzhiyun * Kernel issued warning (#9) 63*4882a593Smuzhiyun * Externally-built ('out-of-tree') module was loaded (#12) 64*4882a593Smuzhiyun See Documentation/admin-guide/tainted-kernels.rst in the Linux kernel or 65*4882a593Smuzhiyun https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html for 66*4882a593Smuzhiyun a more details explanation of the various taint flags. 67*4882a593Smuzhiyun Raw taint value as int/string: 4609/'P W O ' 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunYou can try to decode the number yourself. That's easy if there was only one 70*4882a593Smuzhiyunreason that got your kernel tainted, as in this case you can find the number 71*4882a593Smuzhiyunwith the table below. If there were multiple reasons you need to decode the 72*4882a593Smuzhiyunnumber, as it is a bitfield, where each bit indicates the absence or presence of 73*4882a593Smuzhiyuna particular type of taint. It's best to leave that to the aforementioned 74*4882a593Smuzhiyunscript, but if you need something quick you can use this shell command to check 75*4882a593Smuzhiyunwhich bits are set:: 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun $ for i in $(seq 18); do echo $(($i-1)) $(($(cat /proc/sys/kernel/tainted)>>($i-1)&1));done 78*4882a593Smuzhiyun 79*4882a593SmuzhiyunTable for decoding tainted state 80*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun=== === ====== ======================================================== 83*4882a593SmuzhiyunBit Log Number Reason that got the kernel tainted 84*4882a593Smuzhiyun=== === ====== ======================================================== 85*4882a593Smuzhiyun 0 G/P 1 proprietary module was loaded 86*4882a593Smuzhiyun 1 _/F 2 module was force loaded 87*4882a593Smuzhiyun 2 _/S 4 SMP kernel oops on an officially SMP incapable processor 88*4882a593Smuzhiyun 3 _/R 8 module was force unloaded 89*4882a593Smuzhiyun 4 _/M 16 processor reported a Machine Check Exception (MCE) 90*4882a593Smuzhiyun 5 _/B 32 bad page referenced or some unexpected page flags 91*4882a593Smuzhiyun 6 _/U 64 taint requested by userspace application 92*4882a593Smuzhiyun 7 _/D 128 kernel died recently, i.e. there was an OOPS or BUG 93*4882a593Smuzhiyun 8 _/A 256 ACPI table overridden by user 94*4882a593Smuzhiyun 9 _/W 512 kernel issued warning 95*4882a593Smuzhiyun 10 _/C 1024 staging driver was loaded 96*4882a593Smuzhiyun 11 _/I 2048 workaround for bug in platform firmware applied 97*4882a593Smuzhiyun 12 _/O 4096 externally-built ("out-of-tree") module was loaded 98*4882a593Smuzhiyun 13 _/E 8192 unsigned module was loaded 99*4882a593Smuzhiyun 14 _/L 16384 soft lockup occurred 100*4882a593Smuzhiyun 15 _/K 32768 kernel has been live patched 101*4882a593Smuzhiyun 16 _/X 65536 auxiliary taint, defined for and used by distros 102*4882a593Smuzhiyun 17 _/T 131072 kernel was built with the struct randomization plugin 103*4882a593Smuzhiyun=== === ====== ======================================================== 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunNote: The character ``_`` is representing a blank in this table to make reading 106*4882a593Smuzhiyuneasier. 107*4882a593Smuzhiyun 108*4882a593SmuzhiyunMore detailed explanation for tainting 109*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun 0) ``G`` if all modules loaded have a GPL or compatible license, ``P`` if 112*4882a593Smuzhiyun any proprietary module has been loaded. Modules without a 113*4882a593Smuzhiyun MODULE_LICENSE or with a MODULE_LICENSE that is not recognised by 114*4882a593Smuzhiyun insmod as GPL compatible are assumed to be proprietary. 115*4882a593Smuzhiyun 116*4882a593Smuzhiyun 1) ``F`` if any module was force loaded by ``insmod -f``, ``' '`` if all 117*4882a593Smuzhiyun modules were loaded normally. 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun 2) ``S`` if the oops occurred on an SMP kernel running on hardware that 120*4882a593Smuzhiyun hasn't been certified as safe to run multiprocessor. 121*4882a593Smuzhiyun Currently this occurs only on various Athlons that are not 122*4882a593Smuzhiyun SMP capable. 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun 3) ``R`` if a module was force unloaded by ``rmmod -f``, ``' '`` if all 125*4882a593Smuzhiyun modules were unloaded normally. 126*4882a593Smuzhiyun 127*4882a593Smuzhiyun 4) ``M`` if any processor has reported a Machine Check Exception, 128*4882a593Smuzhiyun ``' '`` if no Machine Check Exceptions have occurred. 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun 5) ``B`` If a page-release function has found a bad page reference or some 131*4882a593Smuzhiyun unexpected page flags. This indicates a hardware problem or a kernel bug; 132*4882a593Smuzhiyun there should be other information in the log indicating why this tainting 133*4882a593Smuzhiyun occurred. 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun 6) ``U`` if a user or user application specifically requested that the 136*4882a593Smuzhiyun Tainted flag be set, ``' '`` otherwise. 137*4882a593Smuzhiyun 138*4882a593Smuzhiyun 7) ``D`` if the kernel has died recently, i.e. there was an OOPS or BUG. 139*4882a593Smuzhiyun 140*4882a593Smuzhiyun 8) ``A`` if an ACPI table has been overridden. 141*4882a593Smuzhiyun 142*4882a593Smuzhiyun 9) ``W`` if a warning has previously been issued by the kernel. 143*4882a593Smuzhiyun (Though some warnings may set more specific taint flags.) 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun 10) ``C`` if a staging driver has been loaded. 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun 11) ``I`` if the kernel is working around a severe bug in the platform 148*4882a593Smuzhiyun firmware (BIOS or similar). 149*4882a593Smuzhiyun 150*4882a593Smuzhiyun 12) ``O`` if an externally-built ("out-of-tree") module has been loaded. 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun 13) ``E`` if an unsigned module has been loaded in a kernel supporting 153*4882a593Smuzhiyun module signature. 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun 14) ``L`` if a soft lockup has previously occurred on the system. 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun 15) ``K`` if the kernel has been live patched. 158*4882a593Smuzhiyun 159*4882a593Smuzhiyun 16) ``X`` Auxiliary taint, defined for and used by Linux distributors. 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun 17) ``T`` Kernel was build with the randstruct plugin, which can intentionally 162*4882a593Smuzhiyun produce extremely unusual kernel structure layouts (even performance 163*4882a593Smuzhiyun pathological ones), which is important to know when debugging. Set at 164*4882a593Smuzhiyun build time. 165