0138-x86-unwinder-orc-Dont-bail-on-stack-overflow.patch 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. From bb0be747b5ee45f07f5514a214231c9061261b50 Mon Sep 17 00:00:00 2001
  2. From: Andy Lutomirski <[email protected]>
  3. Date: Mon, 4 Dec 2017 15:07:08 +0100
  4. Subject: [PATCH 138/232] x86/unwinder/orc: Dont bail on stack overflow
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. If the stack overflows into a guard page and the ORC unwinder should work
  10. well: by construction, there can't be any meaningful data in the guard page
  11. because no writes to the guard page will have succeeded.
  12. But there is a bug that prevents unwinding from working correctly: if the
  13. starting register state has RSP pointing into a stack guard page, the ORC
  14. unwinder bails out immediately.
  15. Instead of bailing out immediately check whether the next page up is a
  16. valid check page and if so analyze that. As a result the ORC unwinder will
  17. start the unwind.
  18. Tested by intentionally overflowing the task stack. The result is an
  19. accurate call trace instead of a trace consisting purely of '?' entries.
  20. There are a few other bugs that are triggered if the unwinder encounters a
  21. stack overflow after the first step, but they are outside the scope of this
  22. fix.
  23. Signed-off-by: Andy Lutomirski <[email protected]>
  24. Signed-off-by: Thomas Gleixner <[email protected]>
  25. Cc: Boris Ostrovsky <[email protected]>
  26. Cc: Borislav Petkov <[email protected]>
  27. Cc: Borislav Petkov <[email protected]>
  28. Cc: Brian Gerst <[email protected]>
  29. Cc: Dave Hansen <[email protected]>
  30. Cc: Dave Hansen <[email protected]>
  31. Cc: David Laight <[email protected]>
  32. Cc: Denys Vlasenko <[email protected]>
  33. Cc: Eduardo Valentin <[email protected]>
  34. Cc: Greg KH <[email protected]>
  35. Cc: H. Peter Anvin <[email protected]>
  36. Cc: Josh Poimboeuf <[email protected]>
  37. Cc: Juergen Gross <[email protected]>
  38. Cc: Linus Torvalds <[email protected]>
  39. Cc: Peter Zijlstra <[email protected]>
  40. Cc: Rik van Riel <[email protected]>
  41. Cc: Will Deacon <[email protected]>
  42. Cc: [email protected]
  43. Cc: [email protected]
  44. Cc: [email protected]
  45. Cc: [email protected]
  46. Link: https://lkml.kernel.org/r/[email protected]
  47. Signed-off-by: Ingo Molnar <[email protected]>
  48. (cherry picked from commit d3a09104018cf2ad5973dfa8a9c138ef9f5015a3)
  49. Signed-off-by: Andy Whitcroft <[email protected]>
  50. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  51. (cherry picked from commit e5c3115ac69cddd384d6f7abc4a0ef030b247498)
  52. Signed-off-by: Fabian Grünbichler <[email protected]>
  53. ---
  54. arch/x86/kernel/unwind_orc.c | 14 ++++++++++++--
  55. 1 file changed, 12 insertions(+), 2 deletions(-)
  56. diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
  57. index 570b70d3f604..cea85bfe93f7 100644
  58. --- a/arch/x86/kernel/unwind_orc.c
  59. +++ b/arch/x86/kernel/unwind_orc.c
  60. @@ -552,8 +552,18 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
  61. }
  62. if (get_stack_info((unsigned long *)state->sp, state->task,
  63. - &state->stack_info, &state->stack_mask))
  64. - return;
  65. + &state->stack_info, &state->stack_mask)) {
  66. + /*
  67. + * We weren't on a valid stack. It's possible that
  68. + * we overflowed a valid stack into a guard page.
  69. + * See if the next page up is valid so that we can
  70. + * generate some kind of backtrace if this happens.
  71. + */
  72. + void *next_page = (void *)PAGE_ALIGN((unsigned long)state->sp);
  73. + if (get_stack_info(next_page, state->task, &state->stack_info,
  74. + &state->stack_mask))
  75. + return;
  76. + }
  77. /*
  78. * The caller can provide the address of the first frame directly
  79. --
  80. 2.14.2