]> git.proxmox.com Git - pve-kernel.git/blob - patches/kernel/0048-x86-tracing-Introduce-a-static-key-for-exception-tra.patch
KPTI: add follow-up fixes
[pve-kernel.git] / patches / kernel / 0048-x86-tracing-Introduce-a-static-key-for-exception-tra.patch
1 From 179faefa769caa263bc88b1f7292be7a60df4298 Mon Sep 17 00:00:00 2001
2 From: Thomas Gleixner <tglx@linutronix.de>
3 Date: Mon, 28 Aug 2017 08:47:21 +0200
4 Subject: [PATCH 048/241] x86/tracing: Introduce a static key for exception
5 tracing
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 CVE-2017-5754
11
12 Switching the IDT just for avoiding tracepoints creates a completely
13 impenetrable macro/inline/ifdef mess.
14
15 There is no point in avoiding tracepoints for most of the traps/exceptions.
16 For the more expensive tracepoints, like pagefaults, this can be handled with
17 an explicit static key.
18
19 Preparatory patch to remove the tracing IDT.
20
21 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
22 Cc: Andy Lutomirski <luto@kernel.org>
23 Cc: Borislav Petkov <bp@alien8.de>
24 Cc: Linus Torvalds <torvalds@linux-foundation.org>
25 Cc: Peter Zijlstra <peterz@infradead.org>
26 Cc: Steven Rostedt <rostedt@goodmis.org>
27 Link: http://lkml.kernel.org/r/20170828064956.593094539@linutronix.de
28 Signed-off-by: Ingo Molnar <mingo@kernel.org>
29 (cherry picked from commit 2feb1b316d48004d905278c02a55902cab0be8be)
30 Signed-off-by: Andy Whitcroft <apw@kathleen.maas>
31 (cherry picked from commit 15e0ff2a63fdd93f8881e2ebba5c048c5b601e57)
32 Signed-off-by: Andy Whitcroft <apw@canonical.com>
33 Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
34 (cherry picked from commit d58a56e851c339d8d9d311dc9b4fad6abbf8bf19)
35 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
36 ---
37 arch/x86/include/asm/trace/common.h | 15 +++++++++++++++
38 arch/x86/include/asm/trace/exceptions.h | 4 +---
39 arch/x86/include/asm/trace/irq_vectors.h | 4 +---
40 arch/x86/kernel/tracepoint.c | 9 ++++++++-
41 4 files changed, 25 insertions(+), 7 deletions(-)
42 create mode 100644 arch/x86/include/asm/trace/common.h
43
44 diff --git a/arch/x86/include/asm/trace/common.h b/arch/x86/include/asm/trace/common.h
45 new file mode 100644
46 index 000000000000..b1eb7b18ee8a
47 --- /dev/null
48 +++ b/arch/x86/include/asm/trace/common.h
49 @@ -0,0 +1,15 @@
50 +#ifndef _ASM_TRACE_COMMON_H
51 +#define _ASM_TRACE_COMMON_H
52 +
53 +extern int trace_irq_vector_regfunc(void);
54 +extern void trace_irq_vector_unregfunc(void);
55 +
56 +#ifdef CONFIG_TRACING
57 +DECLARE_STATIC_KEY_FALSE(trace_irqvectors_key);
58 +#define trace_irqvectors_enabled() \
59 + static_branch_unlikely(&trace_irqvectors_key)
60 +#else
61 +static inline bool trace_irqvectors_enabled(void) { return false; }
62 +#endif
63 +
64 +#endif
65 diff --git a/arch/x86/include/asm/trace/exceptions.h b/arch/x86/include/asm/trace/exceptions.h
66 index 2422b14c50a7..960a5b50ac3b 100644
67 --- a/arch/x86/include/asm/trace/exceptions.h
68 +++ b/arch/x86/include/asm/trace/exceptions.h
69 @@ -5,9 +5,7 @@
70 #define _TRACE_PAGE_FAULT_H
71
72 #include <linux/tracepoint.h>
73 -
74 -extern int trace_irq_vector_regfunc(void);
75 -extern void trace_irq_vector_unregfunc(void);
76 +#include <asm/trace/common.h>
77
78 DECLARE_EVENT_CLASS(x86_exceptions,
79
80 diff --git a/arch/x86/include/asm/trace/irq_vectors.h b/arch/x86/include/asm/trace/irq_vectors.h
81 index 32dd6a9e343c..7825b4426e7e 100644
82 --- a/arch/x86/include/asm/trace/irq_vectors.h
83 +++ b/arch/x86/include/asm/trace/irq_vectors.h
84 @@ -5,9 +5,7 @@
85 #define _TRACE_IRQ_VECTORS_H
86
87 #include <linux/tracepoint.h>
88 -
89 -extern int trace_irq_vector_regfunc(void);
90 -extern void trace_irq_vector_unregfunc(void);
91 +#include <asm/trace/common.h>
92
93 DECLARE_EVENT_CLASS(x86_irq_vector,
94
95 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
96 index 15515132bf0d..dd4aa04bb95c 100644
97 --- a/arch/x86/kernel/tracepoint.c
98 +++ b/arch/x86/kernel/tracepoint.c
99 @@ -4,9 +4,11 @@
100 * Copyright (C) 2013 Seiji Aguchi <seiji.aguchi@hds.com>
101 *
102 */
103 +#include <linux/jump_label.h>
104 +#include <linux/atomic.h>
105 +
106 #include <asm/hw_irq.h>
107 #include <asm/desc.h>
108 -#include <linux/atomic.h>
109
110 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
111 struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
112 @@ -15,6 +17,7 @@ struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
113 /* No need to be aligned, but done to keep all IDTs defined the same way. */
114 gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
115
116 +DEFINE_STATIC_KEY_FALSE(trace_irqvectors_key);
117 static int trace_irq_vector_refcount;
118 static DEFINE_MUTEX(irq_vector_mutex);
119
120 @@ -36,6 +39,8 @@ static void switch_idt(void *arg)
121
122 int trace_irq_vector_regfunc(void)
123 {
124 + static_branch_inc(&trace_irqvectors_key);
125 +
126 mutex_lock(&irq_vector_mutex);
127 if (!trace_irq_vector_refcount) {
128 set_trace_idt_ctr(1);
129 @@ -49,6 +54,8 @@ int trace_irq_vector_regfunc(void)
130
131 void trace_irq_vector_unregfunc(void)
132 {
133 + static_branch_dec(&trace_irqvectors_key);
134 +
135 mutex_lock(&irq_vector_mutex);
136 trace_irq_vector_refcount--;
137 if (!trace_irq_vector_refcount) {
138 --
139 2.14.2
140