tainted-kernels.rst 7.6 KB

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