0191-x86-pti-Add-the-pti-cmdline-option-and-documentation.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. From d6b6a8fa92efd244f759ab8ded4ccaebac2b762c Mon Sep 17 00:00:00 2001
  2. From: Borislav Petkov <[email protected]>
  3. Date: Tue, 12 Dec 2017 14:39:52 +0100
  4. Subject: [PATCH 191/232] x86/pti: Add the pti= cmdline option and
  5. documentation
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. Keep the "nopti" optional for traditional reasons.
  11. [ tglx: Don't allow force on when running on XEN PV and made 'on'
  12. printout conditional ]
  13. Requested-by: Linus Torvalds <[email protected]>
  14. Signed-off-by: Borislav Petkov <[email protected]>
  15. Signed-off-by: Thomas Gleixner <[email protected]>
  16. Cc: Andy Lutomirski <[email protected]>
  17. Cc: Andy Lutomirsky <[email protected]>
  18. Cc: Boris Ostrovsky <[email protected]>
  19. Cc: Borislav Petkov <[email protected]>
  20. Cc: Brian Gerst <[email protected]>
  21. Cc: Dave Hansen <[email protected]>
  22. Cc: Dave Hansen <[email protected]>
  23. Cc: David Laight <[email protected]>
  24. Cc: Denys Vlasenko <[email protected]>
  25. Cc: Eduardo Valentin <[email protected]>
  26. Cc: Greg KH <[email protected]>
  27. Cc: H. Peter Anvin <[email protected]>
  28. Cc: Josh Poimboeuf <[email protected]>
  29. Cc: Juergen Gross <[email protected]>
  30. Cc: Linus Torvalds <[email protected]>
  31. Cc: Peter Zijlstra <[email protected]>
  32. Cc: Will Deacon <[email protected]>
  33. Cc: [email protected]
  34. Cc: [email protected]
  35. Cc: [email protected]
  36. Cc: [email protected]
  37. Link: https://lkml.kernel.org/r/[email protected]
  38. Signed-off-by: Ingo Molnar <[email protected]>
  39. (cherry picked from commit 41f4c20b57a4890ea7f56ff8717cc83fefb8d537)
  40. Signed-off-by: Andy Whitcroft <[email protected]>
  41. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  42. (cherry picked from commit 96d3670fa8f88989fb7c0be5172a1378143f3296)
  43. Signed-off-by: Fabian Grünbichler <[email protected]>
  44. ---
  45. Documentation/admin-guide/kernel-parameters.txt | 6 ++++++
  46. arch/x86/mm/pti.c | 26 ++++++++++++++++++++++++-
  47. 2 files changed, 31 insertions(+), 1 deletion(-)
  48. diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
  49. index e2a4608da5d2..b4d2edf316db 100644
  50. --- a/Documentation/admin-guide/kernel-parameters.txt
  51. +++ b/Documentation/admin-guide/kernel-parameters.txt
  52. @@ -3247,6 +3247,12 @@
  53. pt. [PARIDE]
  54. See Documentation/blockdev/paride.txt.
  55. + pti= [X86_64]
  56. + Control user/kernel address space isolation:
  57. + on - enable
  58. + off - disable
  59. + auto - default setting
  60. +
  61. pty.legacy_count=
  62. [KNL] Number of legacy pty's. Overwrites compiled-in
  63. default number.
  64. diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
  65. index 375f23a758bc..a13f6b109865 100644
  66. --- a/arch/x86/mm/pti.c
  67. +++ b/arch/x86/mm/pti.c
  68. @@ -54,21 +54,45 @@ static void __init pti_print_if_insecure(const char *reason)
  69. pr_info("%s\n", reason);
  70. }
  71. +static void __init pti_print_if_secure(const char *reason)
  72. +{
  73. + if (!boot_cpu_has_bug(X86_BUG_CPU_INSECURE))
  74. + pr_info("%s\n", reason);
  75. +}
  76. +
  77. void __init pti_check_boottime_disable(void)
  78. {
  79. + char arg[5];
  80. + int ret;
  81. +
  82. if (hypervisor_is_type(X86_HYPER_XEN_PV)) {
  83. pti_print_if_insecure("disabled on XEN PV.");
  84. return;
  85. }
  86. + ret = cmdline_find_option(boot_command_line, "pti", arg, sizeof(arg));
  87. + if (ret > 0) {
  88. + if (ret == 3 && !strncmp(arg, "off", 3)) {
  89. + pti_print_if_insecure("disabled on command line.");
  90. + return;
  91. + }
  92. + if (ret == 2 && !strncmp(arg, "on", 2)) {
  93. + pti_print_if_secure("force enabled on command line.");
  94. + goto enable;
  95. + }
  96. + if (ret == 4 && !strncmp(arg, "auto", 4))
  97. + goto autosel;
  98. + }
  99. +
  100. if (cmdline_find_option_bool(boot_command_line, "nopti")) {
  101. pti_print_if_insecure("disabled on command line.");
  102. return;
  103. }
  104. +autosel:
  105. if (!boot_cpu_has_bug(X86_BUG_CPU_INSECURE))
  106. return;
  107. -
  108. +enable:
  109. setup_force_cpu_cap(X86_FEATURE_PTI);
  110. }
  111. --
  112. 2.14.2