From: Marios Pomonis Date: Wed, 11 Dec 2019 20:47:44 +0000 (-0800) Subject: KVM: x86: Protect ioapic_read_indirect() from Spectre-v1/L1TF attacks X-Git-Tag: v5.15~4592^2~52 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c86405f606ca8508b8d9280680166ca26723695;p=platform%2Fkernel%2Flinux-starfive.git KVM: x86: Protect ioapic_read_indirect() from Spectre-v1/L1TF attacks This fixes a Spectre-v1/L1TF vulnerability in ioapic_read_indirect(). This function contains index computations based on the (attacker-controlled) IOREGSEL register. Fixes: a2c118bfab8b ("KVM: Fix bounds checking in ioapic indirect register reads (CVE-2013-1798)") Signed-off-by: Nick Finco Signed-off-by: Marios Pomonis Reviewed-by: Andrew Honig Cc: stable@vger.kernel.org Reviewed-by: Jim Mattson Signed-off-by: Paolo Bonzini --- diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c index 7312aab..c5776fe 100644 --- a/arch/x86/kvm/ioapic.c +++ b/arch/x86/kvm/ioapic.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -68,13 +69,14 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic, default: { u32 redir_index = (ioapic->ioregsel - 0x10) >> 1; - u64 redir_content; + u64 redir_content = ~0ULL; - if (redir_index < IOAPIC_NUM_PINS) - redir_content = - ioapic->redirtbl[redir_index].bits; - else - redir_content = ~0ULL; + if (redir_index < IOAPIC_NUM_PINS) { + u32 index = array_index_nospec( + redir_index, IOAPIC_NUM_PINS); + + redir_content = ioapic->redirtbl[index].bits; + } result = (ioapic->ioregsel & 0x1) ? (redir_content >> 32) & 0xffffffff :