Vulnerability: The instruction decoder in arch/x86/kvm/emulate.c in the KVM subsystem in the Linux kernel before 3.18-rc2 lacks intended decoder-table flags for certain RIP-relative instructions, which allows guest OS users to cause a denial of service (NULL pointer dereference and host OS crash) via a crafted application.
Vulnerability ID: CVE-2014-8480
CWE: CWE-399
Severity score: 6.9
Project: https://github.com/torvalds/linux
Published: 2014-11-10
File: arch/x86/kvm/emulate.c
Commit message: KVM: x86: PREFETCH and HINT_NOP should have SrcMem flag

The decode phase of the x86 emulator assumes that every instruction with the
ModRM flag, and which can be used with RIP-relative addressing, has either
SrcMem or DstMem.  This is not the case for several instructions - prefetch,
hint-nop and clflush.

Adding SrcMem|NoAccess for prefetch and hint-nop and SrcMem for clflush.

This fixes CVE-2014-8480.

Fixes: 41061cdb98a0bec464278b4db8e894a3121671f5
Cc: stable@vger.kernel.org
Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Commit author: Nadav Amit

Vulnerable version (before fix):
 static const struct opcode group11[] = { };  static const struct gprefix pfx_0f_ae_7 = { 	I(0, em_clflush), N, N, N, };  static const struct group_dual group15 = { { static const struct opcode twobyte_table[256] = { 	N, I(ImplicitOps | EmulateOnUD, em_syscall), 	II(ImplicitOps | Priv, em_clts, clts), N, 	DI(ImplicitOps | Priv, invd), DI(ImplicitOps | Priv, wbinvd), N, N, 	N, D(ImplicitOps | ModRM), N, N, 	/* 0x10 - 0x1F */ 	N, N, N, N, N, N, N, N, 	D(ImplicitOps | ModRM), N, N, N, N, N, N, D(ImplicitOps | ModRM), 	/* 0x20 - 0x2F */ 	DIP(ModRM | DstMem | Priv | Op3264 | NoMod, cr_read, check_cr_read), 	DIP(ModRM | DstMem | Priv | Op3264 | NoMod, dr_read, check_dr_read),

Fixed version (after fix):
 static const struct opcode group11[] = { };  static const struct gprefix pfx_0f_ae_7 = { 	I(SrcMem | ByteOp, em_clflush), N, N, N, };  static const struct group_dual group15 = { { static const struct opcode twobyte_table[256] = { 	N, I(ImplicitOps | EmulateOnUD, em_syscall), 	II(ImplicitOps | Priv, em_clts, clts), N, 	DI(ImplicitOps | Priv, invd), DI(ImplicitOps | Priv, wbinvd), N, N, 	N, D(ImplicitOps | ModRM | SrcMem | NoAccess), N, N, 	/* 0x10 - 0x1F */ 	N, N, N, N, N, N, N, N, 	D(ImplicitOps | ModRM | SrcMem | NoAccess), 	N, N, N, N, N, N, D(ImplicitOps | ModRM | SrcMem | NoAccess), 	/* 0x20 - 0x2F */ 	DIP(ModRM | DstMem | Priv | Op3264 | NoMod, cr_read, check_cr_read), 	DIP(ModRM | DstMem | Priv | Op3264 | NoMod, dr_read, check_dr_read),

Patch:
patch: @@ -3807,7 +3807,7 @@ static const struct opcode group11[] = {
 };
 
 static const struct gprefix pfx_0f_ae_7 = {
-	I(0, em_clflush), N, N, N,
+	I(SrcMem | ByteOp, em_clflush), N, N, N,
 };
 
 static const struct group_dual group15 = { {
@@ -4024,10 +4024,11 @@ static const struct opcode twobyte_table[256] = {
 	N, I(ImplicitOps | EmulateOnUD, em_syscall),
 	II(ImplicitOps | Priv, em_clts, clts), N,
 	DI(ImplicitOps | Priv, invd), DI(ImplicitOps | Priv, wbinvd), N, N,
-	N, D(ImplicitOps | ModRM), N, N,
+	N, D(ImplicitOps | ModRM | SrcMem | NoAccess), N, N,
 	/* 0x10 - 0x1F */
 	N, N, N, N, N, N, N, N,
-	D(ImplicitOps | ModRM), N, N, N, N, N, N, D(ImplicitOps | ModRM),
+	D(ImplicitOps | ModRM | SrcMem | NoAccess),
+	N, N, N, N, N, N, D(ImplicitOps | ModRM | SrcMem | NoAccess),
 	/* 0x20 - 0x2F */
 	DIP(ModRM | DstMem | Priv | Op3264 | NoMod, cr_read, check_cr_read),
 	DIP(ModRM | DstMem | Priv | Op3264 | NoMod, dr_read, check_dr_read),
path: arch/x86/kvm/emulate.c