when vmlaunch or vmresume fails.
Follow the lead of clang and the intel recommendation and do an lfence
after the pause in the speculation-stop path for retpoline, RSB refill,
and meltover ASM bits.
ok kettenis@ deraadt@
-/* $OpenBSD: locore.S,v 1.106 2018/07/23 17:54:04 guenther Exp $ */
+/* $OpenBSD: locore.S,v 1.107 2018/07/24 02:42:25 guenther Exp $ */
/* $NetBSD: locore.S,v 1.13 2004/03/25 18:33:17 drochner Exp $ */
/*
movq PCB_CR3(%r13),%rax
movq %rax,%cr3 /* %rax used below too */
+ /*
+ * If we switched from a userland thread with a shallow call stack
+ * (e.g interrupt->ast->mi_ast->prempt->mi_switch->cpu_switchto)
+ * then the RSB may have attacker controlled entries when we switch
+ * to a deeper call stack in the new thread. Refill the RSB with
+ * entries safe to speculate into/through.
+ */
+ RET_STACK_REFILL_WITH_RCX
+
/* Don't bother with the rest if switching to a system process. */
testl $P_SYSTEM,P_FLAG(%r12)
jnz switch_restored
movq CPUVAR(KERN_CR3),%rax
movq %rax,%cr3
0: pause
+ lfence
jmp 0b
KUTEXT_PAGE_END
movq %rax,%cr3
Xsyscall_trampback:
0: pause
+ lfence
jmp 0b
CODEPATCH_END(CPTAG_MELTDOWN_NOP)
swapgs
movq %rax,%cr3
Xiretq_trampback:
0: pause
+ lfence
jmp 0b
.space 5,0xcc /* pad to match "movq CPUVAR(SCRATCH),%rax" */
CODEPATCH_END(CPTAG_MELTDOWN_NOP)
-/* $OpenBSD: vector.S,v 1.74 2018/07/21 02:19:54 guenther Exp $ */
+/* $OpenBSD: vector.S,v 1.75 2018/07/24 02:42:25 guenther Exp $ */
/* $NetBSD: vector.S,v 1.5 2004/06/28 09:13:11 fvdl Exp $ */
/*
movq CPUVAR(KERN_CR3),%rax
movq %rax,%cr3
0: pause
+ lfence
jmp 0b
KUTEXT_PAGE_END
-/* $OpenBSD: vmm_support.S,v 1.11 2018/07/03 23:21:15 mortimer Exp $ */
+/* $OpenBSD: vmm_support.S,v 1.12 2018/07/24 02:42:25 guenther Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
*
movq 0x00(%rsi), %rsi
vmresume
fail_launch_or_resume:
+ RET_STACK_REFILL_WITH_RCX
+
/* Failed launch/resume (fell through) */
jc fail_launch_invalid_vmcs /* Invalid VMCS */
jz fail_launch_valid_vmcs /* Valid VMCS, failed launch/resume */
/* %rdi = 0 means we took an exit */
xorq %rdi, %rdi
+ RET_STACK_REFILL_WITH_RCX
+
restore_host:
popq %rbx
popq %rbp
-/* $OpenBSD: asm.h,v 1.16 2018/07/23 17:54:04 guenther Exp $ */
+/* $OpenBSD: asm.h,v 1.17 2018/07/24 02:42:25 guenther Exp $ */
/* $NetBSD: asm.h,v 1.2 2003/05/02 18:05:47 yamt Exp $ */
/*-
_ALIGN_TEXT ; \
3: call 5f ; \
4: pause ; \
+ lfence ; \
call 4b ; \
_ALIGN_TRAPS ; \
5: call 7f ; \
6: pause ; \
+ lfence ; \
call 6b ; \
_ALIGN_TRAPS ; \
7: loop 3b ; \
#define JMP_RETPOLINE(reg) \
call 69f ; \
68: pause ; \
+ lfence ; \
jmp 68b ; \
_ALIGN_TRAPS ; \
69: mov %reg,(%rsp) ; \
-/* $OpenBSD: cpufunc.h,v 1.27 2018/07/23 17:54:04 guenther Exp $ */
+/* $OpenBSD: cpufunc.h,v 1.28 2018/07/24 02:42:25 guenther Exp $ */
/* $NetBSD: cpufunc.h,v 1.3 2003/05/08 10:27:43 fvdl Exp $ */
/*-
" .align 16,0x90 ;"
"3: call 5f ;"
"4: pause ;"
+ " lfence ;"
" call 4b ;"
" .align 16,0xcc ;"
"5: call 7f ;"
"6: pause ;"
+ " lfence ;"
" call 6b ;"
" .align 16,0xcc ;"
"7: loop 3b ;"