| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- From a827c0ac43c2dc1e5e0528ebd4b2ca2d74534e18 Mon Sep 17 00:00:00 2001
- From: Thomas Gleixner <[email protected]>
- Date: Wed, 18 Oct 2017 19:39:35 +0200
- Subject: [PATCH 072/232] x86/cpuid: Prevent out of bound access in
- do_clear_cpu_cap()
- MIME-Version: 1.0
- Content-Type: text/plain; charset=UTF-8
- Content-Transfer-Encoding: 8bit
- CVE-2017-5754
- do_clear_cpu_cap() allocates a bitmap to keep track of disabled feature
- dependencies. That bitmap is sized NCAPINTS * BITS_PER_INIT. The possible
- 'features' which can be handed in are larger than this, because after the
- capabilities the bug 'feature' bits occupy another 32bit. Not really
- obvious...
- So clearing any of the misfeature bits, as 32bit does for the F00F bug,
- accesses that bitmap out of bounds thereby corrupting the stack.
- Size the bitmap proper and add a sanity check to catch accidental out of
- bound access.
- Fixes: 0b00de857a64 ("x86/cpuid: Add generic table for CPUID dependencies")
- Reported-by: kernel test robot <[email protected]>
- Signed-off-by: Thomas Gleixner <[email protected]>
- Cc: Andi Kleen <[email protected]>
- Cc: Borislav Petkov <[email protected]>
- Link: https://lkml.kernel.org/r/20171018022023.GA12058@yexl-desktop
- (cherry picked from commit 57b8b1a1856adaa849d02d547411a553a531022b)
- Signed-off-by: Andy Whitcroft <[email protected]>
- Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
- (cherry picked from commit 4b3a90bd20b35a97fd9ca6f6a71131f4417782e4)
- Signed-off-by: Fabian Grünbichler <[email protected]>
- ---
- arch/x86/kernel/cpu/cpuid-deps.c | 10 ++++++++--
- 1 file changed, 8 insertions(+), 2 deletions(-)
- diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
- index e48eb7313120..c1d49842a411 100644
- --- a/arch/x86/kernel/cpu/cpuid-deps.c
- +++ b/arch/x86/kernel/cpu/cpuid-deps.c
- @@ -75,11 +75,17 @@ static inline void clear_feature(struct cpuinfo_x86 *c, unsigned int feature)
- __clear_cpu_cap(c, feature);
- }
-
- +/* Take the capabilities and the BUG bits into account */
- +#define MAX_FEATURE_BITS ((NCAPINTS + NBUGINTS) * sizeof(u32) * 8)
- +
- static void do_clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int feature)
- {
- - bool changed;
- - DECLARE_BITMAP(disable, NCAPINTS * sizeof(u32) * 8);
- + DECLARE_BITMAP(disable, MAX_FEATURE_BITS);
- const struct cpuid_dep *d;
- + bool changed;
- +
- + if (WARN_ON(feature >= MAX_FEATURE_BITS))
- + return;
-
- clear_feature(c, feature);
-
- --
- 2.14.2
|