0216-x86-mm-dump_pagetables-Check-user-space-page-table-f.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. From 2ed23a29f6f9c736c86dcc8d8ab87cc670593503 Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Mon, 4 Dec 2017 15:08:05 +0100
  4. Subject: [PATCH 216/242] x86/mm/dump_pagetables: Check user space page table
  5. for WX pages
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. ptdump_walk_pgd_level_checkwx() checks the kernel page table for WX pages,
  11. but does not check the PAGE_TABLE_ISOLATION user space page table.
  12. Restructure the code so that dmesg output is selected by an explicit
  13. argument and not implicit via checking the pgd argument for !NULL.
  14. Add the check for the user space page table.
  15. Signed-off-by: Thomas Gleixner <[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: Dave Hansen <[email protected]>
  21. Cc: David Laight <[email protected]>
  22. Cc: Denys Vlasenko <[email protected]>
  23. Cc: Eduardo Valentin <[email protected]>
  24. Cc: Greg KH <[email protected]>
  25. Cc: H. Peter Anvin <[email protected]>
  26. Cc: Josh Poimboeuf <[email protected]>
  27. Cc: Juergen Gross <[email protected]>
  28. Cc: Linus Torvalds <[email protected]>
  29. Cc: Peter Zijlstra <[email protected]>
  30. Cc: Will Deacon <[email protected]>
  31. Cc: [email protected]
  32. Cc: [email protected]
  33. Cc: [email protected]
  34. Cc: [email protected]
  35. Cc: [email protected]
  36. Signed-off-by: Ingo Molnar <[email protected]>
  37. (cherry picked from commit b4bf4f924b1d7bade38fd51b2e401d20d0956e4d)
  38. Signed-off-by: Andy Whitcroft <[email protected]>
  39. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  40. (cherry picked from commit 1adfe82e8fe5afa2fae59efe498c461d5a52cb6c)
  41. Signed-off-by: Fabian Grünbichler <[email protected]>
  42. ---
  43. arch/x86/include/asm/pgtable.h | 1 +
  44. arch/x86/mm/debug_pagetables.c | 2 +-
  45. arch/x86/mm/dump_pagetables.c | 30 +++++++++++++++++++++++++-----
  46. 3 files changed, 27 insertions(+), 6 deletions(-)
  47. diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
  48. index 25604b8a251a..4f5eb81cf8be 100644
  49. --- a/arch/x86/include/asm/pgtable.h
  50. +++ b/arch/x86/include/asm/pgtable.h
  51. @@ -17,6 +17,7 @@
  52. #include <asm/x86_init.h>
  53. void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd);
  54. +void ptdump_walk_pgd_level_debugfs(struct seq_file *m, pgd_t *pgd);
  55. void ptdump_walk_pgd_level_checkwx(void);
  56. #ifdef CONFIG_DEBUG_WX
  57. diff --git a/arch/x86/mm/debug_pagetables.c b/arch/x86/mm/debug_pagetables.c
  58. index d1449fb6dc7a..8e70c1599e51 100644
  59. --- a/arch/x86/mm/debug_pagetables.c
  60. +++ b/arch/x86/mm/debug_pagetables.c
  61. @@ -5,7 +5,7 @@
  62. static int ptdump_show(struct seq_file *m, void *v)
  63. {
  64. - ptdump_walk_pgd_level(m, NULL);
  65. + ptdump_walk_pgd_level_debugfs(m, NULL);
  66. return 0;
  67. }
  68. diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
  69. index eed93dd4cb4a..7b022ad37c4e 100644
  70. --- a/arch/x86/mm/dump_pagetables.c
  71. +++ b/arch/x86/mm/dump_pagetables.c
  72. @@ -457,7 +457,7 @@ static inline bool is_hypervisor_range(int idx)
  73. }
  74. static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
  75. - bool checkwx)
  76. + bool checkwx, bool dmesg)
  77. {
  78. #ifdef CONFIG_X86_64
  79. pgd_t *start = (pgd_t *) &init_top_pgt;
  80. @@ -470,7 +470,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
  81. if (pgd) {
  82. start = pgd;
  83. - st.to_dmesg = true;
  84. + st.to_dmesg = dmesg;
  85. }
  86. st.check_wx = checkwx;
  87. @@ -508,13 +508,33 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
  88. void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd)
  89. {
  90. - ptdump_walk_pgd_level_core(m, pgd, false);
  91. + ptdump_walk_pgd_level_core(m, pgd, false, true);
  92. +}
  93. +
  94. +void ptdump_walk_pgd_level_debugfs(struct seq_file *m, pgd_t *pgd)
  95. +{
  96. + ptdump_walk_pgd_level_core(m, pgd, false, false);
  97. +}
  98. +EXPORT_SYMBOL_GPL(ptdump_walk_pgd_level_debugfs);
  99. +
  100. +static void ptdump_walk_user_pgd_level_checkwx(void)
  101. +{
  102. +#ifdef CONFIG_PAGE_TABLE_ISOLATION
  103. + pgd_t *pgd = (pgd_t *) &init_top_pgt;
  104. +
  105. + if (!static_cpu_has(X86_FEATURE_PTI))
  106. + return;
  107. +
  108. + pr_info("x86/mm: Checking user space page tables\n");
  109. + pgd = kernel_to_user_pgdp(pgd);
  110. + ptdump_walk_pgd_level_core(NULL, pgd, true, false);
  111. +#endif
  112. }
  113. -EXPORT_SYMBOL_GPL(ptdump_walk_pgd_level);
  114. void ptdump_walk_pgd_level_checkwx(void)
  115. {
  116. - ptdump_walk_pgd_level_core(NULL, NULL, true);
  117. + ptdump_walk_pgd_level_core(NULL, NULL, true, false);
  118. + ptdump_walk_user_pgd_level_checkwx();
  119. }
  120. static int __init pt_dump_init(void)
  121. --
  122. 2.14.2