From: Marios Pomonis <pomonis@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
rkrcmar@redhat.com,
Sean Christopherson <sean.j.christopherson@intel.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, Nick Finco <nifi@google.com>,
Andrew Honig <ahonig@google.com>,
Marios Pomonis <pomonis@google.com>,
stable@vger.kernel.org
Subject: [PATCH v2 10/13] KVM: x86: Protect memory accesses from Spectre-v1/L1TF attacks in x86.c
Date: Wed, 11 Dec 2019 12:47:50 -0800 [thread overview]
Message-ID: <20191211204753.242298-11-pomonis@google.com> (raw)
In-Reply-To: <20191211204753.242298-1-pomonis@google.com>
This fixes Spectre-v1/L1TF vulnerabilities in
vmx_read_guest_seg_selector(), vmx_read_guest_seg_base(),
vmx_read_guest_seg_limit() and vmx_read_guest_seg_ar().
These functions contain index computations based on the
(attacker-influenced) segment value.
Fixes: commit 2fb92db1ec08 ("KVM: VMX: Cache vmcs segment fields")
Signed-off-by: Nick Finco <nifi@google.com>
Signed-off-by: Marios Pomonis <pomonis@google.com>
Reviewed-by: Andrew Honig <ahonig@google.com>
Cc: stable@vger.kernel.org
---
arch/x86/kvm/vmx/vmx.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index d39475e2d44e..82b25f1812aa 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -753,7 +753,9 @@ static bool vmx_segment_cache_test_set(struct vcpu_vmx *vmx, unsigned seg,
static u16 vmx_read_guest_seg_selector(struct vcpu_vmx *vmx, unsigned seg)
{
- u16 *p = &vmx->segment_cache.seg[seg].selector;
+ size_t size = ARRAY_SIZE(vmx->segment_cache.seg);
+ size_t index = array_index_nospec(seg, size);
+ u16 *p = &vmx->segment_cache.seg[index].selector;
if (!vmx_segment_cache_test_set(vmx, seg, SEG_FIELD_SEL))
*p = vmcs_read16(kvm_vmx_segment_fields[seg].selector);
@@ -762,7 +764,9 @@ static u16 vmx_read_guest_seg_selector(struct vcpu_vmx *vmx, unsigned seg)
static ulong vmx_read_guest_seg_base(struct vcpu_vmx *vmx, unsigned seg)
{
- ulong *p = &vmx->segment_cache.seg[seg].base;
+ size_t size = ARRAY_SIZE(vmx->segment_cache.seg);
+ size_t index = array_index_nospec(seg, size);
+ ulong *p = &vmx->segment_cache.seg[index].base;
if (!vmx_segment_cache_test_set(vmx, seg, SEG_FIELD_BASE))
*p = vmcs_readl(kvm_vmx_segment_fields[seg].base);
@@ -771,7 +775,9 @@ static ulong vmx_read_guest_seg_base(struct vcpu_vmx *vmx, unsigned seg)
static u32 vmx_read_guest_seg_limit(struct vcpu_vmx *vmx, unsigned seg)
{
- u32 *p = &vmx->segment_cache.seg[seg].limit;
+ size_t size = ARRAY_SIZE(vmx->segment_cache.seg);
+ size_t index = array_index_nospec(seg, size);
+ u32 *p = &vmx->segment_cache.seg[index].limit;
if (!vmx_segment_cache_test_set(vmx, seg, SEG_FIELD_LIMIT))
*p = vmcs_read32(kvm_vmx_segment_fields[seg].limit);
@@ -780,7 +786,9 @@ static u32 vmx_read_guest_seg_limit(struct vcpu_vmx *vmx, unsigned seg)
static u32 vmx_read_guest_seg_ar(struct vcpu_vmx *vmx, unsigned seg)
{
- u32 *p = &vmx->segment_cache.seg[seg].ar;
+ size_t size = ARRAY_SIZE(vmx->segment_cache.seg);
+ size_t index = array_index_nospec(seg, size);
+ u32 *p = &vmx->segment_cache.seg[index].ar;
if (!vmx_segment_cache_test_set(vmx, seg, SEG_FIELD_AR))
*p = vmcs_read32(kvm_vmx_segment_fields[seg].ar_bytes);
--
2.24.0.525.g8f36a354ae-goog
next prev parent reply other threads:[~2019-12-11 20:49 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-11 20:47 [PATCH v2 00/13] KVM: x86: Extend Spectre-v1 mitigation Marios Pomonis
2019-12-11 20:47 ` [PATCH v2 01/13] KVM: x86: Protect x86_decode_insn from Spectre-v1/L1TF attacks Marios Pomonis
2020-01-06 20:16 ` Jim Mattson
2019-12-11 20:47 ` [PATCH v2 02/13] KVM: x86: Protect kvm_hv_msr_[get|set]_crash_data() " Marios Pomonis
2019-12-12 9:43 ` Vitaly Kuznetsov
2019-12-12 17:11 ` Marios Pomonis
2019-12-12 17:31 ` Christian Borntraeger
2019-12-12 17:44 ` Jim Mattson
2019-12-12 17:47 ` Christian Borntraeger
2020-01-06 20:16 ` Jim Mattson
2019-12-11 20:47 ` [PATCH v2 03/13] KVM: x86: Refactor picdev_write() to prevent " Marios Pomonis
2020-01-06 20:17 ` Jim Mattson
2019-12-11 20:47 ` [PATCH v2 04/13] KVM: x86: Protect ioapic_read_indirect() from " Marios Pomonis
2020-01-06 20:17 ` Jim Mattson
2019-12-11 20:47 ` [PATCH v2 05/13] KVM: x86: Protect ioapic_write_indirect() " Marios Pomonis
2020-01-06 20:17 ` Jim Mattson
2019-12-11 20:47 ` [PATCH v2 06/13] KVM: x86: Protect kvm_lapic_reg_write() " Marios Pomonis
2020-01-06 20:17 ` Jim Mattson
2019-12-11 20:47 ` [PATCH v2 07/13] KVM: x86: Protect MSR-based index computations in fixed_msr_to_seg_unit() " Marios Pomonis
2020-01-06 20:18 ` Jim Mattson
2019-12-11 20:47 ` [PATCH v2 08/13] KVM: x86: Protect MSR-based index computations in pmu.h " Marios Pomonis
2020-01-06 20:18 ` Jim Mattson
2019-12-11 20:47 ` [PATCH v2 09/13] KVM: x86: Protect MSR-based index computations from Spectre-v1/L1TF attacks in x86.c Marios Pomonis
2020-01-06 20:18 ` Jim Mattson
2019-12-11 20:47 ` Marios Pomonis [this message]
2020-01-06 20:19 ` [PATCH v2 10/13] KVM: x86: Protect memory accesses " Jim Mattson
2020-01-18 20:13 ` Paolo Bonzini
2019-12-11 20:47 ` [PATCH v2 11/13] KVM: x86: Protect exit_reason from being used in Spectre-v1/L1TF attacks Marios Pomonis
2019-12-11 20:47 ` [PATCH v2 12/13] KVM: x86: Protect DR-based index computations from " Marios Pomonis
2020-01-06 20:19 ` Jim Mattson
2019-12-11 20:47 ` [PATCH v2 13/13] KVM: x86: Protect pmu_intel.c " Marios Pomonis
2020-01-06 20:19 ` Jim Mattson
2020-01-18 20:18 ` [PATCH v2 00/13] KVM: x86: Extend Spectre-v1 mitigation Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191211204753.242298-11-pomonis@google.com \
--to=pomonis@google.com \
--cc=ahonig@google.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nifi@google.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox