0185-init-Invoke-init_espfix_bsp-from-mm_init.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. From a6bd428da9f8bbc467b119ef5dc9ad4a1fb58acc Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Sun, 17 Dec 2017 10:56:29 +0100
  4. Subject: [PATCH 185/242] init: Invoke init_espfix_bsp() from mm_init()
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. init_espfix_bsp() needs to be invoked before the page table isolation
  10. initialization. Move it into mm_init() which is the place where pti_init()
  11. will be added.
  12. While at it get rid of the #ifdeffery and provide proper stub functions.
  13. Signed-off-by: Thomas Gleixner <[email protected]>
  14. Cc: Andy Lutomirski <[email protected]>
  15. Cc: Borislav Petkov <[email protected]>
  16. Cc: Dave Hansen <[email protected]>
  17. Cc: H. Peter Anvin <[email protected]>
  18. Cc: Josh Poimboeuf <[email protected]>
  19. Cc: Juergen Gross <[email protected]>
  20. Cc: Linus Torvalds <[email protected]>
  21. Cc: Peter Zijlstra <[email protected]>
  22. Signed-off-by: Ingo Molnar <[email protected]>
  23. (cherry picked from commit 613e396bc0d4c7604fba23256644e78454c68cf6)
  24. Signed-off-by: Andy Whitcroft <[email protected]>
  25. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  26. (cherry picked from commit a187e1a3cd87c860a8db188991d2d43fedd7225f)
  27. Signed-off-by: Fabian Grünbichler <[email protected]>
  28. ---
  29. arch/x86/include/asm/espfix.h | 7 ++++---
  30. include/asm-generic/pgtable.h | 5 +++++
  31. arch/x86/kernel/smpboot.c | 6 +-----
  32. init/main.c | 6 ++----
  33. 4 files changed, 12 insertions(+), 12 deletions(-)
  34. diff --git a/arch/x86/include/asm/espfix.h b/arch/x86/include/asm/espfix.h
  35. index ca3ce9ab9385..e7009ac975af 100644
  36. --- a/arch/x86/include/asm/espfix.h
  37. +++ b/arch/x86/include/asm/espfix.h
  38. @@ -1,7 +1,7 @@
  39. #ifndef _ASM_X86_ESPFIX_H
  40. #define _ASM_X86_ESPFIX_H
  41. -#ifdef CONFIG_X86_64
  42. +#ifdef CONFIG_X86_ESPFIX64
  43. #include <asm/percpu.h>
  44. @@ -10,7 +10,8 @@ DECLARE_PER_CPU_READ_MOSTLY(unsigned long, espfix_waddr);
  45. extern void init_espfix_bsp(void);
  46. extern void init_espfix_ap(int cpu);
  47. -
  48. -#endif /* CONFIG_X86_64 */
  49. +#else
  50. +static inline void init_espfix_ap(int cpu) { }
  51. +#endif
  52. #endif /* _ASM_X86_ESPFIX_H */
  53. diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
  54. index 7dfa767dc680..1bab3cfc0601 100644
  55. --- a/include/asm-generic/pgtable.h
  56. +++ b/include/asm-generic/pgtable.h
  57. @@ -956,6 +956,11 @@ static inline int pmd_clear_huge(pmd_t *pmd)
  58. struct file;
  59. int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
  60. unsigned long size, pgprot_t *vma_prot);
  61. +
  62. +#ifndef CONFIG_X86_ESPFIX64
  63. +static inline void init_espfix_bsp(void) { }
  64. +#endif
  65. +
  66. #endif /* !__ASSEMBLY__ */
  67. #ifndef io_remap_pfn_range
  68. diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
  69. index 8ea3b18cbdc1..03d2ba2da3b0 100644
  70. --- a/arch/x86/kernel/smpboot.c
  71. +++ b/arch/x86/kernel/smpboot.c
  72. @@ -989,12 +989,8 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle,
  73. initial_code = (unsigned long)start_secondary;
  74. initial_stack = idle->thread.sp;
  75. - /*
  76. - * Enable the espfix hack for this CPU
  77. - */
  78. -#ifdef CONFIG_X86_ESPFIX64
  79. + /* Enable the espfix hack for this CPU */
  80. init_espfix_ap(cpu);
  81. -#endif
  82. /* So we see what's up */
  83. announce_cpu(cpu, apicid);
  84. diff --git a/init/main.c b/init/main.c
  85. index 83d1004e3b97..de1c495da782 100644
  86. --- a/init/main.c
  87. +++ b/init/main.c
  88. @@ -504,6 +504,8 @@ static void __init mm_init(void)
  89. pgtable_init();
  90. vmalloc_init();
  91. ioremap_huge_init();
  92. + /* Should be run before the first non-init thread is created */
  93. + init_espfix_bsp();
  94. }
  95. asmlinkage __visible void __init start_kernel(void)
  96. @@ -664,10 +666,6 @@ asmlinkage __visible void __init start_kernel(void)
  97. #ifdef CONFIG_X86
  98. if (efi_enabled(EFI_RUNTIME_SERVICES))
  99. efi_enter_virtual_mode();
  100. -#endif
  101. -#ifdef CONFIG_X86_ESPFIX64
  102. - /* Should be run before the first non-init thread is created */
  103. - init_espfix_bsp();
  104. #endif
  105. thread_stack_cache_init();
  106. cred_init();
  107. --
  108. 2.14.2