0165-x86-mm-dump_pagetables-Make-the-address-hints-correc.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. From e16f646082d458ec595304dbc2e6906fdc417495 Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Wed, 20 Dec 2017 18:07:42 +0100
  4. Subject: [PATCH 165/242] x86/mm/dump_pagetables: Make the address hints
  5. correct and readable
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. The address hints are a trainwreck. The array entry numbers have to kept
  11. magically in sync with the actual hints, which is doomed as some of the
  12. array members are initialized at runtime via the entry numbers.
  13. Designated initializers have been around before this code was
  14. implemented....
  15. Use the entry numbers to populate the address hints array and add the
  16. missing bits and pieces. Split 32 and 64 bit for readability sake.
  17. Signed-off-by: Thomas Gleixner <[email protected]>
  18. Cc: Andy Lutomirski <[email protected]>
  19. Cc: Borislav Petkov <[email protected]>
  20. Cc: Dave Hansen <[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: [email protected]
  27. Signed-off-by: Ingo Molnar <[email protected]>
  28. (cherry picked from commit 146122e24bdf208015d629babba673e28d090709)
  29. Signed-off-by: Andy Whitcroft <[email protected]>
  30. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  31. (cherry picked from commit 7f4d9163531183fbaa0df1d1b1ceecbade4e58dc)
  32. Signed-off-by: Fabian Grünbichler <[email protected]>
  33. ---
  34. arch/x86/mm/dump_pagetables.c | 90 +++++++++++++++++++++++++------------------
  35. 1 file changed, 53 insertions(+), 37 deletions(-)
  36. diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
  37. index 91aa41c5e0dd..318a7c30e87e 100644
  38. --- a/arch/x86/mm/dump_pagetables.c
  39. +++ b/arch/x86/mm/dump_pagetables.c
  40. @@ -44,10 +44,12 @@ struct addr_marker {
  41. unsigned long max_lines;
  42. };
  43. -/* indices for address_markers; keep sync'd w/ address_markers below */
  44. +/* Address space markers hints */
  45. +
  46. +#ifdef CONFIG_X86_64
  47. +
  48. enum address_markers_idx {
  49. USER_SPACE_NR = 0,
  50. -#ifdef CONFIG_X86_64
  51. KERNEL_SPACE_NR,
  52. LOW_KERNEL_NR,
  53. VMALLOC_START_NR,
  54. @@ -56,56 +58,70 @@ enum address_markers_idx {
  55. KASAN_SHADOW_START_NR,
  56. KASAN_SHADOW_END_NR,
  57. #endif
  58. -# ifdef CONFIG_X86_ESPFIX64
  59. +#ifdef CONFIG_X86_ESPFIX64
  60. ESPFIX_START_NR,
  61. -# endif
  62. +#endif
  63. +#ifdef CONFIG_EFI
  64. + EFI_END_NR,
  65. +#endif
  66. HIGH_KERNEL_NR,
  67. MODULES_VADDR_NR,
  68. MODULES_END_NR,
  69. -#else
  70. + FIXADDR_START_NR,
  71. + END_OF_SPACE_NR,
  72. +};
  73. +
  74. +static struct addr_marker address_markers[] = {
  75. + [USER_SPACE_NR] = { 0, "User Space" },
  76. + [KERNEL_SPACE_NR] = { (1UL << 63), "Kernel Space" },
  77. + [LOW_KERNEL_NR] = { 0UL, "Low Kernel Mapping" },
  78. + [VMALLOC_START_NR] = { 0UL, "vmalloc() Area" },
  79. + [VMEMMAP_START_NR] = { 0UL, "Vmemmap" },
  80. +#ifdef CONFIG_KASAN
  81. + [KASAN_SHADOW_START_NR] = { KASAN_SHADOW_START, "KASAN shadow" },
  82. + [KASAN_SHADOW_END_NR] = { KASAN_SHADOW_END, "KASAN shadow end" },
  83. +#endif
  84. +#ifdef CONFIG_X86_ESPFIX64
  85. + [ESPFIX_START_NR] = { ESPFIX_BASE_ADDR, "ESPfix Area", 16 },
  86. +#endif
  87. +#ifdef CONFIG_EFI
  88. + [EFI_END_NR] = { EFI_VA_END, "EFI Runtime Services" },
  89. +#endif
  90. + [HIGH_KERNEL_NR] = { __START_KERNEL_map, "High Kernel Mapping" },
  91. + [MODULES_VADDR_NR] = { MODULES_VADDR, "Modules" },
  92. + [MODULES_END_NR] = { MODULES_END, "End Modules" },
  93. + [FIXADDR_START_NR] = { FIXADDR_START, "Fixmap Area" },
  94. + [END_OF_SPACE_NR] = { -1, NULL }
  95. +};
  96. +
  97. +#else /* CONFIG_X86_64 */
  98. +
  99. +enum address_markers_idx {
  100. + USER_SPACE_NR = 0,
  101. KERNEL_SPACE_NR,
  102. VMALLOC_START_NR,
  103. VMALLOC_END_NR,
  104. -# ifdef CONFIG_HIGHMEM
  105. +#ifdef CONFIG_HIGHMEM
  106. PKMAP_BASE_NR,
  107. -# endif
  108. - FIXADDR_START_NR,
  109. #endif
  110. + FIXADDR_START_NR,
  111. + END_OF_SPACE_NR,
  112. };
  113. -/* Address space markers hints */
  114. static struct addr_marker address_markers[] = {
  115. - { 0, "User Space" },
  116. -#ifdef CONFIG_X86_64
  117. - { 0x8000000000000000UL, "Kernel Space" },
  118. - { 0/* PAGE_OFFSET */, "Low Kernel Mapping" },
  119. - { 0/* VMALLOC_START */, "vmalloc() Area" },
  120. - { 0/* VMEMMAP_START */, "Vmemmap" },
  121. -#ifdef CONFIG_KASAN
  122. - { KASAN_SHADOW_START, "KASAN shadow" },
  123. - { KASAN_SHADOW_END, "KASAN shadow end" },
  124. + [USER_SPACE_NR] = { 0, "User Space" },
  125. + [KERNEL_SPACE_NR] = { PAGE_OFFSET, "Kernel Mapping" },
  126. + [VMALLOC_START_NR] = { 0UL, "vmalloc() Area" },
  127. + [VMALLOC_END_NR] = { 0UL, "vmalloc() End" },
  128. +#ifdef CONFIG_HIGHMEM
  129. + [PKMAP_BASE_NR] = { 0UL, "Persistent kmap() Area" },
  130. #endif
  131. -# ifdef CONFIG_X86_ESPFIX64
  132. - { ESPFIX_BASE_ADDR, "ESPfix Area", 16 },
  133. -# endif
  134. -# ifdef CONFIG_EFI
  135. - { EFI_VA_END, "EFI Runtime Services" },
  136. -# endif
  137. - { __START_KERNEL_map, "High Kernel Mapping" },
  138. - { MODULES_VADDR, "Modules" },
  139. - { MODULES_END, "End Modules" },
  140. -#else
  141. - { PAGE_OFFSET, "Kernel Mapping" },
  142. - { 0/* VMALLOC_START */, "vmalloc() Area" },
  143. - { 0/*VMALLOC_END*/, "vmalloc() End" },
  144. -# ifdef CONFIG_HIGHMEM
  145. - { 0/*PKMAP_BASE*/, "Persistent kmap() Area" },
  146. -# endif
  147. - { 0/*FIXADDR_START*/, "Fixmap Area" },
  148. -#endif
  149. - { -1, NULL } /* End of list */
  150. + [FIXADDR_START_NR] = { 0UL, "Fixmap area" },
  151. + [END_OF_SPACE_NR] = { -1, NULL }
  152. };
  153. +#endif /* !CONFIG_X86_64 */
  154. +
  155. /* Multipliers for offsets within the PTEs */
  156. #define PTE_LEVEL_MULT (PAGE_SIZE)
  157. #define PMD_LEVEL_MULT (PTRS_PER_PTE * PTE_LEVEL_MULT)
  158. --
  159. 2.14.2