]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.1.1/kvm-s390-check-cpu_id-prior-to-using-it.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.1.1 / kvm-s390-check-cpu_id-prior-to-using-it.patch
1 From 4d47555a80495657161a7e71ec3014ff2021e450 Mon Sep 17 00:00:00 2001
2 From: Carsten Otte <cotte@de.ibm.com>
3 Date: Tue, 18 Oct 2011 12:27:12 +0200
4 Subject: KVM: s390: check cpu_id prior to using it
5
6 From: Carsten Otte <cotte@de.ibm.com>
7
8 commit 4d47555a80495657161a7e71ec3014ff2021e450 upstream.
9
10 We use the cpu id provided by userspace as array index here. Thus we
11 clearly need to check it first. Ooops.
12
13 Signed-off-by: Carsten Otte <cotte@de.ibm.com>
14 Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
15 Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
16 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
17
18 ---
19 arch/s390/kvm/kvm-s390.c | 14 ++++++++++----
20 1 file changed, 10 insertions(+), 4 deletions(-)
21
22 --- a/arch/s390/kvm/kvm-s390.c
23 +++ b/arch/s390/kvm/kvm-s390.c
24 @@ -312,11 +312,17 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu
25 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
26 unsigned int id)
27 {
28 - struct kvm_vcpu *vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL);
29 - int rc = -ENOMEM;
30 + struct kvm_vcpu *vcpu;
31 + int rc = -EINVAL;
32
33 + if (id >= KVM_MAX_VCPUS)
34 + goto out;
35 +
36 + rc = -ENOMEM;
37 +
38 + vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL);
39 if (!vcpu)
40 - goto out_nomem;
41 + goto out;
42
43 vcpu->arch.sie_block = (struct kvm_s390_sie_block *)
44 get_zeroed_page(GFP_KERNEL);
45 @@ -352,7 +358,7 @@ out_free_sie_block:
46 free_page((unsigned long)(vcpu->arch.sie_block));
47 out_free_cpu:
48 kfree(vcpu);
49 -out_nomem:
50 +out:
51 return ERR_PTR(rc);
52 }
53