0175-x86-microcode-Dont-abuse-the-TLB-flush-interface.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. From e80edf9b45a0465ce8fbded75f6d5f218039a67c Mon Sep 17 00:00:00 2001
  2. From: Peter Zijlstra <[email protected]>
  3. Date: Tue, 5 Dec 2017 13:34:51 +0100
  4. Subject: [PATCH 175/242] x86/microcode: Dont abuse the TLB-flush interface
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. Commit:
  10. ec400ddeff20 ("x86/microcode_intel_early.c: Early update ucode on Intel's CPU")
  11. ... grubbed into tlbflush internals without coherent explanation.
  12. Since it says its a precaution and the SDM doesn't mention anything like
  13. this, take it out back.
  14. Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
  15. Signed-off-by: Thomas Gleixner <[email protected]>
  16. Cc: Andy Lutomirski <[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: David Laight <[email protected]>
  22. Cc: Denys Vlasenko <[email protected]>
  23. Cc: Eduardo Valentin <[email protected]>
  24. Cc: Greg KH <[email protected]>
  25. Cc: H. Peter Anvin <[email protected]>
  26. Cc: Josh Poimboeuf <[email protected]>
  27. Cc: Juergen Gross <[email protected]>
  28. Cc: Linus Torvalds <[email protected]>
  29. Cc: Peter Zijlstra <[email protected]>
  30. Cc: Will Deacon <[email protected]>
  31. Cc: [email protected]
  32. Cc: [email protected]
  33. Cc: [email protected]
  34. Cc: [email protected]
  35. Cc: [email protected]
  36. Cc: [email protected]
  37. Signed-off-by: Ingo Molnar <[email protected]>
  38. (cherry picked from commit 23cb7d46f371844c004784ad9552a57446f73e5a)
  39. Signed-off-by: Andy Whitcroft <[email protected]>
  40. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  41. (cherry picked from commit 0f3d96d1e5aa4d9538ab1a918fb49f2c57ebb6f5)
  42. Signed-off-by: Fabian Grünbichler <[email protected]>
  43. ---
  44. arch/x86/include/asm/tlbflush.h | 19 ++++++-------------
  45. arch/x86/kernel/cpu/microcode/intel.c | 13 -------------
  46. 2 files changed, 6 insertions(+), 26 deletions(-)
  47. diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
  48. index 6533da3036c9..6d2688a6fda0 100644
  49. --- a/arch/x86/include/asm/tlbflush.h
  50. +++ b/arch/x86/include/asm/tlbflush.h
  51. @@ -234,20 +234,9 @@ static inline void __native_flush_tlb(void)
  52. preempt_enable();
  53. }
  54. -static inline void __native_flush_tlb_global_irq_disabled(void)
  55. -{
  56. - unsigned long cr4;
  57. -
  58. - cr4 = this_cpu_read(cpu_tlbstate.cr4);
  59. - /* clear PGE */
  60. - native_write_cr4(cr4 & ~X86_CR4_PGE);
  61. - /* write old PGE again and flush TLBs */
  62. - native_write_cr4(cr4);
  63. -}
  64. -
  65. static inline void __native_flush_tlb_global(void)
  66. {
  67. - unsigned long flags;
  68. + unsigned long cr4, flags;
  69. if (static_cpu_has(X86_FEATURE_INVPCID)) {
  70. /*
  71. @@ -265,7 +254,11 @@ static inline void __native_flush_tlb_global(void)
  72. */
  73. raw_local_irq_save(flags);
  74. - __native_flush_tlb_global_irq_disabled();
  75. + cr4 = this_cpu_read(cpu_tlbstate.cr4);
  76. + /* toggle PGE */
  77. + native_write_cr4(cr4 ^ X86_CR4_PGE);
  78. + /* write old PGE again and flush TLBs */
  79. + native_write_cr4(cr4);
  80. raw_local_irq_restore(flags);
  81. }
  82. diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
  83. index 636a5fcfdeb7..d9a8f69101aa 100644
  84. --- a/arch/x86/kernel/cpu/microcode/intel.c
  85. +++ b/arch/x86/kernel/cpu/microcode/intel.c
  86. @@ -564,15 +564,6 @@ static void print_ucode(struct ucode_cpu_info *uci)
  87. }
  88. #else
  89. -/*
  90. - * Flush global tlb. We only do this in x86_64 where paging has been enabled
  91. - * already and PGE should be enabled as well.
  92. - */
  93. -static inline void flush_tlb_early(void)
  94. -{
  95. - __native_flush_tlb_global_irq_disabled();
  96. -}
  97. -
  98. static inline void print_ucode(struct ucode_cpu_info *uci)
  99. {
  100. struct microcode_intel *mc;
  101. @@ -601,10 +592,6 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
  102. if (rev != mc->hdr.rev)
  103. return -1;
  104. -#ifdef CONFIG_X86_64
  105. - /* Flush global tlb. This is precaution. */
  106. - flush_tlb_early();
  107. -#endif
  108. uci->cpu_sig.rev = rev;
  109. if (early)
  110. --
  111. 2.14.2