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

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