提交 0123be42 编写于 作者: N Nadav Amit 提交者: Paolo Bonzini

KVM: x86: Assertions to check no overrun in MSR lists

Currently there is no check whether shared MSRs list overrun the allocated size
which can results in bugs. In addition there is no check that vmx->guest_msrs
has sufficient space to accommodate all the VMX msrs.  This patch adds the
assertions.
Signed-off-by: NNadav Amit <namit@cs.technion.ac.il>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 d6e8c854
...@@ -7608,6 +7608,8 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) ...@@ -7608,6 +7608,8 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
goto free_vcpu; goto free_vcpu;
vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL); vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
BUILD_BUG_ON(PAGE_SIZE / sizeof(struct shared_msr_entry) < NR_VMX_MSR);
err = -ENOMEM; err = -ENOMEM;
if (!vmx->guest_msrs) { if (!vmx->guest_msrs) {
goto uninit_vcpu; goto uninit_vcpu;
......
...@@ -212,6 +212,7 @@ static void shared_msr_update(unsigned slot, u32 msr) ...@@ -212,6 +212,7 @@ static void shared_msr_update(unsigned slot, u32 msr)
void kvm_define_shared_msr(unsigned slot, u32 msr) void kvm_define_shared_msr(unsigned slot, u32 msr)
{ {
BUG_ON(slot >= KVM_NR_SHARED_MSRS);
if (slot >= shared_msrs_global.nr) if (slot >= shared_msrs_global.nr)
shared_msrs_global.nr = slot + 1; shared_msrs_global.nr = slot + 1;
shared_msrs_global.msrs[slot] = msr; shared_msrs_global.msrs[slot] = msr;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册