Browse code

Initial Spectre fix for 1.0

Change-Id: I2ed0ab875ce977b255fc9fc3940a201c8563ed14
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4622
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Srivatsa S. Bhat <srivatsab@vmware.com>

Bo Gan authored on 2018/01/09 04:36:17
Showing 21 changed files
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:       Kernel
3 3
 Name:          linux-esx
4 4
 Version:       4.4.110
5
-Release:       1%{?dist}
5
+Release:       2%{?dist}
6 6
 License:       GPLv2
7 7
 URL:           http://www.kernel.org/
8 8
 Group:         System Environment/Kernel
... ...
@@ -46,6 +46,27 @@ Patch28:       netfilter-nfnetlink_cthelper-Add-missing-permission-checks.patch
46 46
 # Fix CVE-2017-17450
47 47
 Patch29:       netfilter-xt_osf-Add-missing-permission-checks.patch
48 48
 Patch30:       revert-SMB-validate-negotiate-even-if-signing-off.patch
49
+# For Spectre
50
+Patch50: 0139-x86-cpu-AMD-Make-the-LFENCE-instruction-serialized.patch
51
+Patch51: 0140-x86-cpu-AMD-Remove-now-unused-definition-of-MFENCE_R.patch
52
+Patch52: 0141-locking-barriers-introduce-new-observable-speculatio.patch
53
+Patch53: 0142-bpf-prevent-speculative-execution-in-eBPF-interprete.patch
54
+#Patch54: 0143-x86-bpf-jit-prevent-speculative-execution-when-JIT-i.patch
55
+Patch55: 0144-uvcvideo-prevent-speculative-execution.patch
56
+Patch56: 0145-carl9170-prevent-speculative-execution.patch
57
+Patch57: 0146-p54-prevent-speculative-execution.patch
58
+Patch58: 0147-qla2xxx-prevent-speculative-execution.patch
59
+Patch59: 0148-cw1200-prevent-speculative-execution.patch
60
+Patch60: 0149-Thermal-int340x-prevent-speculative-execution.patch
61
+Patch61: 0150-ipv4-prevent-speculative-execution.patch
62
+Patch62: 0151-ipv6-prevent-speculative-execution.patch
63
+Patch63: 0152-fs-prevent-speculative-execution.patch
64
+Patch64: 0153-net-mpls-prevent-speculative-execution.patch
65
+Patch65: 0154-udf-prevent-speculative-execution.patch
66
+Patch66: 0155-userns-prevent-speculative-execution.patch
67
+Patch67: 0169-x86-syscall-Clear-unused-extra-registers-on-syscall-.patch
68
+Patch68: 0170-x86-syscall-Clear-unused-extra-registers-on-32-bit-c.patch
69
+
49 70
 BuildRequires: bc
50 71
 BuildRequires: kbd
51 72
 BuildRequires: kmod
... ...
@@ -113,6 +134,26 @@ The Linux package contains the Linux kernel doc files
113 113
 %patch29 -p1
114 114
 %patch30 -p1
115 115
 
116
+%patch50 -p1
117
+%patch51 -p1
118
+%patch52 -p1
119
+%patch53 -p1
120
+#%patch54 -p1
121
+%patch55 -p1
122
+%patch56 -p1
123
+%patch57 -p1
124
+%patch58 -p1
125
+%patch59 -p1
126
+%patch60 -p1
127
+%patch61 -p1
128
+%patch62 -p1
129
+%patch63 -p1
130
+%patch64 -p1
131
+%patch65 -p1
132
+%patch66 -p1
133
+%patch67 -p1
134
+%patch68 -p1
135
+
116 136
 %build
117 137
 # patch vmw_balloon driver
118 138
 sed -i 's/module_init/late_initcall/' drivers/misc/vmw_balloon.c
... ...
@@ -200,6 +241,10 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg
200 200
 /usr/src/linux-headers-%{uname_r}
201 201
 
202 202
 %changelog
203
+*   Mon Jan 08 2018 Bo Gan <ganb@vmware.com> 4.4.110-2
204
+-   Initial Spectre fix
205
+-   Add Observable speculation barrier
206
+-   Clear unused register upon syscall entry
203 207
 *   Fri Jan 05 2018 Anish Swaminathan <anishs@vmware.com> 4.4.110-1
204 208
 -   Version update to 4.4.110
205 209
 *   Thu Jan 04 2018 Srivatsa S. Bhat <srivatsa@csail.mit.edu> 4.4.109-3
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:        Kernel
3 3
 Name:           linux
4 4
 Version:    	4.4.110
5
-Release:        1%{?kat_build:.%kat_build}%{?dist}
5
+Release:        2%{?kat_build:.%kat_build}%{?dist}
6 6
 License:    	GPLv2
7 7
 URL:        	http://www.kernel.org/
8 8
 Group:        	System Environment/Kernel
... ...
@@ -45,6 +45,26 @@ Patch22:        netfilter-nfnetlink_cthelper-Add-missing-permission-checks.patch
45 45
 # Fix CVE-2017-17450
46 46
 Patch23:        netfilter-xt_osf-Add-missing-permission-checks.patch
47 47
 Patch24:        revert-SMB-validate-negotiate-even-if-signing-off.patch
48
+# For Spectre
49
+Patch50: 0139-x86-cpu-AMD-Make-the-LFENCE-instruction-serialized.patch
50
+Patch51: 0140-x86-cpu-AMD-Remove-now-unused-definition-of-MFENCE_R.patch
51
+Patch52: 0141-locking-barriers-introduce-new-observable-speculatio.patch
52
+Patch53: 0142-bpf-prevent-speculative-execution-in-eBPF-interprete.patch
53
+#Patch54: 0143-x86-bpf-jit-prevent-speculative-execution-when-JIT-i.patch
54
+Patch55: 0144-uvcvideo-prevent-speculative-execution.patch
55
+Patch56: 0145-carl9170-prevent-speculative-execution.patch
56
+Patch57: 0146-p54-prevent-speculative-execution.patch
57
+Patch58: 0147-qla2xxx-prevent-speculative-execution.patch
58
+Patch59: 0148-cw1200-prevent-speculative-execution.patch
59
+Patch60: 0149-Thermal-int340x-prevent-speculative-execution.patch
60
+Patch61: 0150-ipv4-prevent-speculative-execution.patch
61
+Patch62: 0151-ipv6-prevent-speculative-execution.patch
62
+Patch63: 0152-fs-prevent-speculative-execution.patch
63
+Patch64: 0153-net-mpls-prevent-speculative-execution.patch
64
+Patch65: 0154-udf-prevent-speculative-execution.patch
65
+Patch66: 0155-userns-prevent-speculative-execution.patch
66
+Patch67: 0169-x86-syscall-Clear-unused-extra-registers-on-syscall-.patch
67
+Patch68: 0170-x86-syscall-Clear-unused-extra-registers-on-32-bit-c.patch
48 68
 
49 69
 %if 0%{?kat_build:1}
50 70
 Patch1000:	%{kat_build}.patch
... ...
@@ -143,6 +163,26 @@ This package contains the 'perf' performance analysis tools for Linux kernel.
143 143
 %patch23 -p1
144 144
 %patch24 -p1
145 145
 
146
+%patch50 -p1
147
+%patch51 -p1
148
+%patch52 -p1
149
+%patch53 -p1
150
+#%patch54 -p1
151
+%patch55 -p1
152
+%patch56 -p1
153
+%patch57 -p1
154
+%patch58 -p1
155
+%patch59 -p1
156
+%patch60 -p1
157
+%patch61 -p1
158
+%patch62 -p1
159
+%patch63 -p1
160
+%patch64 -p1
161
+%patch65 -p1
162
+%patch66 -p1
163
+%patch67 -p1
164
+%patch68 -p1
165
+
146 166
 %if 0%{?kat_build:1}
147 167
 %patch1000 -p1
148 168
 %endif
... ...
@@ -298,6 +338,10 @@ ln -sf %{name}-%{uname_r}.cfg /boot/photon.cfg
298 298
 /usr/share/perf-core
299 299
 
300 300
 %changelog
301
+*   Mon Jan 08 2018 Bo Gan <ganb@vmware.com> 4.4.110-2
302
+-   Initial Spectre fix
303
+-   Add Observable speculation barrier
304
+-   Clear unused register upon syscall entry
301 305
 *   Fri Jan 05 2018 Anish Swaminathan <anishs@vmware.com> 4.4.110-1
302 306
 -   Version update to 4.4.110
303 307
 *   Thu Jan 04 2018 Srivatsa S. Bhat <srivatsa@csail.mit.edu> 4.4.109-3
304 308
new file mode 100644
... ...
@@ -0,0 +1,58 @@
0
+From 9883f4d618615acaa9541aaae38e8434d699593f Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Thu, 14 Dec 2017 09:57:58 +0200
3
+Subject: [PATCH 139/194] x86/cpu/AMD: Make the LFENCE instruction serialized
4
+
5
+In order to reduce the impact of using MFENCE, make the execution of the
6
+LFENCE instruction serialized.  This is done by setting bit 1 of MSR
7
+0xc0011029 (DE_CFG).
8
+
9
+Some families that support LFENCE do not have this MSR.  For these
10
+families, the LFENCE instruction is already serialized.
11
+
12
+Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
13
+---
14
+ arch/x86/include/asm/msr-index.h |  2 ++
15
+ arch/x86/kernel/cpu/amd.c        | 13 +++++++++++--
16
+ 2 files changed, 13 insertions(+), 2 deletions(-)
17
+
18
+diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
19
+index ab02261..1e7d710 100644
20
+--- a/arch/x86/include/asm/msr-index.h
21
+@@ -352,6 +352,8 @@
22
+ #define FAM10H_MMIO_CONF_BASE_MASK	0xfffffffULL
23
+ #define FAM10H_MMIO_CONF_BASE_SHIFT	20
24
+ #define MSR_FAM10H_NODE_ID		0xc001100c
25
++#define MSR_F10H_DECFG			0xc0011029
26
++#define MSR_F10H_DECFG_LFENCE_SERIALIZE_BIT	1
27
+ 
28
+ /* K8 MSRs */
29
+ #define MSR_K8_TOP_MEM1			0xc001001a
30
+diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
31
+index e2defc7..5751810 100644
32
+--- a/arch/x86/kernel/cpu/amd.c
33
+@@ -746,8 +746,17 @@ static void init_amd(struct cpuinfo_x86 *c)
34
+ 		set_cpu_cap(c, X86_FEATURE_K8);
35
+ 
36
+ 	if (cpu_has_xmm2) {
37
+-		/* MFENCE stops RDTSC speculation */
38
+-		set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
39
++		/*
40
++		 * Use LFENCE for execution serialization. On some families
41
++		 * LFENCE is already serialized and the MSR is not available,
42
++		 * but msr_set_bit() uses rdmsrl_safe() and wrmsrl_safe().
43
++		 */
44
++		if (c->x86 > 0xf)
45
++			msr_set_bit(MSR_F10H_DECFG,
46
++				    MSR_F10H_DECFG_LFENCE_SERIALIZE_BIT);
47
++
48
++		/* LFENCE with MSR_F10H_DECFG[1]=1 stops RDTSC speculation */
49
++		set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
50
+ 	}
51
+ 
52
+ 	/*
53
+-- 
54
+2.9.5
55
+
0 56
new file mode 100644
... ...
@@ -0,0 +1,45 @@
0
+From 3325f36c2f6f6335cb3161977ba07ee58a03577f Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Thu, 14 Dec 2017 10:09:03 +0200
3
+Subject: [PATCH 140/194] x86/cpu/AMD: Remove now unused definition of
4
+ MFENCE_RDTSC feature
5
+
6
+With the switch to using LFENCE_RDTSC on AMD platforms there is no longer
7
+a need for the MFENCE_RDTSC feature.  Remove its usage and definition.
8
+
9
+Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
10
+---
11
+ arch/x86/include/asm/cpufeatures.h | 2 +-
12
+ arch/x86/include/asm/msr.h         | 3 +--
13
+ 2 files changed, 2 insertions(+), 3 deletions(-)
14
+
15
+diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16
+index f8c2bd4..86c68cb 100644
17
+--- a/arch/x86/include/asm/cpufeature.h
18
+@@ -96,7 +96,7 @@
19
+ #define X86_FEATURE_SYSCALL32	( 3*32+14) /* "" syscall in ia32 userspace */
20
+ #define X86_FEATURE_SYSENTER32	( 3*32+15) /* "" sysenter in ia32 userspace */
21
+ #define X86_FEATURE_REP_GOOD	( 3*32+16) /* rep microcode works well */
22
+-#define X86_FEATURE_MFENCE_RDTSC ( 3*32+17) /* "" Mfence synchronizes RDTSC */
23
++
24
+ #define X86_FEATURE_LFENCE_RDTSC ( 3*32+18) /* "" Lfence synchronizes RDTSC */
25
+ /* free, was #define X86_FEATURE_11AP	( 3*32+19) * "" Bad local APIC aka 11AP */
26
+ #define X86_FEATURE_NOPL	( 3*32+20) /* The NOPL (0F 1F) instructions */
27
+diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
28
+index 07962f5..8d8d7ae2 100644
29
+--- a/arch/x86/include/asm/msr.h
30
+@@ -214,8 +214,7 @@ static __always_inline unsigned long long rdtsc_ordered(void)
31
+ 	 * that some other imaginary CPU is updating continuously with a
32
+ 	 * time stamp.
33
+ 	 */
34
+-	alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC,
35
+-			  "lfence", X86_FEATURE_LFENCE_RDTSC);
36
++	alternative("", "lfence", X86_FEATURE_LFENCE_RDTSC);
37
+ 	return rdtsc();
38
+ }
39
+ 
40
+-- 
41
+2.9.5
42
+
0 43
new file mode 100644
... ...
@@ -0,0 +1,62 @@
0
+From 11ea2f142cc668db2383015c722bcd71b6b10ba7 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Mon, 7 Aug 2017 11:03:42 +0300
3
+Subject: [PATCH 141/194] locking/barriers: introduce new observable
4
+ speculation barrier
5
+
6
+The new observable speculation barrier, osb(), ensures
7
+that any user observable speculation doesn't cross the boundary.
8
+
9
+Any user observable speculative activity on this CPU
10
+thread before this point either completes, reaches a
11
+state it can no longer cause an observable activity, or
12
+is aborted before instructions after the barrier execute.
13
+
14
+In x86 case, osb() resolves in lfence if X86_FEATURE_LFENCE_RDTSC
15
+is present. Other architectures can define their variants.
16
+
17
+Suggested-by: Arjan van de Ven <arjan@linux.intel.com>
18
+Suggested-by: Alan Cox <alan.cox@intel.com>
19
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
20
+---
21
+ arch/x86/include/asm/barrier.h |  2 ++
22
+ include/asm-generic/barrier.h  | 11 +++++++++++
23
+ 2 files changed, 13 insertions(+)
24
+
25
+diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
26
+index 01727db..a0f695a 100644
27
+--- a/arch/x86/include/asm/barrier.h
28
+@@ -77,6 +77,8 @@ do {									\
29
+ 
30
+ #endif
31
+ 
32
++#define osb() alternative("", "lfence", X86_FEATURE_LFENCE_RDTSC)
33
++
34
+ /* Atomic operations are already serializing on x86 */
35
+ #define smp_mb__before_atomic()	barrier()
36
+ #define smp_mb__after_atomic()	barrier()
37
+diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
38
+index b42afad..7a9184d 100644
39
+--- a/include/asm-generic/barrier.h
40
+@@ -119,5 +119,16 @@ do {									\
41
+ 	___p1;								\
42
+ })
43
+ 
44
++/* Observable speculation barrier: ensures that any user
45
++ * observable speculation doesn't cross the boundary.
46
++ * Any user observable speculative activity on this CPU
47
++ * thread before this point either completes, reaches a
48
++ * state it can no longer cause observable activity, or
49
++ * is aborted before instructions after the barrier execute.
50
++ */
51
++#ifndef osb
52
++#define osb()	do { } while (0)
53
++#endif
54
++
55
+ #endif /* !__ASSEMBLY__ */
56
+ #endif /* __ASM_GENERIC_BARRIER_H */
57
+-- 
58
+2.9.5
59
+
0 60
new file mode 100644
... ...
@@ -0,0 +1,48 @@
0
+From acc08dc457b9c6b30c21f589ef4f2f5235d1e654 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Mon, 7 Aug 2017 11:10:28 +0300
3
+Subject: [PATCH 142/194] bpf: prevent speculative execution in eBPF
4
+ interpreter
5
+
6
+This adds an observable speculation barrier before LD_IMM_DW and
7
+LDX_MEM_B/H/W/DW eBPF instructions during eBPF program
8
+execution in order to prevent speculative execution on out
9
+of bound BFP_MAP array indexes. This way an arbitary kernel
10
+memory is not exposed through side channel attacks.
11
+
12
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
13
+---
14
+ kernel/bpf/core.c | 3 +++
15
+ 1 file changed, 3 insertions(+)
16
+
17
+diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
18
+index 334b1bd..ae3d943 100644
19
+--- a/kernel/bpf/core.c
20
+@@ -29,6 +29,7 @@
21
+ #include <linux/bpf.h>
22
+ 
23
+ #include <asm/unaligned.h>
24
++#include <asm/barrier.h>
25
+ 
26
+ /* Registers */
27
+ #define BPF_R0	regs[BPF_REG_0]
28
+@@ -356,6 +357,7 @@ select_insn:
29
+ 		DST = IMM;
30
+ 		CONT;
31
+ 	LD_IMM_DW:
32
++		osb();
33
+ 		DST = (u64) (u32) insn[0].imm | ((u64) (u32) insn[1].imm) << 32;
34
+ 		insn++;
35
+ 		CONT;
36
+@@ -570,6 +572,7 @@ out:
37
+ 		*(SIZE *)(unsigned long) (DST + insn->off) = IMM;	\
38
+ 		CONT;							\
39
+ 	LDX_MEM_##SIZEOP:						\
40
++		osb();							\
41
+ 		DST = *(SIZE *)(unsigned long) (SRC + insn->off);	\
42
+ 		CONT;
43
+ 
44
+-- 
45
+2.9.5
46
+
0 47
new file mode 100644
... ...
@@ -0,0 +1,111 @@
0
+From e3b71cad927d33b8e20c66bf07956f935c9c6eef Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Tue, 8 Aug 2017 12:06:58 +0300
3
+Subject: [PATCH 143/194] x86, bpf, jit: prevent speculative execution when JIT
4
+ is enabled
5
+
6
+When constant blinding is enabled (bpf_jit_harden = 1), this adds
7
+an observable speculation barrier before emitting x86 jitted code
8
+for the BPF_ALU(64)_OR_X and BPF_ALU_LHS_X
9
+(for BPF_REG_AX register) eBPF instructions. This is needed in order
10
+to prevent speculative execution on out of bounds BPF_MAP array
11
+indexes when JIT is enabled. This way an arbitary kernel memory is
12
+not exposed through side-channel attacks.
13
+
14
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
15
+---
16
+ arch/x86/net/bpf_jit_comp.c | 28 +++++++++++++++++++++++++++-
17
+ include/linux/filter.h      |  9 +++++++++
18
+ 2 files changed, 36 insertions(+), 1 deletion(-)
19
+
20
+diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
21
+index 0554e8a..f01480a 100644
22
+--- a/arch/x86/net/bpf_jit_comp.c
23
+@@ -16,6 +16,7 @@
24
+ #include <linux/bpf.h>
25
+ 
26
+ int bpf_jit_enable __read_mostly;
27
++u8 bpf_jit_fence = 0;
28
+ 
29
+ /*
30
+  * assembly code in arch/x86/net/bpf_jit.S
31
+@@ -109,6 +110,18 @@ static void bpf_flush_icache(void *start, void *end)
32
+ 	set_fs(old_fs);
33
+ }
34
+ 
35
++static void emit_memory_barrier(u8 **pprog)
36
++{
37
++	u8 *prog = *pprog;
38
++	int cnt = 0;
39
++
40
++	if (bpf_jit_fence)
41
++			EMIT3(0x0f, 0xae, 0xe8);
42
++
43
++	*pprog = prog;
44
++	return;
45
++}
46
++
47
+ #define CHOOSE_LOAD_FUNC(K, func) \
48
+ 	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
49
+ 
50
+@@ -400,7 +413,7 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
51
+ 			case BPF_ADD: b2 = 0x01; break;
52
+ 			case BPF_SUB: b2 = 0x29; break;
53
+ 			case BPF_AND: b2 = 0x21; break;
54
+-			case BPF_OR: b2 = 0x09; break;
55
++			case BPF_OR: b2 = 0x09; emit_memory_barrier(&prog); break;
56
+ 			case BPF_XOR: b2 = 0x31; break;
57
+ 			}
58
+ 			if (BPF_CLASS(insn->code) == BPF_ALU64)
59
+@@ -647,6 +660,16 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
60
+ 		case BPF_ALU64 | BPF_RSH | BPF_X:
61
+ 		case BPF_ALU64 | BPF_ARSH | BPF_X:
62
+ 
63
++			/* If blinding is enabled, each
64
++			 * BPF_LD | BPF_IMM | BPF_DW instruction
65
++			 * is converted to 4 eBPF instructions with
66
++			 * BPF_ALU64_IMM(BPF_LSH, BPF_REG_AX, 32)
67
++			 * always present(number 3). Detect such cases
68
++			 * and insert memory barriers. */
69
++			if ((BPF_CLASS(insn->code) == BPF_ALU64)
70
++				&& (BPF_OP(insn->code) == BPF_LSH)
71
++				&& (src_reg == BPF_REG_AX))
72
++				emit_memory_barrier(&prog);
73
+ 			/* check for bad case when dst_reg == rcx */
74
+ 			if (dst_reg == BPF_REG_4) {
75
+ 				/* mov r11, dst_reg */
76
+@@ -1124,6 +1147,9 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
77
+ 	if (!bpf_jit_enable)
78
+ 		return orig_prog;
79
+ 
80
++	if (bpf_jit_fence_present() && bpf_jit_blinding_enabled())
81
++		bpf_jit_fence = 1;
82
++
83
+ 	tmp = bpf_jit_blind_constants(prog);
84
+ 	/* If blinding was requested and we failed during blinding,
85
+ 	 * we must fall back to the interpreter.
86
+diff --git a/include/linux/filter.h b/include/linux/filter.h
87
+index 48ec57e..cba50a5 100644
88
+--- a/include/linux/filter.h
89
+@@ -651,6 +651,16 @@ static inline bool bpf_jit_blinding_enabled(void)
90
+ 
91
+ 	return true;
92
+ }
93
++
94
++static inline bool bpf_jit_fence_present(void)
95
++{
96
++	/* Check if lfence is present on CPU
97
++	 */
98
++	if (boot_cpu_has(X86_FEATURE_LFENCE_RDTSC))
99
++		return true;
100
++	return false;
101
++}
102
++
103
+ #else
104
+ static inline void bpf_jit_compile(struct bpf_prog *fp)
105
+ {
106
+-- 
107
+2.9.5
108
+
0 109
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+From 7dd7ad0b13eb99b650d92ea3b1a2ca170a567216 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 30 Aug 2017 13:41:27 +0300
3
+Subject: [PATCH 144/194] uvcvideo: prevent speculative execution
4
+
5
+Since the index value in function uvc_ioctl_enum_input()
6
+seems to be controllable by userspace and later on
7
+conditionally (upon bound check) used to resolve
8
+selector->baSourceID, insert an observable speculation
9
+barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ drivers/media/usb/uvc/uvc_v4l2.c | 1 +
16
+ 1 file changed, 1 insertion(+)
17
+
18
+diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
19
+index 3e7e283..65175bb 100644
20
+--- a/drivers/media/usb/uvc/uvc_v4l2.c
21
+@@ -821,6 +821,7 @@ static int uvc_ioctl_enum_input(struct file *file, void *fh,
22
+ 		}
23
+ 		pin = iterm->id;
24
+ 	} else if (index < selector->bNrInPins) {
25
++		osb();
26
+ 		pin = selector->baSourceID[index];
27
+ 		list_for_each_entry(iterm, &chain->entities, chain) {
28
+ 			if (!UVC_ENTITY_IS_ITERM(iterm))
29
+-- 
30
+2.9.5
31
+
0 32
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+From 9c2549c6adcafe2c2f35d44dc87ec23cc52a68b2 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 30 Aug 2017 13:43:39 +0300
3
+Subject: [PATCH 145/194] carl9170: prevent speculative execution
4
+
5
+Since the queue value in function carl9170_op_conf_tx()
6
+seems to be controllable by userspace and later on
7
+conditionally (upon bound check) used to resolve
8
+ar9170_qmap and following ar->edcf, insert an observable
9
+speculation barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ drivers/net/wireless/ath/carl9170/main.c | 1 +
16
+ 1 file changed, 1 insertion(+)
17
+
18
+diff --git a/drivers/net/wireless/ath/carl9170/main.c b/drivers/net/wireless/ath/carl9170/main.c
19
+index 988c885..cf267b7 100644
20
+--- a/drivers/net/wireless/ath/carl9170/main.c
21
+@@ -1388,6 +1388,7 @@ static int carl9170_op_conf_tx(struct ieee80211_hw *hw,
22
+ 
23
+ 	mutex_lock(&ar->mutex);
24
+ 	if (queue < ar->hw->queues) {
25
++		osb();
26
+ 		memcpy(&ar->edcf[ar9170_qmap[queue]], param, sizeof(*param));
27
+ 		ret = carl9170_set_qos(ar);
28
+ 	} else {
29
+-- 
30
+2.9.5
31
+
0 32
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+From 07f7bcf24d303ec6d91d7da809f3b6e6760f8301 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 30 Aug 2017 13:44:38 +0300
3
+Subject: [PATCH 146/194] p54: prevent speculative execution
4
+
5
+Since the queue value in function p54_conf_tx()
6
+seems to be controllable by userspace and later on
7
+conditionally (upon bound check) used to resolve
8
+priv->qos_params, insert an observable speculation
9
+barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ drivers/net/wireless/p54/main.c | 1 +
16
+ 1 file changed, 1 insertion(+)
17
+
18
+diff --git a/drivers/net/wireless/p54/main.c b/drivers/net/wireless/p54/main.c
19
+index d5a3bf9..3d20b47 100644
20
+--- a/drivers/net/wireless/p54/main.c
21
+@@ -415,6 +415,7 @@ static int p54_conf_tx(struct ieee80211_hw *dev,
22
+ 
23
+ 	mutex_lock(&priv->conf_mutex);
24
+ 	if (queue < dev->queues) {
25
++		osb();
26
+ 		P54_SET_QUEUE(priv->qos_params[queue], params->aifs,
27
+ 			params->cw_min, params->cw_max, params->txop);
28
+ 		ret = p54_set_edcf(priv);
29
+-- 
30
+2.9.5
31
+
0 32
new file mode 100644
... ...
@@ -0,0 +1,55 @@
0
+From f7de96128d46f9d9ecad5c1ded3133e2da25f39c Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 30 Aug 2017 13:45:35 +0300
3
+Subject: [PATCH 147/194] qla2xxx: prevent speculative execution
4
+
5
+Since the handle value in functions qlafx00_status_entry()
6
+and qlafx00_multistatus_entry() seems to be controllable
7
+by userspace and later on conditionally (upon bound check)
8
+used to resolve req->outstanding_cmds, insert an observable
9
+speculation barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid kernel
11
+memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ drivers/scsi/qla2xxx/qla_mr.c | 12 ++++++++----
16
+ 1 file changed, 8 insertions(+), 4 deletions(-)
17
+
18
+diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c
19
+index e23a3d4..9090283 100644
20
+--- a/drivers/scsi/qla2xxx/qla_mr.c
21
+@@ -2305,10 +2305,12 @@ qlafx00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
22
+ 	req = ha->req_q_map[que];
23
+ 
24
+ 	/* Validate handle. */
25
+-	if (handle < req->num_outstanding_cmds)
26
++	if (handle < req->num_outstanding_cmds) {
27
++		osb();
28
+ 		sp = req->outstanding_cmds[handle];
29
+-	else
30
++	} else {
31
+ 		sp = NULL;
32
++	}
33
+ 
34
+ 	if (sp == NULL) {
35
+ 		ql_dbg(ql_dbg_io, vha, 0x3034,
36
+@@ -2656,10 +2658,12 @@ qlafx00_multistatus_entry(struct scsi_qla_host *vha,
37
+ 		req = ha->req_q_map[que];
38
+ 
39
+ 		/* Validate handle. */
40
+-		if (handle < req->num_outstanding_cmds)
41
++		if (handle < req->num_outstanding_cmds) {
42
++			osb();
43
+ 			sp = req->outstanding_cmds[handle];
44
+-		else
45
++		} else {
46
+ 			sp = NULL;
47
++		}
48
+ 
49
+ 		if (sp == NULL) {
50
+ 			ql_dbg(ql_dbg_io, vha, 0x3044,
51
+-- 
52
+2.9.5
53
+
0 54
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+From 9a0dc9abad09792c93d099d5e92af5788c224791 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 30 Aug 2017 13:46:21 +0300
3
+Subject: [PATCH 148/194] cw1200: prevent speculative execution
4
+
5
+Since the queue value in function cw1200_conf_tx()
6
+seems to be controllable by userspace and later on
7
+conditionally (upon bound check) used in
8
+WSM_TX_QUEUE_SET, insert an observable speculation
9
+barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ drivers/net/wireless/cw1200/sta.c | 1 +
16
+ 1 file changed, 1 insertion(+)
17
+
18
+diff --git a/drivers/net/wireless/cw1200/sta.c b/drivers/net/wireless/cw1200/sta.c
19
+index a522248..754fc43 100644
20
+--- a/drivers/net/wireless/cw1200/sta.c
21
+@@ -619,6 +619,7 @@ int cw1200_conf_tx(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
22
+ 	mutex_lock(&priv->conf_mutex);
23
+ 
24
+ 	if (queue < dev->queues) {
25
++		osb();
26
+ 		old_uapsd_flags = le16_to_cpu(priv->uapsd_info.uapsd_flags);
27
+ 
28
+ 		WSM_TX_QUEUE_SET(&priv->tx_queue_params, queue, 0, 0, 0);
29
+-- 
30
+2.9.5
31
+
0 32
new file mode 100644
... ...
@@ -0,0 +1,47 @@
0
+From d9542e2d9b4b1e4649f0c1ea13a1b5dcfc1e2674 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 30 Aug 2017 13:47:12 +0300
3
+Subject: [PATCH 149/194] Thermal/int340x: prevent speculative execution
4
+
5
+Since the trip value in function int340x_thermal_get_trip_temp()
6
+seems to be controllable by userspace and later on
7
+conditionally (upon bound check) used to resolve
8
+d->aux_trips, insert an observable speculation
9
+barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ drivers/thermal/int340x_thermal/int340x_thermal_zone.c | 11 ++++++-----
16
+ 1 file changed, 6 insertions(+), 5 deletions(-)
17
+
18
+diff --git a/drivers/thermal/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/int340x_thermal/int340x_thermal_zone.c
19
+index 145a5c53..d732b34 100644
20
+--- a/drivers/thermal/int340x_thermal/int340x_thermal_zone.c
21
+@@ -57,15 +57,16 @@ static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,
22
+ 	if (d->override_ops && d->override_ops->get_trip_temp)
23
+ 		return d->override_ops->get_trip_temp(zone, trip, temp);
24
+ 
25
+-	if (trip < d->aux_trip_nr)
26
++	if (trip < d->aux_trip_nr) {
27
++		osb();
28
+ 		*temp = d->aux_trips[trip];
29
+-	else if (trip == d->crt_trip_id)
30
++	} else if (trip == d->crt_trip_id) {
31
+ 		*temp = d->crt_temp;
32
+-	else if (trip == d->psv_trip_id)
33
++	} else if (trip == d->psv_trip_id) {
34
+ 		*temp = d->psv_temp;
35
+-	else if (trip == d->hot_trip_id)
36
++	} else if (trip == d->hot_trip_id) {
37
+ 		*temp = d->hot_temp;
38
+-	else {
39
++	} else {
40
+ 		for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) {
41
+ 			if (d->act_trips[i].valid &&
42
+ 			    d->act_trips[i].id == trip) {
43
+-- 
44
+2.9.5
45
+
0 46
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+From 9515f43ddd006464308b2796b63b7d6446d922b8 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 13 Dec 2017 10:16:07 +0200
3
+Subject: [PATCH 150/194] ipv4: prevent speculative execution
4
+
5
+Since the offset value in function raw_getfrag()
6
+seems to be controllable by userspace and later on
7
+conditionally (upon bound check) used in the following
8
+memcpy, insert an observable speculation
9
+barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ net/ipv4/raw.c | 1 +
16
+ 1 file changed, 1 insertion(+)
17
+
18
+diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
19
+index 33b70bf..c9d33f1 100644
20
+--- a/net/ipv4/raw.c
21
+@@ -476,6 +476,7 @@ static int raw_getfrag(void *from, char *to, int offset, int len, int odd,
22
+ 	if (offset < rfv->hlen) {
23
+ 		int copy = min(rfv->hlen - offset, len);
24
+ 
25
++		osb();
26
+ 		if (skb->ip_summed == CHECKSUM_PARTIAL)
27
+ 			memcpy(to, rfv->hdr.c + offset, copy);
28
+ 		else
29
+-- 
30
+2.9.5
31
+
0 32
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+From 1ce83a2cfe57cec87a22e69b726e9547b4d830f8 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 30 Aug 2017 13:48:35 +0300
3
+Subject: [PATCH 151/194] ipv6: prevent speculative execution
4
+
5
+Since the offset value in function raw6_getfrag()
6
+seems to be controllable by userspace and later on
7
+conditionally (upon bound check) used in the
8
+following memcpy, insert an observable speculation
9
+barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ net/ipv6/raw.c | 1 +
16
+ 1 file changed, 1 insertion(+)
17
+
18
+diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
19
+index e4462b0..8794d92 100644
20
+--- a/net/ipv6/raw.c
21
+@@ -729,6 +729,7 @@ static int raw6_getfrag(void *from, char *to, int offset, int len, int odd,
22
+ 	if (offset < rfv->hlen) {
23
+ 		int copy = min(rfv->hlen - offset, len);
24
+ 
25
++		osb();
26
+ 		if (skb->ip_summed == CHECKSUM_PARTIAL)
27
+ 			memcpy(to, rfv->c + offset, copy);
28
+ 		else
29
+-- 
30
+2.9.5
31
+
0 32
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+From d7ca466502c0427749f64a6bdb47d96f848bf72d Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 30 Aug 2017 13:52:22 +0300
3
+Subject: [PATCH 152/194] fs: prevent speculative execution
4
+
5
+Since the fd value in function __fcheck_files()
6
+seems to be controllable by userspace and later on
7
+conditionally (upon bound check) used to resolve
8
+fdt->fd, insert an observable speculation
9
+barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ include/linux/fdtable.h | 4 +++-
16
+ 1 file changed, 3 insertions(+), 1 deletion(-)
17
+
18
+diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
19
+index 1c65817..dbc1200 100644
20
+--- a/include/linux/fdtable.h
21
+@@ -82,8 +82,10 @@ static inline struct file *__fcheck_files(struct files_struct *files, unsigned i
22
+ {
23
+ 	struct fdtable *fdt = rcu_dereference_raw(files->fdt);
24
+ 
25
+-	if (fd < fdt->max_fds)
26
++	if (fd < fdt->max_fds) {
27
++		osb();
28
+ 		return rcu_dereference_raw(fdt->fd[fd]);
29
++	}
30
+ 	return NULL;
31
+ }
32
+ 
33
+-- 
34
+2.9.5
35
+
0 36
new file mode 100644
... ...
@@ -0,0 +1,34 @@
0
+From 3e9a34c67e5376bedd9e79e6a7e16b01a01c8215 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 30 Aug 2017 13:55:54 +0300
3
+Subject: [PATCH 153/194] net: mpls: prevent speculative execution
4
+
5
+Since the index value in function mpls_route_input_rcu()
6
+seems to be controllable by userspace and later on
7
+conditionally (upon bound check) used to resolve
8
+platform_label, insert an observable speculation
9
+barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ net/mpls/af_mpls.c | 2 ++
16
+ 1 file changed, 2 insertions(+)
17
+
18
+diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
19
+index c5b9ce4..3bdf8d8 100644
20
+--- a/net/mpls/af_mpls.c
21
+@@ -50,6 +50,8 @@ static struct mpls_route *mpls_route_input_rcu(struct net *net, unsigned index)
22
+ 	if (index < net->mpls.platform_labels) {
23
+ 		struct mpls_route __rcu **platform_label =
24
+ 			rcu_dereference(net->mpls.platform_label);
25
++
26
++		osb();
27
+ 		rt = rcu_dereference(platform_label[index]);
28
+ 	}
29
+ 	return rt;
30
+-- 
31
+2.9.5
32
+
0 33
new file mode 100644
... ...
@@ -0,0 +1,52 @@
0
+From bbb72371d2212fe0526f1ae679d5d55fe51bd909 Mon Sep 17 00:00:00 2001
1
+From: Elena Reshetova <elena.reshetova@intel.com>
2
+Date: Wed, 13 Dec 2017 10:15:30 +0200
3
+Subject: [PATCH 154/194] udf: prevent speculative execution
4
+
5
+Since the eahd->appAttrLocation value in function
6
+udf_add_extendedattr() seems to be controllable by
7
+userspace and later on conditionally (upon bound check)
8
+used in following memmove, insert an observable speculation
9
+barrier before its usage. This should prevent
10
+observable speculation on that branch and avoid
11
+kernel memory leak.
12
+
13
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
14
+---
15
+ fs/udf/misc.c | 6 ++++++
16
+ 1 file changed, 6 insertions(+)
17
+
18
+diff --git a/fs/udf/misc.c b/fs/udf/misc.c
19
+index 3949c4b..c826ccc 100644
20
+--- a/fs/udf/misc.c
21
+@@ -104,6 +104,8 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
22
+ 					iinfo->i_lenEAttr) {
23
+ 				uint32_t aal =
24
+ 					le32_to_cpu(eahd->appAttrLocation);
25
++
26
++				osb();
27
+ 				memmove(&ea[offset - aal + size],
28
+ 					&ea[aal], offset - aal);
29
+ 				offset -= aal;
30
+@@ -114,6 +116,8 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
31
+ 					iinfo->i_lenEAttr) {
32
+ 				uint32_t ial =
33
+ 					le32_to_cpu(eahd->impAttrLocation);
34
++
35
++				osb();
36
+ 				memmove(&ea[offset - ial + size],
37
+ 					&ea[ial], offset - ial);
38
+ 				offset -= ial;
39
+@@ -125,6 +129,8 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
40
+ 					iinfo->i_lenEAttr) {
41
+ 				uint32_t aal =
42
+ 					le32_to_cpu(eahd->appAttrLocation);
43
++
44
++				osb();
45
+ 				memmove(&ea[offset - aal + size],
46
+ 					&ea[aal], offset - aal);
47
+ 				offset -= aal;
48
+-- 
49
+2.9.5
50
+
0 51
new file mode 100644
... ...
@@ -0,0 +1,39 @@
0
+From 616abca9e7f1add8e8f26cf6d33992b76412bcec Mon Sep 17 00:00:00 2001
1
+From: Tim Chen <tim.c.chen@linux.intel.com>
2
+Date: Fri, 15 Dec 2017 02:29:09 -0800
3
+Subject: [PATCH 155/194] userns: prevent speculative execution
4
+
5
+From: Elena Reshetova <elena.reshetova@intel.com>
6
+
7
+Since the pos value in function m_start()
8
+seems to be controllable by userspace and later on
9
+conditionally (upon bound check) used to resolve
10
+map->extent, insert an observable speculation
11
+barrier before its usage. This should prevent
12
+observable speculation on that branch and avoid
13
+kernel memory leak.
14
+
15
+Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
16
+---
17
+ kernel/user_namespace.c | 4 +++-
18
+ 1 file changed, 3 insertions(+), 1 deletion(-)
19
+
20
+diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
21
+index c490f1e..2240f36 100644
22
+--- a/kernel/user_namespace.c
23
+@@ -543,8 +543,10 @@ static void *m_start(struct seq_file *seq, loff_t *ppos,
24
+ 	struct uid_gid_extent *extent = NULL;
25
+ 	loff_t pos = *ppos;
26
+ 
27
+-	if (pos < map->nr_extents)
28
++	if (pos < map->nr_extents) {
29
++		osb();
30
+ 		extent = &map->extent[pos];
31
++	}
32
+ 
33
+ 	return extent;
34
+ }
35
+-- 
36
+2.9.5
37
+
0 38
new file mode 100644
... ...
@@ -0,0 +1,116 @@
0
+From 632c8d1eaacb69fb0e8ed5c6d8e19e4f69a17554 Mon Sep 17 00:00:00 2001
1
+From: Tim Chen <tim.c.chen@linux.intel.com>
2
+Date: Tue, 19 Sep 2017 15:21:40 -0700
3
+Subject: [PATCH 169/194] x86/syscall: Clear unused extra registers on syscall
4
+ entrance
5
+
6
+To prevent the unused registers %r12-%r15, %rbp and %rbx from
7
+being used speculatively, we clear them upon syscall entrance
8
+for code hygiene.
9
+---
10
+ arch/x86/entry/calling.h  | 19 +++++++++++++++++++
11
+ arch/x86/entry/entry_64.S | 13 ++++++++++---
12
+ 2 files changed, 29 insertions(+), 3 deletions(-)
13
+
14
+ Removed arch/x86/entry/calling.h changes, as it's in 4.4 upstream already
15
+
16
+diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
17
+index 952b23b5..d16bfe2 100644
18
+--- a/arch/x86/entry/entry_64.S
19
+@@ -171,7 +171,14 @@ GLOBAL(entry_SYSCALL_64_after_swapgs)
20
+ 	pushq	%r9				/* pt_regs->r9 */
21
+ 	pushq	%r10				/* pt_regs->r10 */
22
+ 	pushq	%r11				/* pt_regs->r11 */
23
+-	sub	$(6*8), %rsp			/* pt_regs->bp, bx, r12-15 not saved */
24
++	sub	$(6*8), %rsp			/* pt_regs->bp, bx, r12-15 not used */
25
++
26
++	/*
27
++	 * Clear the unused extra regs for code hygiene.
28
++	 * Will restore the callee saved extra regs at end of syscall.
29
++	 */
30
++	SAVE_EXTRA_REGS
31
++	ZERO_EXTRA_REGS
32
+ 
33
+ 	testl	$_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
34
+ 	jnz	tracesys
35
+@@ -211,6 +218,7 @@ entry_SYSCALL_64_fastpath:
36
+ 
37
+ 	movq	RIP(%rsp), %rcx
38
+ 	movq	EFLAGS(%rsp), %r11
39
++	RESTORE_EXTRA_REGS
40
+ 	RESTORE_C_REGS_EXCEPT_RCX_R11
41
+ 	/*
42
+ 	 * This opens a window where we have a user CR3, but are
43
+@@ -255,7 +263,6 @@ tracesys:
44
+ 	jmp	entry_SYSCALL_64_fastpath	/* and return to the fast path */
45
+ 
46
+ tracesys_phase2:
47
+-	SAVE_EXTRA_REGS
48
+ 	movq	%rsp, %rdi
49
+ 	movl	$AUDIT_ARCH_X86_64, %esi
50
+ 	movq	%rax, %rdx
51
+@@ -267,7 +274,6 @@ tracesys_phase2:
52
+ 	 * the value it wants us to use in the table lookup.
53
+ 	 */
54
+ 	RESTORE_C_REGS_EXCEPT_RAX
55
+-	RESTORE_EXTRA_REGS
56
+ #if __SYSCALL_MASK == ~0
57
+ 	cmpq	$__NR_syscall_max, %rax
58
+ #else
59
+@@ -286,10 +292,8 @@ tracesys_phase2:
60
+  * Has correct iret frame.
61
+  */
62
+ GLOBAL(int_ret_from_sys_call)
63
+-	SAVE_EXTRA_REGS
64
+ 	movq	%rsp, %rdi
65
+ 	call	syscall_return_slowpath	/* returns with IRQs disabled */
66
+-	RESTORE_EXTRA_REGS
67
+ 	TRACE_IRQS_IRETQ		/* we're about to change IF */
68
+ 
69
+ 	/*
70
+@@ -355,6 +359,7 @@ GLOBAL(int_ret_from_sys_call)
71
+ 	 * perf profiles. Nothing jumps here.
72
+ 	 */
73
+ syscall_return_via_sysret:
74
++	RESTORE_EXTRA_REGS
75
+ 	/* rcx and r11 are already restored (see code above) */
76
+ 	RESTORE_C_REGS_EXCEPT_RCX_R11
77
+ 	/*
78
+@@ -378,13 +383,12 @@ opportunistic_sysret_failed:
79
+ 	 */
80
+ 	SWITCH_USER_CR3
81
+ 	SWAPGS
82
+-	jmp	restore_c_regs_and_iret
83
++	jmp	restore_regs_and_iret
84
+ END(entry_SYSCALL_64)
85
+ 
86
+ 
87
+ 	.macro FORK_LIKE func
88
+ ENTRY(stub_\func)
89
+-	SAVE_EXTRA_REGS 8
90
+ 	jmp	sys_\func
91
+ END(stub_\func)
92
+ 	.endm
93
+@@ -442,18 +446,15 @@ ENTRY(stub_rt_sigreturn)
94
+ 	 * To make sure RESTORE_EXTRA_REGS doesn't restore garbage on error,
95
+ 	 * we SAVE_EXTRA_REGS here.
96
+ 	 */
97
+-	SAVE_EXTRA_REGS 8
98
+ 	call	sys_rt_sigreturn
99
+ return_from_stub:
100
+ 	addq	$8, %rsp
101
+-	RESTORE_EXTRA_REGS
102
+ 	movq	%rax, RAX(%rsp)
103
+ 	jmp	int_ret_from_sys_call
104
+ END(stub_rt_sigreturn)
105
+ 
106
+ #ifdef CONFIG_X86_X32_ABI
107
+ ENTRY(stub_x32_rt_sigreturn)
108
+-	SAVE_EXTRA_REGS 8
109
+ 	call	sys32_x32_rt_sigreturn
110
+ 	jmp	return_from_stub
111
+ END(stub_x32_rt_sigreturn)
112
+-- 
113
+2.9.5
114
+
0 115
new file mode 100644
... ...
@@ -0,0 +1,101 @@
0
+From 2c536e1e9227a94ce8f3fb8e52591a1c4b9e3975 Mon Sep 17 00:00:00 2001
1
+From: Tim Chen <tim.c.chen@linux.intel.com>
2
+Date: Fri, 15 Sep 2017 19:41:24 -0700
3
+Subject: [PATCH 170/194] x86/syscall: Clear unused extra registers on 32-bit
4
+ compatible syscall entrance
5
+
6
+To prevent the unused registers %r8-%r15, from being used speculatively,
7
+we clear them upon syscall entrance for code hygiene in 32 bit compatible
8
+mode.
9
+
10
+Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
11
+---
12
+ arch/x86/entry/calling.h         | 11 +++++++++++
13
+ arch/x86/entry/entry_64_compat.S | 18 ++++++++++++++----
14
+ 2 files changed, 25 insertions(+), 4 deletions(-)
15
+
16
+diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
17
+index 9a9e588..1439429 100644
18
+--- a/arch/x86/entry/calling.h
19
+@@ -129,6 +129,17 @@ For 32-bit we have the following conventions - kernel is built with
20
+ 	SAVE_C_REGS_HELPER 0, 0, 0, 1, 0
21
+ 	.endm
22
+ 
23
++	.macro CLEAR_R8_TO_R15
24
++	xorq %r15, %r15
25
++	xorq %r14, %r14
26
++	xorq %r13, %r13
27
++	xorq %r12, %r12
28
++	xorq %r11, %r11
29
++	xorq %r10, %r10
30
++	xorq %r9, %r9
31
++	xorq %r8, %r8
32
++	.endm
33
++
34
+ 	.macro SAVE_EXTRA_REGS offset=0
35
+ 	movq %r15, 0*8+\offset(%rsp)
36
+ 	movq %r14, 1*8+\offset(%rsp)
37
+diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
38
+index d03bf0e..0c59ac0 100644
39
+--- a/arch/x86/entry/entry_64_compat.S
40
+@@ -93,12 +93,14 @@ ENTRY(entry_SYSENTER_compat)
41
+ 	pushq   %r8                     /* pt_regs->r11 = 0 */
42
+ 	pushq   %rbx                    /* pt_regs->rbx */
43
+ 	pushq   %rbp                    /* pt_regs->rbp (will be overwritten) */
44
+-	pushq   %r8                     /* pt_regs->r12 = 0 */
45
+-	pushq   %r8                     /* pt_regs->r13 = 0 */
46
+-	pushq   %r8                     /* pt_regs->r14 = 0 */
47
+-	pushq   %r8                     /* pt_regs->r15 = 0 */
48
++	pushq   %r12                    /* pt_regs->r12 */
49
++	pushq   %r13                    /* pt_regs->r13 */
50
++	pushq   %r14                    /* pt_regs->r14 */
51
++	pushq   %r15                    /* pt_regs->r15 */
52
+ 	cld
53
+ 
54
++	CLEAR_R8_TO_R15
55
++
56
+ 	/*
57
+ 	 * Sysenter doesn't filter flags, so we need to clear NT
58
+ 	 * ourselves.  To save a few cycles, we can check whether
59
+@@ -192,10 +194,12 @@ ENTRY(entry_SYSCALL_compat)
60
+ 	pushq   %r8                     /* pt_regs->r11 = 0 */
61
+ 	pushq   %rbx                    /* pt_regs->rbx */
62
+ 	pushq   %rbp                    /* pt_regs->rbp (will be overwritten) */
63
+-	pushq   %r8                     /* pt_regs->r12 = 0 */
64
+-	pushq   %r8                     /* pt_regs->r13 = 0 */
65
+-	pushq   %r8                     /* pt_regs->r14 = 0 */
66
+-	pushq   %r8                     /* pt_regs->r15 = 0 */
67
++	pushq   %r12                    /* pt_regs->r12 */
68
++	pushq   %r13                    /* pt_regs->r13 */
69
++	pushq   %r14                    /* pt_regs->r14 */
70
++	pushq   %r15                    /* pt_regs->r15 */
71
++
72
++	CLEAR_R8_TO_R15
73
+ 
74
+ 	/*
75
+ 	 * User mode is traced as though IRQs are on, and SYSENTER
76
+@@ -213,6 +217,10 @@ ENTRY(entry_SYSCALL_compat)
77
+ sysret32_from_system_call:
78
+ 	TRACE_IRQS_ON			/* User mode traces as IRQs on. */
79
+ 	SWITCH_USER_CR3
80
++	movq	R15(%rsp), %r15		/* pt_regs->r15 */
81
++	movq	R14(%rsp), %r14		/* pt_regs->r14 */
82
++	movq	R13(%rsp), %r13		/* pt_regs->r13 */
83
++	movq	R12(%rsp), %r12		/* pt_regs->r12 */
84
+ 	movq	RBX(%rsp), %rbx		/* pt_regs->rbx */
85
+ 	movq	RBP(%rsp), %rbp		/* pt_regs->rbp */
86
+ 	movq	EFLAGS(%rsp), %r11	/* pt_regs->flags (in r11) */
87
+@@ -305,6 +313,8 @@ ENTRY(entry_INT80_compat)
88
+ 	pushq   %r15                    /* pt_regs->r15 */
89
+ 	cld
90
+ 
91
++	CLEAR_R8_TO_R15
92
++
93
+ 	/*
94
+ 	 * User mode is traced as though IRQs are on, and the interrupt
95
+ 	 * gate turned them off.
96
+-- 
97
+2.9.5
98
+