Commit b772ff36 authored by Dave Hansen's avatar Dave Hansen Committed by Avi Kivity

KVM: Reduce stack usage in kvm_arch_vcpu_ioctl()

[sheng: fix KVM_GET_LAPIC using wrong size]
Signed-off-by: default avatarDave Hansen <dave@linux.vnet.ibm.com>
Signed-off-by: default avatarSheng Yang <sheng.yang@intel.com>
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent fa3795a7
...@@ -1542,28 +1542,33 @@ long kvm_arch_vcpu_ioctl(struct file *filp, ...@@ -1542,28 +1542,33 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
struct kvm_vcpu *vcpu = filp->private_data; struct kvm_vcpu *vcpu = filp->private_data;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
int r; int r;
struct kvm_lapic_state *lapic = NULL;
switch (ioctl) { switch (ioctl) {
case KVM_GET_LAPIC: { case KVM_GET_LAPIC: {
struct kvm_lapic_state lapic; lapic = kzalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL);
memset(&lapic, 0, sizeof lapic); r = -ENOMEM;
r = kvm_vcpu_ioctl_get_lapic(vcpu, &lapic); if (!lapic)
goto out;
r = kvm_vcpu_ioctl_get_lapic(vcpu, lapic);
if (r) if (r)
goto out; goto out;
r = -EFAULT; r = -EFAULT;
if (copy_to_user(argp, &lapic, sizeof lapic)) if (copy_to_user(argp, lapic, sizeof(struct kvm_lapic_state)))
goto out; goto out;
r = 0; r = 0;
break; break;
} }
case KVM_SET_LAPIC: { case KVM_SET_LAPIC: {
struct kvm_lapic_state lapic; lapic = kmalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL);
r = -ENOMEM;
if (!lapic)
goto out;
r = -EFAULT; r = -EFAULT;
if (copy_from_user(&lapic, argp, sizeof lapic)) if (copy_from_user(lapic, argp, sizeof(struct kvm_lapic_state)))
goto out; goto out;
r = kvm_vcpu_ioctl_set_lapic(vcpu, &lapic);; r = kvm_vcpu_ioctl_set_lapic(vcpu, lapic);
if (r) if (r)
goto out; goto out;
r = 0; r = 0;
...@@ -1661,6 +1666,8 @@ long kvm_arch_vcpu_ioctl(struct file *filp, ...@@ -1661,6 +1666,8 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
r = -EINVAL; r = -EINVAL;
} }
out: out:
if (lapic)
kfree(lapic);
return r; return r;
} }
......
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