Skip to contentSkip to conversation

x86/fpu: Fix get_xsave_addr which returns error pointer to KVM

PATCH In review Huaitong Han 3 participants 3 messages Nov 6, 2015 – Nov 12, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/fpu: Fix get_xsave_addr which returns error pointer to KVM

when KVM uses the get_xsave_addr, xsave parameter belongs to guest vcpu, if xsave is replaced with current task (host) xsave, get_xsave_addr will return error xsave addr to KVM.

---
 arch/x86/kernel/fpu/xstate.c | 1 -
 1 file changed, 1 deletion(-)
arch/x86/kernel/fpu/xstate.c +0 -1
index 62fc001..2c4ac07 100644
@@ -402,7 +402,6 @@ void *get_xsave_addr(struct xregs_state *xsave, int xstate_feature)
 	if (!boot_cpu_has(X86_FEATURE_XSAVE))
 		return NULL;
 
-	xsave = &current->thread.fpu.state.xsave;
 	/*
 	 * We should not ever be requesting features that we
 	 * have not enabled.  Remember that pcntxt_mask is
Signature · 1 line
2.4.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Huaitong Han

when KVM uses the get_xsave_addr, xsave parameter belongs to guest vcpu, if xsave is replaced with current task (host) xsave, get_xsave_addr will return error xsave addr to KVM.

Looks good to me. It was completely bogus that we passed 'xsave' in there and then just wrote over it.

#2 lore raw

[tip:x86/urgent] x86/fpu: Fix get_xsave_addr() behavior under virtualization

In reply to Huaitong Han
x86/fpu: Fix get_xsave_addr() behavior under virtualization
Commit-ID:  a05917b6ba9dc9a95fc42bdcbe3a875e8ad83935
Gitweb:     http://git.kernel.org/tip/a05917b6ba9dc9a95fc42bdcbe3a875e8ad83935
Author:     Huaitong Han <[email protected]>
AuthorDate: Fri, 6 Nov 2015 17:00:23 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 12 Nov 2015 09:34:58 +0100

x86/fpu: Fix get_xsave_addr() behavior under virtualization

KVM uses the get_xsave_addr() function in a different fashion from the native kernel, in that the 'xsave' parameter belongs to guest vcpu, not the currently running task.

But 'xsave' is replaced with current task's (host) xsave structure, so get_xsave_addr() will incorrectly return the bad xsave address to KVM.

Fix it so that the passed in 'xsave' address is used - as intended originally.

Cc Andy Lutomirski <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Quentin Casasnovas <[email protected]>
Cc Thomas Gleixner <[email protected]>
[ Tidied up the changelog. ]
---
 arch/x86/kernel/fpu/xstate.c | 1 -
 1 file changed, 1 deletion(-)
arch/x86/kernel/fpu/xstate.c +0 -1
index 6454f27..70fc312 100644
@@ -694,7 +694,6 @@ void *get_xsave_addr(struct xregs_state *xsave, int xstate_feature)
 	if (!boot_cpu_has(X86_FEATURE_XSAVE))
 		return NULL;
 
-	xsave = &current->thread.fpu.state.xsave;
 	/*
 	 * We should not ever be requesting features that we
 	 * have not enabled.  Remember that pcntxt_mask is