]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: s390: check cpu_id prior to using it
authorCarsten Otte <cotte@de.ibm.com>
Tue, 18 Oct 2011 10:27:12 +0000 (12:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 11 Feb 2012 14:37:46 +0000 (15:37 +0100)
commit 4d47555a80495657161a7e71ec3014ff2021e450 upstream.

We use the cpu id provided by userspace as array index here. Thus we
clearly need to check it first. Ooops.

Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Willy Tarreau <w@1wt.eu>
arch/s390/kvm/kvm-s390.c

index 8b00eb2ddf57459c9469d8455d0762d365a71c1f..26a73dae020642f2827bc753efe07fd0787e484a 100644 (file)
@@ -274,11 +274,17 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
                                      unsigned int id)
 {
-       struct kvm_vcpu *vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL);
-       int rc = -ENOMEM;
+       struct kvm_vcpu *vcpu;
+       int rc = -EINVAL;
 
+       if (id >= KVM_MAX_VCPUS)
+               goto out;
+
+       rc = -ENOMEM;
+
+       vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL);
        if (!vcpu)
-               goto out_nomem;
+               goto out;
 
        vcpu->arch.sie_block = (struct kvm_s390_sie_block *)
                                        get_zeroed_page(GFP_KERNEL);
@@ -313,7 +319,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
        return vcpu;
 out_free_cpu:
        kfree(vcpu);
-out_nomem:
+out:
        return ERR_PTR(rc);
 }