@@ -101,44 +101,42 @@ For 32-bit we have the following conventions - kernel is built with
101101 addq $ - (15 * 8 ), %rsp
102102 .endm
103103
104- .macro SAVE_REGS offset = 0
104+ .macro SAVE_AND_CLEAR_REGS offset = 0
105+ /*
106+ * Save registers and sanitize registers of values that a
107+ * speculation attack might otherwise want to exploit. The
108+ * lower registers are likely clobbered well before they
109+ * could be put to use in a speculative execution gadget.
110+ * Interleave XOR with PUSH for better uop scheduling:
111+ */
105112 movq %rdi , 14 * 8 + \offset (%rsp )
106113 movq %rsi , 13 * 8 + \offset (%rsp )
107114 movq %rdx , 12 * 8 + \offset (%rsp )
108115 movq %rcx , 11 * 8 + \offset (%rsp )
109116 movq %rax , 10 * 8 + \offset (%rsp )
110117 movq %r8 , 9 * 8 + \offset (%rsp )
118+ xorq %r8 , %r8 /* nospec r8 */
111119 movq %r9 , 8 * 8 + \offset (%rsp )
120+ xorq %r9 , %r9 /* nospec r9 */
112121 movq %r10 , 7 * 8 + \offset (%rsp )
122+ xorq %r10 , %r10 /* nospec r10 */
113123 movq %r11 , 6 * 8 + \offset (%rsp )
124+ xorq %r11 , %r11 /* nospec r11 */
114125 movq %rbx , 5 * 8 + \offset (%rsp )
126+ xorl %ebx , %ebx /* nospec rbx */
115127 movq %rbp , 4 * 8 + \offset (%rsp )
128+ xorl %ebp , %ebp /* nospec rbp */
116129 movq %r12 , 3 * 8 + \offset (%rsp )
130+ xorq %r12 , %r12 /* nospec r12 */
117131 movq %r13 , 2 * 8 + \offset (%rsp )
132+ xorq %r13 , %r13 /* nospec r13 */
118133 movq %r14 , 1 * 8 + \offset (%rsp )
134+ xorq %r14 , %r14 /* nospec r14 */
119135 movq %r15 , 0 * 8 + \offset (%rsp )
136+ xorq %r15 , %r15 /* nospec r15 */
120137 UNWIND_HINT_REGS offset = \offset
121138 .endm
122139
123- /*
124- * Sanitize registers of values that a speculation attack
125- * might otherwise want to exploit. The lower registers are
126- * likely clobbered well before they could be put to use in
127- * a speculative execution gadget:
128- */
129- .macro CLEAR_REGS_NOSPEC
130- xorl %ebp , %ebp
131- xorl %ebx , %ebx
132- xorq %r8 , %r8
133- xorq %r9 , %r9
134- xorq %r10 , %r10
135- xorq %r11 , %r11
136- xorq %r12 , %r12
137- xorq %r13 , %r13
138- xorq %r14 , %r14
139- xorq %r15 , %r15
140- .endm
141-
142140 .macro POP_REGS pop_rdi = 1 skip_r11rcx = 0
143141 popq %r15
144142 popq %r14
@@ -177,7 +175,7 @@ For 32-bit we have the following conventions - kernel is built with
177175 * is just setting the LSB, which makes it an invalid stack address and is also
178176 * a signal to the unwinder that it's a pt_regs pointer in disguise.
179177 *
180- * NOTE: This macro must be used *after* SAVE_REGS because it corrupts
178+ * NOTE: This macro must be used *after* SAVE_AND_CLEAR_REGS because it corrupts
181179 * the original rbp.
182180 */
183181.macro ENCODE_FRAME_POINTER ptregs_offset = 0
0 commit comments