0148-x86-dumpstack-Handle-stack-overflow-on-all-stacks.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From 11739f104753550b4d256207c07a75f667b7aae4 Mon Sep 17 00:00:00 2001
  2. From: Andy Lutomirski <[email protected]>
  3. Date: Mon, 4 Dec 2017 15:07:18 +0100
  4. Subject: [PATCH 148/242] x86/dumpstack: Handle stack overflow on all stacks
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. We currently special-case stack overflow on the task stack. We're
  10. going to start putting special stacks in the fixmap with a custom
  11. layout, so they'll have guard pages, too. Teach the unwinder to be
  12. able to unwind an overflow of any of the stacks.
  13. Signed-off-by: Andy Lutomirski <[email protected]>
  14. Signed-off-by: Thomas Gleixner <[email protected]>
  15. Reviewed-by: Borislav Petkov <[email protected]>
  16. Cc: Boris Ostrovsky <[email protected]>
  17. Cc: Borislav Petkov <[email protected]>
  18. Cc: Borislav Petkov <[email protected]>
  19. Cc: Brian Gerst <[email protected]>
  20. Cc: Dave Hansen <[email protected]>
  21. Cc: Dave Hansen <[email protected]>
  22. Cc: David Laight <[email protected]>
  23. Cc: Denys Vlasenko <[email protected]>
  24. Cc: Eduardo Valentin <[email protected]>
  25. Cc: Greg KH <[email protected]>
  26. Cc: H. Peter Anvin <[email protected]>
  27. Cc: Josh Poimboeuf <[email protected]>
  28. Cc: Juergen Gross <[email protected]>
  29. Cc: Linus Torvalds <[email protected]>
  30. Cc: Peter Zijlstra <[email protected]>
  31. Cc: Rik van Riel <[email protected]>
  32. Cc: Will Deacon <[email protected]>
  33. Cc: [email protected]
  34. Cc: [email protected]
  35. Cc: [email protected]
  36. Cc: [email protected]
  37. Link: https://lkml.kernel.org/r/[email protected]
  38. Signed-off-by: Ingo Molnar <[email protected]>
  39. (cherry picked from commit 6e60e583426c2f8751c22c2dfe5c207083b4483a)
  40. Signed-off-by: Andy Whitcroft <[email protected]>
  41. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  42. (cherry picked from commit 1ab51120b9a5baaa46979e4ab8ff28916c9cb846)
  43. Signed-off-by: Fabian Grünbichler <[email protected]>
  44. ---
  45. arch/x86/kernel/dumpstack.c | 24 ++++++++++++++----------
  46. 1 file changed, 14 insertions(+), 10 deletions(-)
  47. diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
  48. index c211cbdff709..0f4b931e1a02 100644
  49. --- a/arch/x86/kernel/dumpstack.c
  50. +++ b/arch/x86/kernel/dumpstack.c
  51. @@ -112,24 +112,28 @@ void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
  52. * - task stack
  53. * - interrupt stack
  54. * - HW exception stacks (double fault, nmi, debug, mce)
  55. + * - SYSENTER stack
  56. *
  57. - * x86-32 can have up to three stacks:
  58. + * x86-32 can have up to four stacks:
  59. * - task stack
  60. * - softirq stack
  61. * - hardirq stack
  62. + * - SYSENTER stack
  63. */
  64. for (regs = NULL; stack; stack = PTR_ALIGN(stack_info.next_sp, sizeof(long))) {
  65. const char *stack_name;
  66. - /*
  67. - * If we overflowed the task stack into a guard page, jump back
  68. - * to the bottom of the usable stack.
  69. - */
  70. - if (task_stack_page(task) - (void *)stack < PAGE_SIZE)
  71. - stack = task_stack_page(task);
  72. -
  73. - if (get_stack_info(stack, task, &stack_info, &visit_mask))
  74. - break;
  75. + if (get_stack_info(stack, task, &stack_info, &visit_mask)) {
  76. + /*
  77. + * We weren't on a valid stack. It's possible that
  78. + * we overflowed a valid stack into a guard page.
  79. + * See if the next page up is valid so that we can
  80. + * generate some kind of backtrace if this happens.
  81. + */
  82. + stack = (unsigned long *)PAGE_ALIGN((unsigned long)stack);
  83. + if (get_stack_info(stack, task, &stack_info, &visit_mask))
  84. + break;
  85. + }
  86. stack_name = stack_type_name(stack_info.type);
  87. if (stack_name)
  88. --
  89. 2.14.2