All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Marios Pomonis <pomonis@google.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>,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 10/13] KVM: x86: Protect memory accesses from Spectre-v1/L1TF attacks in x86.c
Date: Sat, 18 Jan 2020 21:13:53 +0100	[thread overview]
Message-ID: <d8f47c12-3301-cb70-8d08-fe93450d19eb@redhat.com> (raw)
In-Reply-To: <20191211204753.242298-11-pomonis@google.com>

On 11/12/19 21:47, Marios Pomonis wrote:
> 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")

I think we could instead do

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 2d4faefe8dd4..20c0cbdff1be 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -5195,16 +5195,28 @@ int x86_decode_insn(struct x86_emulate_ctxt
*ctxt, void *insn, int insn_len)
 				ctxt->ad_bytes = def_ad_bytes ^ 6;
 			break;
 		case 0x26:	/* ES override */
+			has_seg_override = true;
+			ctxt->seg_override = VCPU_SREG_ES;
+			break;
 		case 0x2e:	/* CS override */
+			has_seg_override = true;
+			ctxt->seg_override = VCPU_SREG_CS;
+			break;
 		case 0x36:	/* SS override */
+			has_seg_override = true;
+			ctxt->seg_override = VCPU_SREG_SS;
+			break;
 		case 0x3e:	/* DS override */
 			has_seg_override = true;
-			ctxt->seg_override = (ctxt->b >> 3) & 3;
+			ctxt->seg_override = VCPU_SREG_DS;
 			break;
 		case 0x64:	/* FS override */
+			has_seg_override = true;
+			ctxt->seg_override = VCPU_SREG_FS;
+			break;
 		case 0x65:	/* GS override */
 			has_seg_override = true;
-			ctxt->seg_override = ctxt->b & 7;
+			ctxt->seg_override = VCPU_SREG_GS;
 			break;
 		case 0x40 ... 0x4f: /* REX */
 			if (mode != X86EMUL_MODE_PROT64)

so that the segment is never calculated.

Paolo


  parent reply	other threads:[~2020-01-18 20:13 UTC|newest]

Thread overview: 34+ 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
     [not found]   ` <20191225235523.470232075B@mail.kernel.org>
2019-12-30 23:14     ` 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 ` [PATCH v2 10/13] KVM: x86: Protect memory accesses " Marios Pomonis
2020-01-06 20:19   ` Jim Mattson
2020-01-18 20:13   ` Paolo Bonzini [this message]
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=d8f47c12-3301-cb70-8d08-fe93450d19eb@redhat.com \
    --to=pbonzini@redhat.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=pomonis@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.