lkml.org 
[lkml]   [2008]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 39/40] KVM: Reduce stack usage in kvm_arch_vcpu_ioctl()
    Date
    From: Dave Hansen <dave@linux.vnet.ibm.com>

    [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>
    ---
    arch/x86/kvm/x86.c | 23 +++++++++++++++--------
    1 files changed, 15 insertions(+), 8 deletions(-)

    diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
    index 87d4342..f1b0223 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,
    struct kvm_vcpu *vcpu = filp->private_data;
    void __user *argp = (void __user *)arg;
    int r;
    + struct kvm_lapic_state *lapic = NULL;

    switch (ioctl) {
    case KVM_GET_LAPIC: {
    - struct kvm_lapic_state lapic;
    + lapic = kzalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL);

    - memset(&lapic, 0, sizeof lapic);
    - r = kvm_vcpu_ioctl_get_lapic(vcpu, &lapic);
    + r = -ENOMEM;
    + if (!lapic)
    + goto out;
    + r = kvm_vcpu_ioctl_get_lapic(vcpu, lapic);
    if (r)
    goto out;
    r = -EFAULT;
    - if (copy_to_user(argp, &lapic, sizeof lapic))
    + if (copy_to_user(argp, lapic, sizeof(struct kvm_lapic_state)))
    goto out;
    r = 0;
    break;
    }
    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;
    - if (copy_from_user(&lapic, argp, sizeof lapic))
    + if (copy_from_user(lapic, argp, sizeof(struct kvm_lapic_state)))
    goto out;
    - r = kvm_vcpu_ioctl_set_lapic(vcpu, &lapic);;
    + r = kvm_vcpu_ioctl_set_lapic(vcpu, lapic);
    if (r)
    goto out;
    r = 0;
    @@ -1661,6 +1666,8 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
    r = -EINVAL;
    }
    out:
    + if (lapic)
    + kfree(lapic);
    return r;
    }

    --
    1.6.0.1


    \
     
     \ /
      Last update: 2008-09-23 16:09    [W:0.023 / U:62.100 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site