0195-x86-mm-pti-Populate-user-PGD.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. From 3bc42412073e1c559266e2b07bc1fbce154d92dc Mon Sep 17 00:00:00 2001
  2. From: Dave Hansen <[email protected]>
  3. Date: Mon, 4 Dec 2017 15:07:40 +0100
  4. Subject: [PATCH 195/242] x86/mm/pti: Populate user PGD
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. In clone_pgd_range() copy the init user PGDs which cover the kernel half of
  10. the address space, so a process has all the required kernel mappings
  11. visible.
  12. [ tglx: Split out from the big kaiser dump and folded Andys simplification ]
  13. Signed-off-by: Dave Hansen <[email protected]>
  14. Signed-off-by: Thomas Gleixner <[email protected]>
  15. Reviewed-by: Borislav Petkov <[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: David Laight <[email protected]>
  21. Cc: Denys Vlasenko <[email protected]>
  22. Cc: Eduardo Valentin <[email protected]>
  23. Cc: Greg KH <[email protected]>
  24. Cc: H. Peter Anvin <[email protected]>
  25. Cc: Josh Poimboeuf <[email protected]>
  26. Cc: Juergen Gross <[email protected]>
  27. Cc: Linus Torvalds <[email protected]>
  28. Cc: Peter Zijlstra <[email protected]>
  29. Cc: Will Deacon <[email protected]>
  30. Cc: [email protected]
  31. Cc: [email protected]
  32. Cc: [email protected]
  33. Cc: [email protected]
  34. Signed-off-by: Ingo Molnar <[email protected]>
  35. (cherry picked from commit fc2fbc8512ed08d1de7720936fd7d2e4ce02c3a2)
  36. Signed-off-by: Andy Whitcroft <[email protected]>
  37. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  38. (cherry picked from commit 26c08c52162e1079cbb3e9ce8e1346a100ea7ccc)
  39. Signed-off-by: Fabian Grünbichler <[email protected]>
  40. ---
  41. arch/x86/include/asm/pgtable.h | 9 ++++++++-
  42. 1 file changed, 8 insertions(+), 1 deletion(-)
  43. diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
  44. index 3ef8415b2358..25604b8a251a 100644
  45. --- a/arch/x86/include/asm/pgtable.h
  46. +++ b/arch/x86/include/asm/pgtable.h
  47. @@ -1104,7 +1104,14 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
  48. */
  49. static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
  50. {
  51. - memcpy(dst, src, count * sizeof(pgd_t));
  52. + memcpy(dst, src, count * sizeof(pgd_t));
  53. +#ifdef CONFIG_PAGE_TABLE_ISOLATION
  54. + if (!static_cpu_has(X86_FEATURE_PTI))
  55. + return;
  56. + /* Clone the user space pgd as well */
  57. + memcpy(kernel_to_user_pgdp(dst), kernel_to_user_pgdp(src),
  58. + count * sizeof(pgd_t));
  59. +#endif
  60. }
  61. #define PTE_SHIFT ilog2(PTRS_PER_PTE)
  62. --
  63. 2.14.2