Commit f45755b8 authored by Xiaotian Feng's avatar Xiaotian Feng Committed by Avi Kivity

KVM: fix poison overwritten caused by using wrong xstate size

fpu.state is allocated from task_xstate_cachep, the size of task_xstate_cachep
is xstate_size. xstate_size is set from cpuid instruction, which is often
smaller than sizeof(struct xsave_struct). kvm is using sizeof(struct xsave_struct)
to fill in/out fpu.state.xsave, as what we allocated for fpu.state is
xstate_size, kernel will write out of memory and caused poison/redzone/padding
overwritten warnings.
Signed-off-by: default avatarXiaotian Feng <dfeng@redhat.com>
Reviewed-by: default avatarSheng Yang <sheng@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Sheng Yang <sheng@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 3cfc2c42
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
static unsigned int mxcsr_feature_mask __read_mostly = 0xffffffffu; static unsigned int mxcsr_feature_mask __read_mostly = 0xffffffffu;
unsigned int xstate_size; unsigned int xstate_size;
EXPORT_SYMBOL_GPL(xstate_size);
unsigned int sig_xstate_ia32_size = sizeof(struct _fpstate_ia32); unsigned int sig_xstate_ia32_size = sizeof(struct _fpstate_ia32);
static struct i387_fxsave_struct fx_scratch __cpuinitdata; static struct i387_fxsave_struct fx_scratch __cpuinitdata;
......
...@@ -2387,7 +2387,7 @@ static void kvm_vcpu_ioctl_x86_get_xsave(struct kvm_vcpu *vcpu, ...@@ -2387,7 +2387,7 @@ static void kvm_vcpu_ioctl_x86_get_xsave(struct kvm_vcpu *vcpu,
if (cpu_has_xsave) if (cpu_has_xsave)
memcpy(guest_xsave->region, memcpy(guest_xsave->region,
&vcpu->arch.guest_fpu.state->xsave, &vcpu->arch.guest_fpu.state->xsave,
sizeof(struct xsave_struct)); xstate_size);
else { else {
memcpy(guest_xsave->region, memcpy(guest_xsave->region,
&vcpu->arch.guest_fpu.state->fxsave, &vcpu->arch.guest_fpu.state->fxsave,
...@@ -2405,7 +2405,7 @@ static int kvm_vcpu_ioctl_x86_set_xsave(struct kvm_vcpu *vcpu, ...@@ -2405,7 +2405,7 @@ static int kvm_vcpu_ioctl_x86_set_xsave(struct kvm_vcpu *vcpu,
if (cpu_has_xsave) if (cpu_has_xsave)
memcpy(&vcpu->arch.guest_fpu.state->xsave, memcpy(&vcpu->arch.guest_fpu.state->xsave,
guest_xsave->region, sizeof(struct xsave_struct)); guest_xsave->region, xstate_size);
else { else {
if (xstate_bv & ~XSTATE_FPSSE) if (xstate_bv & ~XSTATE_FPSSE)
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment