]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
c11eed9cb69a97d766e8872f96c0b7594be227e9
[thirdparty/kernel/stable-queue.git] /
1 From 25a5edea71b7c154b6a0b8cec14c711cafa31d26 Mon Sep 17 00:00:00 2001
2 From: Marios Pomonis <pomonis@google.com>
3 Date: Wed, 11 Dec 2019 12:47:47 -0800
4 Subject: KVM: x86: Protect MSR-based index computations in fixed_msr_to_seg_unit() from Spectre-v1/L1TF attacks
5
6 From: Marios Pomonis <pomonis@google.com>
7
8 commit 25a5edea71b7c154b6a0b8cec14c711cafa31d26 upstream.
9
10 This fixes a Spectre-v1/L1TF vulnerability in fixed_msr_to_seg_unit().
11 This function contains index computations based on the
12 (attacker-controlled) MSR number.
13
14 Fixes: de9aef5e1ad6 ("KVM: MTRR: introduce fixed_mtrr_segment table")
15
16 Signed-off-by: Nick Finco <nifi@google.com>
17 Signed-off-by: Marios Pomonis <pomonis@google.com>
18 Reviewed-by: Andrew Honig <ahonig@google.com>
19 Cc: stable@vger.kernel.org
20 Reviewed-by: Jim Mattson <jmattson@google.com>
21 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23
24 ---
25 arch/x86/kvm/mtrr.c | 9 +++++++--
26 1 file changed, 7 insertions(+), 2 deletions(-)
27
28 --- a/arch/x86/kvm/mtrr.c
29 +++ b/arch/x86/kvm/mtrr.c
30 @@ -17,6 +17,7 @@
31 */
32
33 #include <linux/kvm_host.h>
34 +#include <linux/nospec.h>
35 #include <asm/mtrr.h>
36
37 #include "cpuid.h"
38 @@ -202,11 +203,15 @@ static bool fixed_msr_to_seg_unit(u32 ms
39 break;
40 case MSR_MTRRfix16K_80000 ... MSR_MTRRfix16K_A0000:
41 *seg = 1;
42 - *unit = msr - MSR_MTRRfix16K_80000;
43 + *unit = array_index_nospec(
44 + msr - MSR_MTRRfix16K_80000,
45 + MSR_MTRRfix16K_A0000 - MSR_MTRRfix16K_80000 + 1);
46 break;
47 case MSR_MTRRfix4K_C0000 ... MSR_MTRRfix4K_F8000:
48 *seg = 2;
49 - *unit = msr - MSR_MTRRfix4K_C0000;
50 + *unit = array_index_nospec(
51 + msr - MSR_MTRRfix4K_C0000,
52 + MSR_MTRRfix4K_F8000 - MSR_MTRRfix4K_C0000 + 1);
53 break;
54 default:
55 return false;