0059-x86-head-Add-unwind-hint-annotations.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. From 6ef121f444bab6ac294e1eda62eb727ee639c6d7 Mon Sep 17 00:00:00 2001
  2. From: Josh Poimboeuf <[email protected]>
  3. Date: Mon, 18 Sep 2017 21:43:37 -0500
  4. Subject: [PATCH 059/231] x86/head: Add unwind hint annotations
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. Jiri Slaby reported an ORC issue when unwinding from an idle task. The
  10. stack was:
  11. ffffffff811083c2 do_idle+0x142/0x1e0
  12. ffffffff8110861d cpu_startup_entry+0x5d/0x60
  13. ffffffff82715f58 start_kernel+0x3ff/0x407
  14. ffffffff827153e8 x86_64_start_kernel+0x14e/0x15d
  15. ffffffff810001bf secondary_startup_64+0x9f/0xa0
  16. The ORC unwinder errored out at secondary_startup_64 because the head
  17. code isn't annotated yet so there wasn't a corresponding ORC entry.
  18. Fix that and any other head-related unwinding issues by adding unwind
  19. hints to the head code.
  20. Reported-by: Jiri Slaby <[email protected]>
  21. Tested-by: Jiri Slaby <[email protected]>
  22. Signed-off-by: Josh Poimboeuf <[email protected]>
  23. Cc: Andy Lutomirski <[email protected]>
  24. Cc: Boris Ostrovsky <[email protected]>
  25. Cc: Juergen Gross <[email protected]>
  26. Cc: Linus Torvalds <[email protected]>
  27. Cc: Peter Zijlstra <[email protected]>
  28. Cc: Thomas Gleixner <[email protected]>
  29. Link: http://lkml.kernel.org/r/78ef000a2f68f545d6eef44ee912edceaad82ccf.1505764066.git.jpoimboe@redhat.com
  30. Signed-off-by: Ingo Molnar <[email protected]>
  31. (cherry picked from commit 2704fbb672d0d9a19414907fda7949283dcef6a1)
  32. Signed-off-by: Andy Whitcroft <[email protected]>
  33. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  34. (cherry picked from commit b63a868e404e64172afefea553c6a40963a151db)
  35. Signed-off-by: Fabian Grünbichler <[email protected]>
  36. ---
  37. arch/x86/kernel/Makefile | 1 -
  38. arch/x86/kernel/head_64.S | 14 ++++++++++++--
  39. 2 files changed, 12 insertions(+), 3 deletions(-)
  40. diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
  41. index 287eac7d207f..e2315aecc441 100644
  42. --- a/arch/x86/kernel/Makefile
  43. +++ b/arch/x86/kernel/Makefile
  44. @@ -26,7 +26,6 @@ KASAN_SANITIZE_dumpstack.o := n
  45. KASAN_SANITIZE_dumpstack_$(BITS).o := n
  46. KASAN_SANITIZE_stacktrace.o := n
  47. -OBJECT_FILES_NON_STANDARD_head_$(BITS).o := y
  48. OBJECT_FILES_NON_STANDARD_relocate_kernel_$(BITS).o := y
  49. OBJECT_FILES_NON_STANDARD_ftrace_$(BITS).o := y
  50. OBJECT_FILES_NON_STANDARD_test_nx.o := y
  51. diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
  52. index 45b18b1a6417..d081bc7a027d 100644
  53. --- a/arch/x86/kernel/head_64.S
  54. +++ b/arch/x86/kernel/head_64.S
  55. @@ -49,6 +49,7 @@ L3_START_KERNEL = pud_index(__START_KERNEL_map)
  56. .code64
  57. .globl startup_64
  58. startup_64:
  59. + UNWIND_HINT_EMPTY
  60. /*
  61. * At this point the CPU runs in 64bit mode CS.L = 1 CS.D = 0,
  62. * and someone has loaded an identity mapped page table
  63. @@ -81,6 +82,7 @@ startup_64:
  64. movq $(early_top_pgt - __START_KERNEL_map), %rax
  65. jmp 1f
  66. ENTRY(secondary_startup_64)
  67. + UNWIND_HINT_EMPTY
  68. /*
  69. * At this point the CPU runs in 64bit mode CS.L = 1 CS.D = 0,
  70. * and someone has loaded a mapped page table.
  71. @@ -116,6 +118,7 @@ ENTRY(secondary_startup_64)
  72. movq $1f, %rax
  73. jmp *%rax
  74. 1:
  75. + UNWIND_HINT_EMPTY
  76. /* Check if nx is implemented */
  77. movl $0x80000001, %eax
  78. @@ -230,6 +233,7 @@ END(secondary_startup_64)
  79. */
  80. ENTRY(start_cpu0)
  81. movq initial_stack(%rip), %rsp
  82. + UNWIND_HINT_EMPTY
  83. jmp .Ljump_to_C_code
  84. ENDPROC(start_cpu0)
  85. #endif
  86. @@ -254,13 +258,18 @@ ENTRY(early_idt_handler_array)
  87. i = 0
  88. .rept NUM_EXCEPTION_VECTORS
  89. .ifeq (EXCEPTION_ERRCODE_MASK >> i) & 1
  90. - pushq $0 # Dummy error code, to make stack frame uniform
  91. + UNWIND_HINT_IRET_REGS
  92. + pushq $0 # Dummy error code, to make stack frame uniform
  93. + .else
  94. + UNWIND_HINT_IRET_REGS offset=8
  95. .endif
  96. pushq $i # 72(%rsp) Vector number
  97. jmp early_idt_handler_common
  98. + UNWIND_HINT_IRET_REGS
  99. i = i + 1
  100. .fill early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
  101. .endr
  102. + UNWIND_HINT_IRET_REGS offset=16
  103. END(early_idt_handler_array)
  104. early_idt_handler_common:
  105. @@ -289,6 +298,7 @@ early_idt_handler_common:
  106. pushq %r13 /* pt_regs->r13 */
  107. pushq %r14 /* pt_regs->r14 */
  108. pushq %r15 /* pt_regs->r15 */
  109. + UNWIND_HINT_REGS
  110. cmpq $14,%rsi /* Page fault? */
  111. jnz 10f
  112. @@ -411,7 +421,7 @@ ENTRY(phys_base)
  113. EXPORT_SYMBOL(phys_base)
  114. #include "../../x86/xen/xen-head.S"
  115. -
  116. +
  117. __PAGE_ALIGNED_BSS
  118. NEXT_PAGE(empty_zero_page)
  119. .skip PAGE_SIZE
  120. --
  121. 2.14.2