0198-x86-mm-pti-Share-cpu_entry_area-with-user-space-page.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. From 0e6d8e0cd5b1439d97f56445aef57d8839580b33 Mon Sep 17 00:00:00 2001
  2. From: Andy Lutomirski <[email protected]>
  3. Date: Mon, 4 Dec 2017 15:07:45 +0100
  4. Subject: [PATCH 198/242] x86/mm/pti: Share cpu_entry_area with user space page
  5. tables
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. Share the cpu entry area so the user space and kernel space page tables
  11. have the same P4D page.
  12. Signed-off-by: Andy Lutomirski <[email protected]>
  13. Signed-off-by: Thomas Gleixner <[email protected]>
  14. Cc: Boris Ostrovsky <[email protected]>
  15. Cc: Borislav Petkov <[email protected]>
  16. Cc: Brian Gerst <[email protected]>
  17. Cc: Dave Hansen <[email protected]>
  18. Cc: David Laight <[email protected]>
  19. Cc: Denys Vlasenko <[email protected]>
  20. Cc: Eduardo Valentin <[email protected]>
  21. Cc: Greg KH <[email protected]>
  22. Cc: H. Peter Anvin <[email protected]>
  23. Cc: Josh Poimboeuf <[email protected]>
  24. Cc: Juergen Gross <[email protected]>
  25. Cc: Linus Torvalds <[email protected]>
  26. Cc: Peter Zijlstra <[email protected]>
  27. Cc: Will Deacon <[email protected]>
  28. Cc: [email protected]
  29. Cc: [email protected]
  30. Cc: [email protected]
  31. Cc: [email protected]
  32. Signed-off-by: Ingo Molnar <[email protected]>
  33. (cherry picked from commit f7cfbee91559ca7e3e961a00ffac921208a115ad)
  34. Signed-off-by: Andy Whitcroft <[email protected]>
  35. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  36. (cherry picked from commit 6e8142de3a6e84a82a421b66a74ba37976912282)
  37. Signed-off-by: Fabian Grünbichler <[email protected]>
  38. ---
  39. arch/x86/mm/pti.c | 25 +++++++++++++++++++++++++
  40. 1 file changed, 25 insertions(+)
  41. diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
  42. index d58bcee470fc..59290356f19f 100644
  43. --- a/arch/x86/mm/pti.c
  44. +++ b/arch/x86/mm/pti.c
  45. @@ -264,6 +264,29 @@ pti_clone_pmds(unsigned long start, unsigned long end, pmdval_t clear)
  46. }
  47. }
  48. +/*
  49. + * Clone a single p4d (i.e. a top-level entry on 4-level systems and a
  50. + * next-level entry on 5-level systems.
  51. + */
  52. +static void __init pti_clone_p4d(unsigned long addr)
  53. +{
  54. + p4d_t *kernel_p4d, *user_p4d;
  55. + pgd_t *kernel_pgd;
  56. +
  57. + user_p4d = pti_user_pagetable_walk_p4d(addr);
  58. + kernel_pgd = pgd_offset_k(addr);
  59. + kernel_p4d = p4d_offset(kernel_pgd, addr);
  60. + *user_p4d = *kernel_p4d;
  61. +}
  62. +
  63. +/*
  64. + * Clone the CPU_ENTRY_AREA into the user space visible page table.
  65. + */
  66. +static void __init pti_clone_user_shared(void)
  67. +{
  68. + pti_clone_p4d(CPU_ENTRY_AREA_BASE);
  69. +}
  70. +
  71. /*
  72. * Initialize kernel page table isolation
  73. */
  74. @@ -273,4 +296,6 @@ void __init pti_init(void)
  75. return;
  76. pr_info("enabled\n");
  77. +
  78. + pti_clone_user_shared();
  79. }
  80. --
  81. 2.14.2