Skip to content

Commit 9de6fe3

Browse files
calmisisuryasaimadhu
authored andcommitted
KVM: x86: Emulate split-lock access as a write in emulator
Emulate split-lock accesses as writes if split lock detection is on to avoid #AC during emulation, which will result in a panic(). This should never occur for a well-behaved guest, but a malicious guest can manipulate the TLB to trigger emulation of a locked instruction[1]. More discussion can be found at [2][3]. [1] https://lkml.kernel.org/r/[email protected] [2] https://lkml.kernel.org/r/[email protected] [3] https://lkml.kernel.org/r/[email protected] Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Xiaoyao Li <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Paolo Bonzini <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent d7e94db commit 9de6fe3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

arch/x86/kvm/x86.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5839,6 +5839,7 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
58395839
{
58405840
struct kvm_host_map map;
58415841
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
5842+
u64 page_line_mask;
58425843
gpa_t gpa;
58435844
char *kaddr;
58445845
bool exchanged;
@@ -5853,7 +5854,16 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
58535854
(gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
58545855
goto emul_write;
58555856

5856-
if (((gpa + bytes - 1) & PAGE_MASK) != (gpa & PAGE_MASK))
5857+
/*
5858+
* Emulate the atomic as a straight write to avoid #AC if SLD is
5859+
* enabled in the host and the access splits a cache line.
5860+
*/
5861+
if (boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT))
5862+
page_line_mask = ~(cache_line_size() - 1);
5863+
else
5864+
page_line_mask = PAGE_MASK;
5865+
5866+
if (((gpa + bytes - 1) & page_line_mask) != (gpa & page_line_mask))
58575867
goto emul_write;
58585868

58595869
if (kvm_vcpu_map(vcpu, gpa_to_gfn(gpa), &map))

0 commit comments

Comments
 (0)