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

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