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