0092-x86-entry-64-Simplify-reg-restore-code-in-the-standa.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Andy Lutomirski <[email protected]>
  3. Date: Thu, 2 Nov 2017 00:59:01 -0700
  4. Subject: [PATCH] x86/entry/64: Simplify reg restore code in the standard IRET
  5. paths
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. The old code restored all the registers with movq instead of pop.
  11. In theory, this was done because some CPUs have higher movq
  12. throughput, but any gain there would be tiny and is almost certainly
  13. outweighed by the higher text size.
  14. This saves 96 bytes of text.
  15. Signed-off-by: Andy Lutomirski <[email protected]>
  16. Cc: Borislav Petkov <[email protected]>
  17. Cc: Brian Gerst <[email protected]>
  18. Cc: Dave Hansen <[email protected]>
  19. Cc: Linus Torvalds <[email protected]>
  20. Cc: Peter Zijlstra <[email protected]>
  21. Cc: Thomas Gleixner <[email protected]>
  22. Link: http://lkml.kernel.org/r/ad82520a207ccd851b04ba613f4f752b33ac05f7.1509609304.git.luto@kernel.org
  23. Signed-off-by: Ingo Molnar <[email protected]>
  24. (cherry picked from commit e872045bfd9c465a8555bab4b8567d56a4d2d3bb)
  25. Signed-off-by: Andy Whitcroft <[email protected]>
  26. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  27. (cherry picked from commit f926575cd370de4052e89477582b349af5664a56)
  28. Signed-off-by: Fabian Grünbichler <[email protected]>
  29. ---
  30. arch/x86/entry/calling.h | 21 +++++++++++++++++++++
  31. arch/x86/entry/entry_64.S | 12 ++++++------
  32. 2 files changed, 27 insertions(+), 6 deletions(-)
  33. diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
  34. index 640aafebdc00..0b9dd8123701 100644
  35. --- a/arch/x86/entry/calling.h
  36. +++ b/arch/x86/entry/calling.h
  37. @@ -151,6 +151,27 @@ For 32-bit we have the following conventions - kernel is built with
  38. UNWIND_HINT_REGS offset=\offset extra=0
  39. .endm
  40. + .macro POP_EXTRA_REGS
  41. + popq %r15
  42. + popq %r14
  43. + popq %r13
  44. + popq %r12
  45. + popq %rbp
  46. + popq %rbx
  47. + .endm
  48. +
  49. + .macro POP_C_REGS
  50. + popq %r11
  51. + popq %r10
  52. + popq %r9
  53. + popq %r8
  54. + popq %rax
  55. + popq %rcx
  56. + popq %rdx
  57. + popq %rsi
  58. + popq %rdi
  59. + .endm
  60. +
  61. .macro RESTORE_C_REGS_HELPER rstor_rax=1, rstor_rcx=1, rstor_r11=1, rstor_r8910=1, rstor_rdx=1
  62. .if \rstor_r11
  63. movq 6*8(%rsp), %r11
  64. diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
  65. index 7c8258e3ad2d..a1a86e782a0e 100644
  66. --- a/arch/x86/entry/entry_64.S
  67. +++ b/arch/x86/entry/entry_64.S
  68. @@ -618,9 +618,9 @@ GLOBAL(swapgs_restore_regs_and_return_to_usermode)
  69. 1:
  70. #endif
  71. SWAPGS
  72. - RESTORE_EXTRA_REGS
  73. - RESTORE_C_REGS
  74. - REMOVE_PT_GPREGS_FROM_STACK 8
  75. + POP_EXTRA_REGS
  76. + POP_C_REGS
  77. + addq $8, %rsp /* skip regs->orig_ax */
  78. INTERRUPT_RETURN
  79. @@ -650,9 +650,9 @@ GLOBAL(restore_regs_and_return_to_kernel)
  80. ud2
  81. 1:
  82. #endif
  83. - RESTORE_EXTRA_REGS
  84. - RESTORE_C_REGS
  85. - REMOVE_PT_GPREGS_FROM_STACK 8
  86. + POP_EXTRA_REGS
  87. + POP_C_REGS
  88. + addq $8, %rsp /* skip regs->orig_ax */
  89. INTERRUPT_RETURN
  90. ENTRY(native_iret)
  91. --
  92. 2.14.2