spec_ctrl.rst 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. ===================
  2. Speculation Control
  3. ===================
  4. Quite some CPUs have speculation-related misfeatures which are in
  5. fact vulnerabilities causing data leaks in various forms even across
  6. privilege domains.
  7. The kernel provides mitigation for such vulnerabilities in various
  8. forms. Some of these mitigations are compile-time configurable and some
  9. can be supplied on the kernel command line.
  10. There is also a class of mitigations which are very expensive, but they can
  11. be restricted to a certain set of processes or tasks in controlled
  12. environments. The mechanism to control these mitigations is via
  13. :manpage:`prctl(2)`.
  14. There are two prctl options which are related to this:
  15. * PR_GET_SPECULATION_CTRL
  16. * PR_SET_SPECULATION_CTRL
  17. PR_GET_SPECULATION_CTRL
  18. -----------------------
  19. PR_GET_SPECULATION_CTRL returns the state of the speculation misfeature
  20. which is selected with arg2 of prctl(2). The return value uses bits 0-3 with
  21. the following meaning:
  22. ==== ====================== ==================================================
  23. Bit Define Description
  24. ==== ====================== ==================================================
  25. 0 PR_SPEC_PRCTL Mitigation can be controlled per task by
  26. PR_SET_SPECULATION_CTRL.
  27. 1 PR_SPEC_ENABLE The speculation feature is enabled, mitigation is
  28. disabled.
  29. 2 PR_SPEC_DISABLE The speculation feature is disabled, mitigation is
  30. enabled.
  31. 3 PR_SPEC_FORCE_DISABLE Same as PR_SPEC_DISABLE, but cannot be undone. A
  32. subsequent prctl(..., PR_SPEC_ENABLE) will fail.
  33. 4 PR_SPEC_DISABLE_NOEXEC Same as PR_SPEC_DISABLE, but the state will be
  34. cleared on :manpage:`execve(2)`.
  35. ==== ====================== ==================================================
  36. If all bits are 0 the CPU is not affected by the speculation misfeature.
  37. If PR_SPEC_PRCTL is set, then the per-task control of the mitigation is
  38. available. If not set, prctl(PR_SET_SPECULATION_CTRL) for the speculation
  39. misfeature will fail.
  40. .. _set_spec_ctrl:
  41. PR_SET_SPECULATION_CTRL
  42. -----------------------
  43. PR_SET_SPECULATION_CTRL allows to control the speculation misfeature, which
  44. is selected by arg2 of :manpage:`prctl(2)` per task. arg3 is used to hand
  45. in the control value, i.e. either PR_SPEC_ENABLE or PR_SPEC_DISABLE or
  46. PR_SPEC_FORCE_DISABLE.
  47. Common error codes
  48. ------------------
  49. ======= =================================================================
  50. Value Meaning
  51. ======= =================================================================
  52. EINVAL The prctl is not implemented by the architecture or unused
  53. prctl(2) arguments are not 0.
  54. ENODEV arg2 is selecting a not supported speculation misfeature.
  55. ======= =================================================================
  56. PR_SET_SPECULATION_CTRL error codes
  57. -----------------------------------
  58. ======= =================================================================
  59. Value Meaning
  60. ======= =================================================================
  61. 0 Success
  62. ERANGE arg3 is incorrect, i.e. it's neither PR_SPEC_ENABLE nor
  63. PR_SPEC_DISABLE nor PR_SPEC_FORCE_DISABLE.
  64. ENXIO Control of the selected speculation misfeature is not possible.
  65. See PR_GET_SPECULATION_CTRL.
  66. EPERM Speculation was disabled with PR_SPEC_FORCE_DISABLE and caller
  67. tried to enable it again.
  68. ======= =================================================================
  69. Speculation misfeature controls
  70. -------------------------------
  71. - PR_SPEC_STORE_BYPASS: Speculative Store Bypass
  72. Invocations:
  73. * prctl(PR_GET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, 0, 0, 0);
  74. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_ENABLE, 0, 0);
  75. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);
  76. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_FORCE_DISABLE, 0, 0);
  77. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE_NOEXEC, 0, 0);
  78. - PR_SPEC_INDIR_BRANCH: Indirect Branch Speculation in User Processes
  79. (Mitigate Spectre V2 style attacks against user processes)
  80. Invocations:
  81. * prctl(PR_GET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH, 0, 0, 0);
  82. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH, PR_SPEC_ENABLE, 0, 0);
  83. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH, PR_SPEC_DISABLE, 0, 0);
  84. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH, PR_SPEC_FORCE_DISABLE, 0, 0);
  85. - PR_SPEC_L1D_FLUSH: Flush L1D Cache on context switch out of the task
  86. (works only when tasks run on non SMT cores)
  87. Invocations:
  88. * prctl(PR_GET_SPECULATION_CTRL, PR_SPEC_L1D_FLUSH, 0, 0, 0);
  89. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_L1D_FLUSH, PR_SPEC_ENABLE, 0, 0);
  90. * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_L1D_FLUSH, PR_SPEC_DISABLE, 0, 0);