From cecd655e61a350dd1afd5b5cd837b5d534b447fe Mon Sep 17 00:00:00 2001 Message-Id: <cecd655e61a350dd1afd5b5cd837b5d534b447fe.1363792519.git.minovotn@redhat.com> In-Reply-To: <76f48f7faa6ca5742e3972153b490d00e74d5a93.1363792519.git.minovotn@redhat.com> References: <76f48f7faa6ca5742e3972153b490d00e74d5a93.1363792519.git.minovotn@redhat.com> From: Gleb Natapov <gleb@redhat.com> Date: Sun, 10 Mar 2013 14:46:30 +0200 Subject: [PATCH 3/4] KVM: Fix bounds checking in ioapic indirect register reads. (CVE-2013-1798) If the guest specifies a IOAPIC_REG_SELECT with an invalid value and follows that with a read of the IOAPIC_REG_WINDOW KVM does not properly validate that request. ioapic_read_indirect contains an ASSERT(redir_index < IOAPIC_NUM_PINS), but the ASSERT has no effect in non-debug builds. In recent kernels this allows a guest to cause a kernel oops by reading invalid memory. In older kernels (pre-3.3) this allows a guest to read from large ranges of host memory. Tested: tested against apic unit tests. Upstream status: embargoed BZ: 917029 Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Andrew Honig <ahonig@google.com> Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Michal Novotny <minovotn@redhat.com> --- virt/kvm/ioapic.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c index 1bb520d..3bf4928 100644 --- a/virt/kvm/ioapic.c +++ b/virt/kvm/ioapic.c @@ -70,9 +70,12 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic, u32 redir_index = (ioapic->ioregsel - 0x10) >> 1; u64 redir_content; - ASSERT(redir_index < IOAPIC_NUM_PINS); + if (redir_index < IOAPIC_NUM_PINS) + redir_content = + ioapic->redirtbl[redir_index].bits; + else + redir_content = ~0ULL; - redir_content = ioapic->redirtbl[redir_index].bits; result = (ioapic->ioregsel & 0x1) ? (redir_content >> 32) & 0xffffffff : redir_content & 0xffffffff; -- 1.7.11.7