Skip to content

Commit 8c42819

Browse files
Peter Zijlstrasuryasaimadhu
authored andcommitted
x86/entry: Use PUSH_AND_CLEAR_REGS for compat
Since the upper regs don't exist for ia32 code, preserving them doesn't hurt and it simplifies the code. This doesn't add any attack surface that would not already be available through INT80. Notably: - 32bit SYSENTER: didn't clear si, dx, cx. - 32bit SYSCALL, INT80: *do* clear si since the C functions don't take a second argument. - 64bit: didn't clear si since the C functions take a second argument; except the error_entry path might have only one argument, so clearing si was missing here. 32b SYSENTER should be clearing all those 3 registers, nothing uses them and selftests pass. Unconditionally clear rsi since it simplifies code. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d205222 commit 8c42819

File tree

2 files changed

+4
-84
lines changed

2 files changed

+4
-84
lines changed

arch/x86/entry/calling.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ For 32-bit we have the following conventions - kernel is built with
9999
* well before they could be put to use in a speculative execution
100100
* gadget.
101101
*/
102+
xorl %esi, %esi /* nospec si */
102103
xorl %edx, %edx /* nospec dx */
103104
xorl %ecx, %ecx /* nospec cx */
104105
xorl %r8d, %r8d /* nospec r8 */

arch/x86/entry/entry_64_compat.S

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -83,32 +83,7 @@ SYM_INNER_LABEL(entry_SYSENTER_compat_after_hwframe, SYM_L_GLOBAL)
8383
movl %eax, %eax
8484

8585
pushq %rax /* pt_regs->orig_ax */
86-
pushq %rdi /* pt_regs->di */
87-
pushq %rsi /* pt_regs->si */
88-
pushq %rdx /* pt_regs->dx */
89-
pushq %rcx /* pt_regs->cx */
90-
pushq $-ENOSYS /* pt_regs->ax */
91-
pushq $0 /* pt_regs->r8 = 0 */
92-
xorl %r8d, %r8d /* nospec r8 */
93-
pushq $0 /* pt_regs->r9 = 0 */
94-
xorl %r9d, %r9d /* nospec r9 */
95-
pushq $0 /* pt_regs->r10 = 0 */
96-
xorl %r10d, %r10d /* nospec r10 */
97-
pushq $0 /* pt_regs->r11 = 0 */
98-
xorl %r11d, %r11d /* nospec r11 */
99-
pushq %rbx /* pt_regs->rbx */
100-
xorl %ebx, %ebx /* nospec rbx */
101-
pushq %rbp /* pt_regs->rbp (will be overwritten) */
102-
xorl %ebp, %ebp /* nospec rbp */
103-
pushq $0 /* pt_regs->r12 = 0 */
104-
xorl %r12d, %r12d /* nospec r12 */
105-
pushq $0 /* pt_regs->r13 = 0 */
106-
xorl %r13d, %r13d /* nospec r13 */
107-
pushq $0 /* pt_regs->r14 = 0 */
108-
xorl %r14d, %r14d /* nospec r14 */
109-
pushq $0 /* pt_regs->r15 = 0 */
110-
xorl %r15d, %r15d /* nospec r15 */
111-
86+
PUSH_AND_CLEAR_REGS rax=$-ENOSYS
11287
UNWIND_HINT_REGS
11388

11489
cld
@@ -225,35 +200,7 @@ SYM_INNER_LABEL(entry_SYSCALL_compat_safe_stack, SYM_L_GLOBAL)
225200
SYM_INNER_LABEL(entry_SYSCALL_compat_after_hwframe, SYM_L_GLOBAL)
226201
movl %eax, %eax /* discard orig_ax high bits */
227202
pushq %rax /* pt_regs->orig_ax */
228-
pushq %rdi /* pt_regs->di */
229-
pushq %rsi /* pt_regs->si */
230-
xorl %esi, %esi /* nospec si */
231-
pushq %rdx /* pt_regs->dx */
232-
xorl %edx, %edx /* nospec dx */
233-
pushq %rbp /* pt_regs->cx (stashed in bp) */
234-
xorl %ecx, %ecx /* nospec cx */
235-
pushq $-ENOSYS /* pt_regs->ax */
236-
pushq $0 /* pt_regs->r8 = 0 */
237-
xorl %r8d, %r8d /* nospec r8 */
238-
pushq $0 /* pt_regs->r9 = 0 */
239-
xorl %r9d, %r9d /* nospec r9 */
240-
pushq $0 /* pt_regs->r10 = 0 */
241-
xorl %r10d, %r10d /* nospec r10 */
242-
pushq $0 /* pt_regs->r11 = 0 */
243-
xorl %r11d, %r11d /* nospec r11 */
244-
pushq %rbx /* pt_regs->rbx */
245-
xorl %ebx, %ebx /* nospec rbx */
246-
pushq %rbp /* pt_regs->rbp (will be overwritten) */
247-
xorl %ebp, %ebp /* nospec rbp */
248-
pushq $0 /* pt_regs->r12 = 0 */
249-
xorl %r12d, %r12d /* nospec r12 */
250-
pushq $0 /* pt_regs->r13 = 0 */
251-
xorl %r13d, %r13d /* nospec r13 */
252-
pushq $0 /* pt_regs->r14 = 0 */
253-
xorl %r14d, %r14d /* nospec r14 */
254-
pushq $0 /* pt_regs->r15 = 0 */
255-
xorl %r15d, %r15d /* nospec r15 */
256-
203+
PUSH_AND_CLEAR_REGS rax=$-ENOSYS
257204
UNWIND_HINT_REGS
258205

259206
movq %rsp, %rdi
@@ -380,35 +327,7 @@ SYM_CODE_START(entry_INT80_compat)
380327
pushq 0*8(%rax) /* regs->orig_ax */
381328
.Lint80_keep_stack:
382329

383-
pushq %rdi /* pt_regs->di */
384-
pushq %rsi /* pt_regs->si */
385-
xorl %esi, %esi /* nospec si */
386-
pushq %rdx /* pt_regs->dx */
387-
xorl %edx, %edx /* nospec dx */
388-
pushq %rcx /* pt_regs->cx */
389-
xorl %ecx, %ecx /* nospec cx */
390-
pushq $-ENOSYS /* pt_regs->ax */
391-
pushq %r8 /* pt_regs->r8 */
392-
xorl %r8d, %r8d /* nospec r8 */
393-
pushq %r9 /* pt_regs->r9 */
394-
xorl %r9d, %r9d /* nospec r9 */
395-
pushq %r10 /* pt_regs->r10*/
396-
xorl %r10d, %r10d /* nospec r10 */
397-
pushq %r11 /* pt_regs->r11 */
398-
xorl %r11d, %r11d /* nospec r11 */
399-
pushq %rbx /* pt_regs->rbx */
400-
xorl %ebx, %ebx /* nospec rbx */
401-
pushq %rbp /* pt_regs->rbp */
402-
xorl %ebp, %ebp /* nospec rbp */
403-
pushq %r12 /* pt_regs->r12 */
404-
xorl %r12d, %r12d /* nospec r12 */
405-
pushq %r13 /* pt_regs->r13 */
406-
xorl %r13d, %r13d /* nospec r13 */
407-
pushq %r14 /* pt_regs->r14 */
408-
xorl %r14d, %r14d /* nospec r14 */
409-
pushq %r15 /* pt_regs->r15 */
410-
xorl %r15d, %r15d /* nospec r15 */
411-
330+
PUSH_AND_CLEAR_REGS rax=$-ENOSYS
412331
UNWIND_HINT_REGS
413332

414333
cld

0 commit comments

Comments
 (0)