Skip to content

Commit 2333f3c

Browse files
Peter Zijlstra (Intel)bp3tk0v
authored andcommitted
x86/entry/calling: Allow PUSH_AND_CLEAR_REGS being used beyond actual entry code
PUSH_AND_CLEAR_REGS could be used besides actual entry code; in that case %rbp shouldn't be cleared (otherwise the frame pointer is destroyed) and UNWIND_HINT shouldn't be added. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Xin Li <xin3.li@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Tested-by: Shan Kang <shan.kang@intel.com> Link: https://lore.kernel.org/r/20231205105030.8698-31-xin3.li@intel.com
1 parent 5105e76 commit 2333f3c

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

arch/x86/entry/calling.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ For 32-bit we have the following conventions - kernel is built with
6565
* for assembly code:
6666
*/
6767

68-
.macro PUSH_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0
68+
.macro PUSH_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0 unwind_hint=1
6969
.if \save_ret
7070
pushq %rsi /* pt_regs->si */
7171
movq 8(%rsp), %rsi /* temporarily store the return address in %rsi */
@@ -87,14 +87,17 @@ For 32-bit we have the following conventions - kernel is built with
8787
pushq %r13 /* pt_regs->r13 */
8888
pushq %r14 /* pt_regs->r14 */
8989
pushq %r15 /* pt_regs->r15 */
90+
91+
.if \unwind_hint
9092
UNWIND_HINT_REGS
93+
.endif
9194

9295
.if \save_ret
9396
pushq %rsi /* return address on top of stack */
9497
.endif
9598
.endm
9699

97-
.macro CLEAR_REGS
100+
.macro CLEAR_REGS clear_bp=1
98101
/*
99102
* Sanitize registers of values that a speculation attack might
100103
* otherwise want to exploit. The lower registers are likely clobbered
@@ -109,17 +112,19 @@ For 32-bit we have the following conventions - kernel is built with
109112
xorl %r10d, %r10d /* nospec r10 */
110113
xorl %r11d, %r11d /* nospec r11 */
111114
xorl %ebx, %ebx /* nospec rbx */
115+
.if \clear_bp
112116
xorl %ebp, %ebp /* nospec rbp */
117+
.endif
113118
xorl %r12d, %r12d /* nospec r12 */
114119
xorl %r13d, %r13d /* nospec r13 */
115120
xorl %r14d, %r14d /* nospec r14 */
116121
xorl %r15d, %r15d /* nospec r15 */
117122

118123
.endm
119124

120-
.macro PUSH_AND_CLEAR_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0
121-
PUSH_REGS rdx=\rdx, rcx=\rcx, rax=\rax, save_ret=\save_ret
122-
CLEAR_REGS
125+
.macro PUSH_AND_CLEAR_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0 clear_bp=1 unwind_hint=1
126+
PUSH_REGS rdx=\rdx, rcx=\rcx, rax=\rax, save_ret=\save_ret unwind_hint=\unwind_hint
127+
CLEAR_REGS clear_bp=\clear_bp
123128
.endm
124129

125130
.macro POP_REGS pop_rdi=1

0 commit comments

Comments
 (0)