Module Name: src
Committed By: riastradh
Date: Mon Jul 20 16:37:35 UTC 2020
Modified Files:
src/sys/arch/x86/x86: fpu.c
Log Message:
Revert 1.67 "Restore the lwp's fpu state, not zeros, and leave with fpu
enabled."
This didn't actually avoid double-restore, and it doesn't solve the
problem anyway, and made it harder to detect in-kernel fpu abuse.
To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/x86/x86/fpu.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.68 src/sys/arch/x86/x86/fpu.c:1.69
--- src/sys/arch/x86/x86/fpu.c:1.68 Mon Jul 13 16:51:51 2020
+++ src/sys/arch/x86/x86/fpu.c Mon Jul 20 16:37:34 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fpu.c,v 1.68 2020/07/13 16:51:51 riastradh Exp $ */
+/* $NetBSD: fpu.c,v 1.69 2020/07/20 16:37:34 riastradh Exp $ */
/*
* Copyright (c) 2008, 2019 The NetBSD Foundation, Inc. All
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.68 2020/07/13 16:51:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.69 2020/07/20 16:37:34 riastradh Exp $");
#include "opt_multiprocessor.h"
@@ -421,9 +421,6 @@ void
fpu_kern_leave(void)
{
static const union savefpu zero_fpu __aligned(64);
- const union savefpu *savefpu;
- struct lwp *l = curlwp;
- struct pcb *pcb;
struct cpu_info *ci = curcpu();
int s;
@@ -431,18 +428,17 @@ fpu_kern_leave(void)
KASSERT(ci->ci_kfpu_spl != -1);
/*
- * Restore the FPU state immediately to avoid leaking any
- * kernel secrets, or zero it if this is a kthread.
+ * Zero the fpu registers; otherwise we might leak secrets
+ * through Spectre-class attacks to userland, even if there are
+ * no bugs in fpu state management.
*/
- if ((l->l_pflag & LP_INTR) && (l->l_switchto != NULL))
- l = l->l_switchto;
- if (l->l_flag & LW_SYSTEM) {
- savefpu = &zero_fpu;
- } else {
- pcb = lwp_getpcb(l);
- savefpu = &pcb->pcb_savefpu;
- }
- fpu_area_restore(savefpu, x86_xsave_features);
+ fpu_area_restore(&zero_fpu, x86_xsave_features);
+
+ /*
+ * Set CR0_TS again so that the kernel can't accidentally use
+ * the FPU.
+ */
+ stts();
s = ci->ci_kfpu_spl;
ci->ci_kfpu_spl = -1;