]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
KVM: x86: Emulator does not calculate address correctly
authorNadav Amit <namit@cs.technion.ac.il>
Tue, 30 Sep 2014 17:49:19 +0000 (20:49 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 3 Nov 2014 11:07:24 +0000 (12:07 +0100)
In long-mode, when the address size is 4 bytes, the linear address is not
truncated as the emulator mistakenly does.  Instead, the offset within the
segment (the ea field) should be truncated according to the address size.

As Intel SDM says: "In 64-bit mode, the effective address components are added
and the effective address is truncated ... before adding the full 64-bit
segment base."

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/emulate.c

index 058aff86cfba4e170f1c7587c5c3d4d68c6e71e3..bdd4197e31faa8640c1ad16491085cec5e5adc98 100644 (file)
@@ -655,7 +655,8 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
        u16 sel;
        unsigned cpl;
 
-       la = seg_base(ctxt, addr.seg) + addr.ea;
+       la = seg_base(ctxt, addr.seg) +
+           (fetch || ctxt->ad_bytes == 8 ? addr.ea : (u32)addr.ea);
        *max_size = 0;
        switch (ctxt->mode) {
        case X86EMUL_MODE_PROT64:
@@ -717,7 +718,7 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
                }
                break;
        }
-       if (fetch ? ctxt->mode != X86EMUL_MODE_PROT64 : ctxt->ad_bytes != 8)
+       if (ctxt->mode != X86EMUL_MODE_PROT64)
                la &= (u32)-1;
        if (insn_aligned(ctxt, size) && ((la & (size - 1)) != 0))
                return emulate_gp(ctxt, 0);