Skip to content

Commit 2ed57bb

Browse files
committed
KVM: VMX: Bug the VM if either MSR auto-load list is full
WARN and bug the VM if either MSR auto-load list is full when adding an MSR to the lists, as the set of MSRs that KVM loads via the lists is finite and entirely KVM controlled, i.e. overflowing the lists shouldn't be possible in a fully released version of KVM. Terminate the VM as the core KVM infrastructure has no insight as to _why_ an MSR is being added to the list, and failure to load an MSR on VM-Enter and/or VM-Exit could be fatal to the host. E.g. running the host with a guest-controlled PEBS MSR could generate unexpected writes to the DS buffer and crash the host. Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Tested-by: Manali Shukla <manali.shukla@amd.com> Link: https://patch.msgid.link/20251206001720.468579-40-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 84ac000 commit 2ed57bb

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

arch/x86/kvm/vmx/vmx.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
10981098
{
10991099
int i, j = 0;
11001100
struct msr_autoload *m = &vmx->msr_autoload;
1101+
struct kvm *kvm = vmx->vcpu.kvm;
11011102

11021103
switch (msr) {
11031104
case MSR_EFER:
@@ -1134,12 +1135,10 @@ static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
11341135
i = vmx_find_loadstore_msr_slot(&m->guest, msr);
11351136
j = vmx_find_loadstore_msr_slot(&m->host, msr);
11361137

1137-
if ((i < 0 && m->guest.nr == MAX_NR_LOADSTORE_MSRS) ||
1138-
(j < 0 && m->host.nr == MAX_NR_LOADSTORE_MSRS)) {
1139-
printk_once(KERN_WARNING "Not enough msr switch entries. "
1140-
"Can't add msr %x\n", msr);
1138+
if (KVM_BUG_ON(i < 0 && m->guest.nr == MAX_NR_LOADSTORE_MSRS, kvm) ||
1139+
KVM_BUG_ON(j < 0 && m->host.nr == MAX_NR_LOADSTORE_MSRS, kvm))
11411140
return;
1142-
}
1141+
11431142
if (i < 0) {
11441143
i = m->guest.nr++;
11451144
vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, m->guest.nr);

0 commit comments

Comments
 (0)