]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0072-x86-cpuid-Prevent-out-of-bound-access-in-do_clear_cp.patch
KPTI: add follow-up fixes
[pve-kernel.git] / patches / kernel / 0072-x86-cpuid-Prevent-out-of-bound-access-in-do_clear_cp.patch
CommitLineData
321d628a
FG
1From a827c0ac43c2dc1e5e0528ebd4b2ca2d74534e18 Mon Sep 17 00:00:00 2001
2From: Thomas Gleixner <tglx@linutronix.de>
3Date: Wed, 18 Oct 2017 19:39:35 +0200
e4cdf2a5 4Subject: [PATCH 072/241] x86/cpuid: Prevent out of bound access in
321d628a
FG
5 do_clear_cpu_cap()
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10CVE-2017-5754
11
12do_clear_cpu_cap() allocates a bitmap to keep track of disabled feature
13dependencies. That bitmap is sized NCAPINTS * BITS_PER_INIT. The possible
14'features' which can be handed in are larger than this, because after the
15capabilities the bug 'feature' bits occupy another 32bit. Not really
16obvious...
17
18So clearing any of the misfeature bits, as 32bit does for the F00F bug,
19accesses that bitmap out of bounds thereby corrupting the stack.
20
21Size the bitmap proper and add a sanity check to catch accidental out of
22bound access.
23
24Fixes: 0b00de857a64 ("x86/cpuid: Add generic table for CPUID dependencies")
25Reported-by: kernel test robot <xiaolong.ye@intel.com>
26Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
27Cc: Andi Kleen <ak@linux.intel.com>
28Cc: Borislav Petkov <bp@alien8.de>
29Link: https://lkml.kernel.org/r/20171018022023.GA12058@yexl-desktop
30(cherry picked from commit 57b8b1a1856adaa849d02d547411a553a531022b)
31Signed-off-by: Andy Whitcroft <apw@canonical.com>
32Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
33(cherry picked from commit 4b3a90bd20b35a97fd9ca6f6a71131f4417782e4)
34Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
35---
36 arch/x86/kernel/cpu/cpuid-deps.c | 10 ++++++++--
37 1 file changed, 8 insertions(+), 2 deletions(-)
38
39diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
40index e48eb7313120..c1d49842a411 100644
41--- a/arch/x86/kernel/cpu/cpuid-deps.c
42+++ b/arch/x86/kernel/cpu/cpuid-deps.c
43@@ -75,11 +75,17 @@ static inline void clear_feature(struct cpuinfo_x86 *c, unsigned int feature)
44 __clear_cpu_cap(c, feature);
45 }
46
47+/* Take the capabilities and the BUG bits into account */
48+#define MAX_FEATURE_BITS ((NCAPINTS + NBUGINTS) * sizeof(u32) * 8)
49+
50 static void do_clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int feature)
51 {
52- bool changed;
53- DECLARE_BITMAP(disable, NCAPINTS * sizeof(u32) * 8);
54+ DECLARE_BITMAP(disable, MAX_FEATURE_BITS);
55 const struct cpuid_dep *d;
56+ bool changed;
57+
58+ if (WARN_ON(feature >= MAX_FEATURE_BITS))
59+ return;
60
61 clear_feature(c, feature);
62
63--
642.14.2
65