linux-stable/arch/x86/kvm
Sean Christopherson 36461b145e KVM: x86: Bail from kvm_recalculate_phys_map() if x2APIC ID is out-of-bounds
commit 4364b28798 upstream.

Bail from kvm_recalculate_phys_map() and disable the optimized map if the
target vCPU's x2APIC ID is out-of-bounds, i.e. if the vCPU was added
and/or enabled its local APIC after the map was allocated.  This fixes an
out-of-bounds access bug in the !x2apic_format path where KVM would write
beyond the end of phys_map.

Check the x2APIC ID regardless of whether or not x2APIC is enabled,
as KVM's hardcodes x2APIC ID to be the vCPU ID, i.e. it can't change, and
the map allocation in kvm_recalculate_apic_map() doesn't check for x2APIC
being enabled, i.e. the check won't get false postivies.

Note, this also affects the x2apic_format path, which previously just
ignored the "x2apic_id > new->max_apic_id" case.  That too is arguably a
bug fix, as ignoring the vCPU meant that KVM would not send interrupts to
the vCPU until the next map recalculation.  In practice, that "bug" is
likely benign as a newly present vCPU/APIC would immediately trigger a
recalc.  But, there's no functional downside to disabling the map, and
a future patch will gracefully handle the -E2BIG case by retrying instead
of simply disabling the optimized map.

Opportunistically add a sanity check on the xAPIC ID size, along with a
comment explaining why the xAPIC ID is guaranteed to be "good".

Reported-by: Michal Luczaj <mhal@rbox.co>
Fixes: 5b84b02917 ("KVM: x86: Honor architectural behavior for aliased 8-bit APIC IDs")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20230602233250.1014316-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-06-09 10:48:24 +02:00
..
mmu KVM: x86/mmu: Grab memslot for correct address space in NX recovery worker 2023-06-09 10:48:23 +02:00
svm KVM: SVM: Flush Hyper-V TLB when required 2023-03-27 10:10:26 -04:00
vmx KVM: VMX: Make CR0.WP a guest owned bit 2023-05-17 14:01:51 +02:00
.gitignore KVM: x86: use a separate asm-offsets.c file 2022-11-09 12:10:17 -05:00
Kconfig KVM: Opt out of generic hardware enabling on s390 and PPC 2022-12-29 15:48:37 -05:00
Makefile KVM: x86: Introduce .hv_inject_synthetic_vmexit_post_tlb_flush() nested hook 2022-11-18 12:59:13 -05:00
cpuid.c ARM: 2023-02-25 11:30:21 -08:00
cpuid.h KVM: x86: Add dedicated helper to get CPUID entry with significant index 2022-07-14 11:38:32 -04:00
debugfs.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
emulate.c ARM: 2023-02-25 11:30:21 -08:00
fpu.h
hyperv.c KVM x86 PMU changes for 6.3: 2023-02-15 08:23:24 -05:00
hyperv.h KVM: x86: Hyper-V invariant TSC control 2022-12-29 15:33:29 -05:00
i8254.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
i8254.h KVM: x86: PIT: Preserve state of speaker port data bit 2022-06-08 13:06:20 -04:00
i8259.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
ioapic.c KVM: x86/ioapic: Resample the pending state of an IRQ when unmasking 2023-03-27 10:13:28 -04:00
ioapic.h x86/kvm: remove unused ack_notifier callbacks 2021-11-18 07:05:57 -05:00
irq.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
irq.h x86/kvm: remove unused ack_notifier callbacks 2021-11-18 07:05:57 -05:00
irq_comm.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
kvm-asm-offsets.c KVM: SVM: move MSR_IA32_SPEC_CTRL save/restore to assembly 2022-11-09 12:25:53 -05:00
kvm_cache_regs.h KVM: VMX: Make CR0.WP a guest owned bit 2023-05-17 14:01:51 +02:00
kvm_emulate.h KVM: x86: Use emulator callbacks instead of duplicating "host flags" 2023-01-31 17:29:09 -08:00
kvm_onhyperv.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
kvm_onhyperv.h KVM: SVM: Flush Hyper-V TLB when required 2023-03-27 10:10:26 -04:00
lapic.c KVM: x86: Bail from kvm_recalculate_phys_map() if x2APIC ID is out-of-bounds 2023-06-09 10:48:24 +02:00
lapic.h KVM: x86: Split out logic to generate "readable" APIC regs mask to helper 2023-01-24 10:04:35 -08:00
mmu.h KVM: x86/mmu: Refresh CR0.WP prior to checking for emulated permission faults 2023-05-17 14:01:51 +02:00
mtrr.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
pmu.c KVM: x86: Make use of kvm_read_cr*_bits() when testing bits 2023-05-17 14:01:51 +02:00
pmu.h ARM: 2023-02-25 11:30:21 -08:00
reverse_cpuid.h ARM: 2023-02-25 11:30:21 -08:00
smm.c KVM: x86: Use emulator callbacks instead of duplicating "host flags" 2023-01-31 17:29:09 -08:00
smm.h KVM: x86: smm: preserve interrupt shadow in SMRAM 2022-11-09 12:31:26 -05:00
trace.h KVM: x86/xen: Add CPL to Xen hypercall tracepoint 2022-11-28 13:31:01 -05:00
tss.h
x86.c KVM: x86: Account fastpath-only VM-Exits in vCPU stats 2023-06-09 10:48:24 +02:00
x86.h KVM VMX changes for 6.3: 2023-02-15 12:23:19 -05:00
xen.c KVM: x86/xen: update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present 2023-01-24 10:05:20 -08:00
xen.h KVM: x86/xen: update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present 2023-01-24 10:05:20 -08:00