[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <406DB587-F598-484F-A128-990E2DB6EC78@intel.com>
Date: Tue, 29 Jun 2021 18:35:39 +0000
From: "Bae, Chang Seok" <chang.seok.bae@...el.com>
To: "Hansen, Dave" <dave.hansen@...el.com>
CC: "Lutomirski, Andy" <luto@...nel.org>, Borislav Petkov <bp@...e.de>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...nel.org>, "X86 ML" <x86@...nel.org>,
"Brown, Len" <len.brown@...el.com>,
"Liu, Jing2" <jing2.liu@...el.com>,
"Shankar, Ravi V" <ravi.v.shankar@...el.com>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v5 14/28] x86/fpu/xstate: Prevent unauthorised use of
dynamic user state
On Jun 29, 2021, at 10:54, Hansen, Dave <dave.hansen@...el.com> wrote:
> How about we pay this 26-cycle cost, but only when XFD is in use? We
> could either look at the shadowed value of the XFD MSR, or flip a global
> variable the first time XFD gets used.
How about something like this:
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 777cccab0b47..9752ebe6be79 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -99,6 +99,23 @@ EXPORT_SYMBOL(irq_fpu_usable);
void save_fpregs_to_fpstate(struct fpu *fpu)
{
if (likely(use_xsave())) {
+ /*
+ * MSR IA32_XFD write follows after this XSAVE(S). So if a
+ * state component is in use, XFD should not be armed for
+ * current. But, for potential changes in the future,
+ * cross-check XINUSE and XFD values. If a XINUSE state
+ * is XFD-armed, the following XSAVE(S) does not save the
+ * state.
+ *
+ * Reference the shadow XFD value instead of reading the
+ * MSR.
+ */
+ if (xfd_capable() && boot_cpu_has(X86_FEATURE_XGETBV1)) {
+ u64 current_xfd = (fpu->state_mask & xfd_capable()) ^ xfd_capable();
+
+ WARN_ON_FPU(xgetbv(1) & current_xfd);
+ }
+
os_xsave(&fpu->state->xsave, fpu->state_mask);
Thanks,
Chang
Powered by blists - more mailing lists