0236-x86-mm-Set-MODULES_END-to-0xffffffffff000000.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. From 650929f1bdce50bab031b0886ae91d459edcd18e Mon Sep 17 00:00:00 2001
  2. From: Andrey Ryabinin <[email protected]>
  3. Date: Thu, 28 Dec 2017 19:06:20 +0300
  4. Subject: [PATCH 236/242] x86/mm: Set MODULES_END to 0xffffffffff000000
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. commit f5a40711fa58f1c109165a4fec6078bf2dfd2bdc upstream.
  9. Since f06bdd4001c2 ("x86/mm: Adapt MODULES_END based on fixmap section size")
  10. kasan_mem_to_shadow(MODULES_END) could be not aligned to a page boundary.
  11. So passing page unaligned address to kasan_populate_zero_shadow() have two
  12. possible effects:
  13. 1) It may leave one page hole in supposed to be populated area. After commit
  14. 21506525fb8d ("x86/kasan/64: Teach KASAN about the cpu_entry_area") that
  15. hole happens to be in the shadow covering fixmap area and leads to crash:
  16. BUG: unable to handle kernel paging request at fffffbffffe8ee04
  17. RIP: 0010:check_memory_region+0x5c/0x190
  18. Call Trace:
  19. <NMI>
  20. memcpy+0x1f/0x50
  21. ghes_copy_tofrom_phys+0xab/0x180
  22. ghes_read_estatus+0xfb/0x280
  23. ghes_notify_nmi+0x2b2/0x410
  24. nmi_handle+0x115/0x2c0
  25. default_do_nmi+0x57/0x110
  26. do_nmi+0xf8/0x150
  27. end_repeat_nmi+0x1a/0x1e
  28. Note, the crash likely disappeared after commit 92a0f81d8957, which
  29. changed kasan_populate_zero_shadow() call the way it was before
  30. commit 21506525fb8d.
  31. 2) Attempt to load module near MODULES_END will fail, because
  32. __vmalloc_node_range() called from kasan_module_alloc() will hit the
  33. WARN_ON(!pte_none(*pte)) in the vmap_pte_range() and bail out with error.
  34. To fix this we need to make kasan_mem_to_shadow(MODULES_END) page aligned
  35. which means that MODULES_END should be 8*PAGE_SIZE aligned.
  36. The whole point of commit f06bdd4001c2 was to move MODULES_END down if
  37. NR_CPUS is big, so the cpu_entry_area takes a lot of space.
  38. But since 92a0f81d8957 ("x86/cpu_entry_area: Move it out of the fixmap")
  39. the cpu_entry_area is no longer in fixmap, so we could just set
  40. MODULES_END to a fixed 8*PAGE_SIZE aligned address.
  41. Fixes: f06bdd4001c2 ("x86/mm: Adapt MODULES_END based on fixmap section size")
  42. Reported-by: Jakub Kicinski <[email protected]>
  43. Signed-off-by: Andrey Ryabinin <[email protected]>
  44. Signed-off-by: Thomas Gleixner <[email protected]>
  45. Cc: Andy Lutomirski <[email protected]>
  46. Cc: Thomas Garnier <[email protected]>
  47. Link: https://lkml.kernel.org/r/[email protected]
  48. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  49. Signed-off-by: Fabian Grünbichler <[email protected]>
  50. ---
  51. Documentation/x86/x86_64/mm.txt | 5 +----
  52. arch/x86/include/asm/pgtable_64_types.h | 2 +-
  53. 2 files changed, 2 insertions(+), 5 deletions(-)
  54. diff --git a/Documentation/x86/x86_64/mm.txt b/Documentation/x86/x86_64/mm.txt
  55. index ad41b3813f0a..ddd5ffd31bd0 100644
  56. --- a/Documentation/x86/x86_64/mm.txt
  57. +++ b/Documentation/x86/x86_64/mm.txt
  58. @@ -43,7 +43,7 @@ ffffff0000000000 - ffffff7fffffffff (=39 bits) %esp fixup stacks
  59. ffffffef00000000 - fffffffeffffffff (=64 GB) EFI region mapping space
  60. ... unused hole ...
  61. ffffffff80000000 - ffffffff9fffffff (=512 MB) kernel text mapping, from phys 0
  62. -ffffffffa0000000 - [fixmap start] (~1526 MB) module mapping space
  63. +ffffffffa0000000 - fffffffffeffffff (1520 MB) module mapping space
  64. [fixmap start] - ffffffffff5fffff kernel-internal fixmap range
  65. ffffffffff600000 - ffffffffff600fff (=4 kB) legacy vsyscall ABI
  66. ffffffffffe00000 - ffffffffffffffff (=2 MB) unused hole
  67. @@ -67,9 +67,6 @@ memory window (this size is arbitrary, it can be raised later if needed).
  68. The mappings are not part of any other kernel PGD and are only available
  69. during EFI runtime calls.
  70. -The module mapping space size changes based on the CONFIG requirements for the
  71. -following fixmap section.
  72. -
  73. Note that if CONFIG_RANDOMIZE_MEMORY is enabled, the direct mapping of all
  74. physical memory, vmalloc/ioremap space and virtual memory map are randomized.
  75. Their order is preserved but their base will be offset early at boot time.
  76. diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
  77. index e8a809ee0bb6..c92bd73b1e46 100644
  78. --- a/arch/x86/include/asm/pgtable_64_types.h
  79. +++ b/arch/x86/include/asm/pgtable_64_types.h
  80. @@ -103,7 +103,7 @@ typedef struct { pteval_t pte; } pte_t;
  81. #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
  82. /* The module sections ends with the start of the fixmap */
  83. -#define MODULES_END __fix_to_virt(__end_of_fixed_addresses + 1)
  84. +#define MODULES_END _AC(0xffffffffff000000, UL)
  85. #define MODULES_LEN (MODULES_END - MODULES_VADDR)
  86. #define ESPFIX_PGD_ENTRY _AC(-2, UL)
  87. --
  88. 2.14.2