0047-kprobes-x86-Set-up-frame-pointer-in-kprobe-trampolin.patch 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From f2c1440e8f0b728d48ee8ce295f4dfe495949e1f Mon Sep 17 00:00:00 2001
  2. From: Josh Poimboeuf <[email protected]>
  3. Date: Tue, 3 Oct 2017 08:51:43 -0500
  4. Subject: [PATCH 047/242] kprobes/x86: Set up frame pointer in kprobe
  5. trampoline
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. Richard Weinberger saw an unwinder warning when running bcc's opensnoop:
  11. WARNING: kernel stack frame pointer at ffff99ef4076bea0 in opensnoop:2008 has bad value 0000000000000008
  12. unwind stack type:0 next_sp: (null) mask:0x2 graph_idx:0
  13. ...
  14. ffff99ef4076be88: ffff99ef4076bea0 (0xffff99ef4076bea0)
  15. ffff99ef4076be90: ffffffffac442721 (optimized_callback +0x81/0x90)
  16. ...
  17. A lockdep stack trace was initiated from inside a kprobe handler, when
  18. the unwinder noticed a bad frame pointer on the stack. The bad frame
  19. pointer is related to the fact that the kprobe optprobe trampoline
  20. doesn't save the frame pointer before calling into optimized_callback().
  21. Reported-and-tested-by: Richard Weinberger <[email protected]>
  22. Signed-off-by: Josh Poimboeuf <[email protected]>
  23. Acked-by: Masami Hiramatsu <[email protected]>
  24. Cc: Ananth N Mavinakayanahalli <[email protected]>
  25. Cc: Anil S Keshavamurthy <[email protected]>
  26. Cc: David S . Miller <[email protected]>
  27. Cc: Linus Torvalds <[email protected]>
  28. Cc: Peter Zijlstra <[email protected]>
  29. Cc: Thomas Gleixner <[email protected]>
  30. Link: http://lkml.kernel.org/r/7aef2f8ecd75c2f505ef9b80490412262cf4a44c.1507038547.git.jpoimboe@redhat.com
  31. Signed-off-by: Ingo Molnar <[email protected]>
  32. (cherry picked from commit ee213fc72fd67d0988525af501534f4cb924d1e9)
  33. Signed-off-by: Andy Whitcroft <[email protected]>
  34. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  35. (cherry picked from commit 0f7d5518c91335584b16c7bed1c54c10b78ea76a)
  36. Signed-off-by: Fabian Grünbichler <[email protected]>
  37. ---
  38. arch/x86/kernel/kprobes/common.h | 13 +++++++++++--
  39. 1 file changed, 11 insertions(+), 2 deletions(-)
  40. diff --git a/arch/x86/kernel/kprobes/common.h b/arch/x86/kernel/kprobes/common.h
  41. index db2182d63ed0..3fc0f9a794cb 100644
  42. --- a/arch/x86/kernel/kprobes/common.h
  43. +++ b/arch/x86/kernel/kprobes/common.h
  44. @@ -3,6 +3,15 @@
  45. /* Kprobes and Optprobes common header */
  46. +#include <asm/asm.h>
  47. +
  48. +#ifdef CONFIG_FRAME_POINTER
  49. +# define SAVE_RBP_STRING " push %" _ASM_BP "\n" \
  50. + " mov %" _ASM_SP ", %" _ASM_BP "\n"
  51. +#else
  52. +# define SAVE_RBP_STRING " push %" _ASM_BP "\n"
  53. +#endif
  54. +
  55. #ifdef CONFIG_X86_64
  56. #define SAVE_REGS_STRING \
  57. /* Skip cs, ip, orig_ax. */ \
  58. @@ -17,7 +26,7 @@
  59. " pushq %r10\n" \
  60. " pushq %r11\n" \
  61. " pushq %rbx\n" \
  62. - " pushq %rbp\n" \
  63. + SAVE_RBP_STRING \
  64. " pushq %r12\n" \
  65. " pushq %r13\n" \
  66. " pushq %r14\n" \
  67. @@ -48,7 +57,7 @@
  68. " pushl %es\n" \
  69. " pushl %ds\n" \
  70. " pushl %eax\n" \
  71. - " pushl %ebp\n" \
  72. + SAVE_RBP_STRING \
  73. " pushl %edi\n" \
  74. " pushl %esi\n" \
  75. " pushl %edx\n" \
  76. --
  77. 2.14.2