Skip to content

Commit 64a3829

Browse files
anadavbonzini
authored andcommitted
KVM: x86: Emulate should check #UD before #GP
Intel SDM table 6-2 ("Priority Among Simultaneous Exceptions and Interrupts") shows that faults from decoding the next instruction got higher priority than general protection. Moving the protected-mode check before the CPL check to avoid wrong exception on vm86 mode. Signed-off-by: Nadav Amit <namit@cs.technion.ac.il> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent bc397a6 commit 64a3829

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

arch/x86/kvm/emulate.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4801,6 +4801,12 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
48014801
goto done;
48024802
}
48034803

4804+
/* Instruction can only be executed in protected mode */
4805+
if ((ctxt->d & Prot) && ctxt->mode < X86EMUL_MODE_PROT16) {
4806+
rc = emulate_ud(ctxt);
4807+
goto done;
4808+
}
4809+
48044810
/* Privileged instruction can be executed only in CPL=0 */
48054811
if ((ctxt->d & Priv) && ops->cpl(ctxt)) {
48064812
if (ctxt->d & PrivUD)
@@ -4810,12 +4816,6 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
48104816
goto done;
48114817
}
48124818

4813-
/* Instruction can only be executed in protected mode */
4814-
if ((ctxt->d & Prot) && ctxt->mode < X86EMUL_MODE_PROT16) {
4815-
rc = emulate_ud(ctxt);
4816-
goto done;
4817-
}
4818-
48194819
/* Do instruction specific permission checks */
48204820
if (ctxt->d & CheckPerm) {
48214821
rc = ctxt->check_perm(ctxt);

0 commit comments

Comments
 (0)