0220-x86-mm-Remove-preempt_disable-enable-from-__native_f.patch 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. From 5a86516e393d12bb3965342f1f690db319d01241 Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Sat, 30 Dec 2017 22:13:54 +0100
  4. Subject: [PATCH 220/242] x86/mm: Remove preempt_disable/enable() from
  5. __native_flush_tlb()
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. The preempt_disable/enable() pair in __native_flush_tlb() was added in
  11. commit:
  12. 5cf0791da5c1 ("x86/mm: Disable preemption during CR3 read+write")
  13. ... to protect the UP variant of flush_tlb_mm_range().
  14. That preempt_disable/enable() pair should have been added to the UP variant
  15. of flush_tlb_mm_range() instead.
  16. The UP variant was removed with commit:
  17. ce4a4e565f52 ("x86/mm: Remove the UP asm/tlbflush.h code, always use the (formerly) SMP code")
  18. ... but the preempt_disable/enable() pair stayed around.
  19. The latest change to __native_flush_tlb() in commit:
  20. 6fd166aae78c ("x86/mm: Use/Fix PCID to optimize user/kernel switches")
  21. ... added an access to a per CPU variable outside the preempt disabled
  22. regions, which makes no sense at all. __native_flush_tlb() must always
  23. be called with at least preemption disabled.
  24. Remove the preempt_disable/enable() pair and add a WARN_ON_ONCE() to catch
  25. bad callers independent of the smp_processor_id() debugging.
  26. Signed-off-by: Thomas Gleixner <[email protected]>
  27. Cc: <[email protected]>
  28. Cc: Andy Lutomirski <[email protected]>
  29. Cc: Borislav Petkov <[email protected]>
  30. Cc: Dave Hansen <[email protected]>
  31. Cc: Dominik Brodowski <[email protected]>
  32. Cc: Linus Torvalds <[email protected]>
  33. Cc: Linus Torvalds <[email protected]>
  34. Cc: Peter Zijlstra <[email protected]>
  35. Link: http://lkml.kernel.org/r/[email protected]
  36. Signed-off-by: Ingo Molnar <[email protected]>
  37. (cherry picked from commit decab0888e6e14e11d53cefa85f8b3d3b45ce73c)
  38. Signed-off-by: Andy Whitcroft <[email protected]>
  39. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  40. (cherry picked from commit cfcf931c425b60d0092bcb4a4deb1f5d5db0e293)
  41. Signed-off-by: Fabian Grünbichler <[email protected]>
  42. ---
  43. arch/x86/include/asm/tlbflush.h | 14 ++++++++------
  44. 1 file changed, 8 insertions(+), 6 deletions(-)
  45. diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
  46. index 7a04a1f1ca11..ff6a6d668c32 100644
  47. --- a/arch/x86/include/asm/tlbflush.h
  48. +++ b/arch/x86/include/asm/tlbflush.h
  49. @@ -334,15 +334,17 @@ static inline void invalidate_user_asid(u16 asid)
  50. */
  51. static inline void __native_flush_tlb(void)
  52. {
  53. - invalidate_user_asid(this_cpu_read(cpu_tlbstate.loaded_mm_asid));
  54. /*
  55. - * If current->mm == NULL then we borrow a mm which may change
  56. - * during a task switch and therefore we must not be preempted
  57. - * while we write CR3 back:
  58. + * Preemption or interrupts must be disabled to protect the access
  59. + * to the per CPU variable and to prevent being preempted between
  60. + * read_cr3() and write_cr3().
  61. */
  62. - preempt_disable();
  63. + WARN_ON_ONCE(preemptible());
  64. +
  65. + invalidate_user_asid(this_cpu_read(cpu_tlbstate.loaded_mm_asid));
  66. +
  67. + /* If current->mm == NULL then the read_cr3() "borrows" an mm */
  68. native_write_cr3(__native_read_cr3());
  69. - preempt_enable();
  70. }
  71. /*
  72. --
  73. 2.14.2