The following commit has been merged in the linux branch: commit a9e38c3e01ad242fe2a625354cf065c34b01e3aa Author: Jan Kiszka jan.kiszka@siemens.com Date: Fri Oct 23 09:37:00 2009 +0200
KVM: x86: Catch potential overrun in MCE setup
We only allocate memory for 32 MCE banks (KVM_MAX_MCE_BANKS) but we allow user space to fill up to 255 on setup (mcg_cap & 0xff), corrupting kernel memory. Catch these overflows.
Signed-off-by: Jan Kiszka jan.kiszka@siemens.com Signed-off-by: Marcelo Tosatti mtosatti@redhat.com
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9b96953..8a93fa8 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1692,7 +1692,7 @@ static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu, unsigned bank_num = mcg_cap & 0xff, bank;
r = -EINVAL; - if (!bank_num) + if (!bank_num || bank_num >= KVM_MAX_MCE_BANKS) goto out; if (mcg_cap & ~(KVM_MCE_CAP_SUPPORTED | 0xff | 0xff0000)) goto out;