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

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