0187-x86-cpufeatures-Add-X86_BUG_CPU_INSECURE.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. From 05be4302d695b8676c90b26abe0495df58602685 Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Mon, 4 Dec 2017 15:07:33 +0100
  4. Subject: [PATCH 187/242] x86/cpufeatures: Add X86_BUG_CPU_INSECURE
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. Many x86 CPUs leak information to user space due to missing isolation of
  10. user space and kernel space page tables. There are many well documented
  11. ways to exploit that.
  12. The upcoming software migitation of isolating the user and kernel space
  13. page tables needs a misfeature flag so code can be made runtime
  14. conditional.
  15. Add the BUG bits which indicates that the CPU is affected and add a feature
  16. bit which indicates that the software migitation is enabled.
  17. Assume for now that _ALL_ x86 CPUs are affected by this. Exceptions can be
  18. made later.
  19. Signed-off-by: Thomas Gleixner <[email protected]>
  20. Cc: Andy Lutomirski <[email protected]>
  21. Cc: Boris Ostrovsky <[email protected]>
  22. Cc: Borislav Petkov <[email protected]>
  23. Cc: Brian Gerst <[email protected]>
  24. Cc: Dave Hansen <[email protected]>
  25. Cc: David Laight <[email protected]>
  26. Cc: Denys Vlasenko <[email protected]>
  27. Cc: Eduardo Valentin <[email protected]>
  28. Cc: Greg KH <[email protected]>
  29. Cc: H. Peter Anvin <[email protected]>
  30. Cc: Josh Poimboeuf <[email protected]>
  31. Cc: Juergen Gross <[email protected]>
  32. Cc: Linus Torvalds <[email protected]>
  33. Cc: Peter Zijlstra <[email protected]>
  34. Cc: Will Deacon <[email protected]>
  35. Cc: [email protected]
  36. Cc: [email protected]
  37. Cc: [email protected]
  38. Cc: [email protected]
  39. Signed-off-by: Ingo Molnar <[email protected]>
  40. (cherry picked from commit a89f040fa34ec9cd682aed98b8f04e3c47d998bd)
  41. Signed-off-by: Andy Whitcroft <[email protected]>
  42. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  43. (cherry picked from commit 3b0dffb3557f6a1084a2b92ac0cc2d36b5e1f39f)
  44. Signed-off-by: Fabian Grünbichler <[email protected]>
  45. ---
  46. arch/x86/include/asm/cpufeatures.h | 3 ++-
  47. arch/x86/include/asm/disabled-features.h | 8 +++++++-
  48. arch/x86/kernel/cpu/common.c | 4 ++++
  49. 3 files changed, 13 insertions(+), 2 deletions(-)
  50. diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
  51. index d57a174ec97c..de4e91452de4 100644
  52. --- a/arch/x86/include/asm/cpufeatures.h
  53. +++ b/arch/x86/include/asm/cpufeatures.h
  54. @@ -200,7 +200,7 @@
  55. #define X86_FEATURE_HW_PSTATE ( 7*32+ 8) /* AMD HW-PState */
  56. #define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */
  57. #define X86_FEATURE_SME ( 7*32+10) /* AMD Secure Memory Encryption */
  58. -
  59. +#define X86_FEATURE_PTI ( 7*32+11) /* Kernel Page Table Isolation enabled */
  60. #define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */
  61. #define X86_FEATURE_INTEL_PT ( 7*32+15) /* Intel Processor Trace */
  62. #define X86_FEATURE_AVX512_4VNNIW ( 7*32+16) /* AVX-512 Neural Network Instructions */
  63. @@ -339,5 +339,6 @@
  64. #define X86_BUG_SWAPGS_FENCE X86_BUG(11) /* SWAPGS without input dep on GS */
  65. #define X86_BUG_MONITOR X86_BUG(12) /* IPI required to wake up remote CPU */
  66. #define X86_BUG_AMD_E400 X86_BUG(13) /* CPU is among the affected by Erratum 400 */
  67. +#define X86_BUG_CPU_INSECURE X86_BUG(14) /* CPU is insecure and needs kernel page table isolation */
  68. #endif /* _ASM_X86_CPUFEATURES_H */
  69. diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h
  70. index 5dff775af7cd..db681152f024 100644
  71. --- a/arch/x86/include/asm/disabled-features.h
  72. +++ b/arch/x86/include/asm/disabled-features.h
  73. @@ -42,6 +42,12 @@
  74. # define DISABLE_LA57 (1<<(X86_FEATURE_LA57 & 31))
  75. #endif
  76. +#ifdef CONFIG_PAGE_TABLE_ISOLATION
  77. +# define DISABLE_PTI 0
  78. +#else
  79. +# define DISABLE_PTI (1 << (X86_FEATURE_PTI & 31))
  80. +#endif
  81. +
  82. /*
  83. * Make sure to add features to the correct mask
  84. */
  85. @@ -52,7 +58,7 @@
  86. #define DISABLED_MASK4 0
  87. #define DISABLED_MASK5 0
  88. #define DISABLED_MASK6 0
  89. -#define DISABLED_MASK7 0
  90. +#define DISABLED_MASK7 (DISABLE_PTI)
  91. #define DISABLED_MASK8 0
  92. #define DISABLED_MASK9 (DISABLE_MPX)
  93. #define DISABLED_MASK10 0
  94. diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
  95. index 96171ce46d61..623ba3635793 100644
  96. --- a/arch/x86/kernel/cpu/common.c
  97. +++ b/arch/x86/kernel/cpu/common.c
  98. @@ -898,6 +898,10 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
  99. }
  100. setup_force_cpu_cap(X86_FEATURE_ALWAYS);
  101. +
  102. + /* Assume for now that ALL x86 CPUs are insecure */
  103. + setup_force_cpu_bug(X86_BUG_CPU_INSECURE);
  104. +
  105. fpu__init_system(c);
  106. }
  107. --
  108. 2.14.2