Thread (41 messages) 41 messages, 8 authors, 2023-10-25

Re: [PATCH 2/6] x86/entry_64: Add VERW just before userspace transition

From: Josh Poimboeuf <jpoimboe@kernel.org>
Date: 2023-10-23 18:35:29
Also in: kvm, lkml

On Fri, Oct 20, 2023 at 01:45:03PM -0700, Pawan Gupta wrote:
quoted hunk ↗ jump to hunk
@@ -663,6 +665,10 @@ SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL)
 	/* Restore RDI. */
 	popq	%rdi
 	swapgs
+
+	/* Mitigate CPU data sampling attacks .e.g. MDS */
+	USER_CLEAR_CPU_BUFFERS
+
 	jmp	.Lnative_iret
 
 
@@ -774,6 +780,9 @@ native_irq_return_ldt:
 	 */
 	popq	%rax				/* Restore user RAX */
 
+	/* Mitigate CPU data sampling attacks .e.g. MDS */
+	USER_CLEAR_CPU_BUFFERS
+
Can the above two USER_CLEAR_CPU_BUFFERS be replaced with a single one
just above native_irq_return_iret?  Otherwise the native_irq_return_ldt
case ends up getting two VERWs.
quoted hunk ↗ jump to hunk
 	/*
 	 * RSP now points to an ordinary IRET frame, except that the page
 	 * is read-only and RSP[31:16] are preloaded with the userspace
@@ -1502,6 +1511,9 @@ nmi_restore:
 	std
 	movq	$0, 5*8(%rsp)		/* clear "NMI executing" */
 
+	/* Mitigate CPU data sampling attacks .e.g. MDS */
+	USER_CLEAR_CPU_BUFFERS
+
 	/*
 	 * iretq reads the "iret" frame and exits the NMI stack in a
 	 * single instruction.  We are returning to kernel mode, so this
This isn't needed here.  This is the NMI return-to-kernel path.

The NMI return-to-user path is already mitigated as it goes through
swapgs_restore_regs_and_return_to_usermode.

-- 
Josh
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help