aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorDave Hansen <dave@linux.vnet.ibm.com>2008-08-11 13:01:47 -0400
committerAvi Kivity <avi@qumranet.com>2008-10-15 04:15:18 -0400
commitb772ff362ec6b821c8a5227a3355e263f917bfad (patch)
tree0429106a384afa54f6887380795d568ec9b16d23 /arch/x86/kvm/x86.c
parentfa3795a7308df099f0f2c9e5ca2c20a5ff65bdc4 (diff)
KVM: Reduce stack usage in kvm_arch_vcpu_ioctl()
[sheng: fix KVM_GET_LAPIC using wrong size] Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com> Signed-off-by: Sheng Yang <sheng.yang@intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 87d434228fe2..f1b0223c4088 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1542,28 +1542,33 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
1542 struct kvm_vcpu *vcpu = filp->private_data; 1542 struct kvm_vcpu *vcpu = filp->private_data;
1543 void __user *argp = (void __user *)arg; 1543 void __user *argp = (void __user *)arg;
1544 int r; 1544 int r;
1545 struct kvm_lapic_state *lapic = NULL;
1545 1546
1546 switch (ioctl) { 1547 switch (ioctl) {
1547 case KVM_GET_LAPIC: { 1548 case KVM_GET_LAPIC: {
1548 struct kvm_lapic_state lapic; 1549 lapic = kzalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL);
1549 1550
1550 memset(&lapic, 0, sizeof lapic); 1551 r = -ENOMEM;
1551 r = kvm_vcpu_ioctl_get_lapic(vcpu, &lapic); 1552 if (!lapic)
1553 goto out;
1554 r = kvm_vcpu_ioctl_get_lapic(vcpu, lapic);
1552 if (r) 1555 if (r)
1553 goto out; 1556 goto out;
1554 r = -EFAULT; 1557 r = -EFAULT;
1555 if (copy_to_user(argp, &lapic, sizeof lapic)) 1558 if (copy_to_user(argp, lapic, sizeof(struct kvm_lapic_state)))
1556 goto out; 1559 goto out;
1557 r = 0; 1560 r = 0;
1558 break; 1561 break;
1559 } 1562 }
1560 case KVM_SET_LAPIC: { 1563 case KVM_SET_LAPIC: {
1561 struct kvm_lapic_state lapic; 1564 lapic = kmalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL);
1562 1565 r = -ENOMEM;
1566 if (!lapic)
1567 goto out;
1563 r = -EFAULT; 1568 r = -EFAULT;
1564 if (copy_from_user(&lapic, argp, sizeof lapic)) 1569 if (copy_from_user(lapic, argp, sizeof(struct kvm_lapic_state)))
1565 goto out; 1570 goto out;
1566 r = kvm_vcpu_ioctl_set_lapic(vcpu, &lapic);; 1571 r = kvm_vcpu_ioctl_set_lapic(vcpu, lapic);
1567 if (r) 1572 if (r)
1568 goto out; 1573 goto out;
1569 r = 0; 1574 r = 0;
@@ -1661,6 +1666,8 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
1661 r = -EINVAL; 1666 r = -EINVAL;
1662 } 1667 }
1663out: 1668out:
1669 if (lapic)
1670 kfree(lapic);
1664 return r; 1671 return r;
1665} 1672}
1666 1673