Skip to content

Commit f9a4186

Browse files
committed
Merge: x86/fpu: Keep xfd_state in sync with MSR_IA32_XFD
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4288 JIRA: https://issues.redhat.com/browse/RHEL-36996 CVE: CVE-2024-35801 Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=61392845 Tested: Successful sanity booted on Intel systems. commit 10e4b51 Author: Adamos Ttofari <attofari@amazon.de> Date: Fri Mar 22 16:04:39 2024 -0700 x86/fpu: Keep xfd_state in sync with MSR_IA32_XFD Commit 6723654 ("x86/fpu: Update XFD state where required") and commit 8bf2675 ("x86/fpu: Add XFD state to fpstate") introduced a per CPU variable xfd_state to keep the MSR_IA32_XFD value cached, in order to avoid unnecessary writes to the MSR. On CPU hotplug MSR_IA32_XFD is reset to the init_fpstate.xfd, which wipes out any stale state. But the per CPU cached xfd value is not reset, which brings them out of sync. As a consequence a subsequent xfd_update_state() might fail to update the MSR which in turn can result in XRSTOR raising a #NM in kernel space, which crashes the kernel. To fix this, introduce xfd_set_state() to write xfd_state together with MSR_IA32_XFD, and use it in all places that set MSR_IA32_XFD. Fixes: 6723654 ("x86/fpu: Update XFD state where required") Signed-off-by: Adamos Ttofari <attofari@amazon.de> Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20240322230439.456571-1-chang.seok.bae@intel.com Closes: https://lore.kernel.org/lkml/20230511152818.13839-1-attofari@amazon.de Signed-off-by: Steve Best <sbest@redhat.com> Approved-by: Tony Camuso <tcamuso@redhat.com> Approved-by: David Arcari <darcari@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents 6e17e31 + b5ca434 commit f9a4186

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

arch/x86/kernel/fpu/xstate.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,11 @@ void fpu__init_cpu_xstate(void)
178178
* Must happen after CR4 setup and before xsetbv() to allow KVM
179179
* lazy passthrough. Write independent of the dynamic state static
180180
* key as that does not work on the boot CPU. This also ensures
181-
* that any stale state is wiped out from XFD.
181+
* that any stale state is wiped out from XFD. Reset the per CPU
182+
* xfd cache too.
182183
*/
183184
if (cpu_feature_enabled(X86_FEATURE_XFD))
184-
wrmsrl(MSR_IA32_XFD, init_fpstate.xfd);
185+
xfd_set_state(init_fpstate.xfd);
185186

186187
/*
187188
* XCR_XFEATURE_ENABLED_MASK (aka. XCR0) sets user features

arch/x86/kernel/fpu/xstate.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,26 @@ static inline void xfd_validate_state(struct fpstate *fpstate, u64 mask, bool rs
148148
#endif
149149

150150
#ifdef CONFIG_X86_64
151+
static inline void xfd_set_state(u64 xfd)
152+
{
153+
wrmsrl(MSR_IA32_XFD, xfd);
154+
__this_cpu_write(xfd_state, xfd);
155+
}
156+
151157
static inline void xfd_update_state(struct fpstate *fpstate)
152158
{
153159
if (fpu_state_size_dynamic()) {
154160
u64 xfd = fpstate->xfd;
155161

156-
if (__this_cpu_read(xfd_state) != xfd) {
157-
wrmsrl(MSR_IA32_XFD, xfd);
158-
__this_cpu_write(xfd_state, xfd);
159-
}
162+
if (__this_cpu_read(xfd_state) != xfd)
163+
xfd_set_state(xfd);
160164
}
161165
}
162166

163167
extern int __xfd_enable_feature(u64 which, struct fpu_guest *guest_fpu);
164168
#else
169+
static inline void xfd_set_state(u64 xfd) { }
170+
165171
static inline void xfd_update_state(struct fpstate *fpstate) { }
166172

167173
static inline int __xfd_enable_feature(u64 which, struct fpu_guest *guest_fpu) {

0 commit comments

Comments
 (0)