1 From dd853fd216d1485ed3045ff772079cc8689a9a4a Mon Sep 17 00:00:00 2001
2 From: Lukasz Odzioba <lukasz.odzioba@intel.com>
3 Date: Wed, 28 Dec 2016 14:55:40 +0100
4 Subject: x86/cpu: Fix bootup crashes by sanitizing the argument of the 'clearcpuid=' command-line option
6 From: Lukasz Odzioba <lukasz.odzioba@intel.com>
8 commit dd853fd216d1485ed3045ff772079cc8689a9a4a upstream.
10 A negative number can be specified in the cmdline which will be used as
11 setup_clear_cpu_cap() argument. With that we can clear/set some bit in
12 memory predceeding boot_cpu_data/cpu_caps_cleared which may cause kernel
13 to misbehave. This patch adds lower bound check to setup_disablecpuid().
15 Boris Petkov reproduced a crash:
17 [ 1.234575] BUG: unable to handle kernel paging request at ffffffff858bd540
18 [ 1.236535] IP: memcpy_erms+0x6/0x10
20 Signed-off-by: Lukasz Odzioba <lukasz.odzioba@intel.com>
21 Acked-by: Borislav Petkov <bp@suse.de>
22 Cc: Linus Torvalds <torvalds@linux-foundation.org>
23 Cc: Peter Zijlstra <peterz@infradead.org>
24 Cc: Thomas Gleixner <tglx@linutronix.de>
25 Cc: andi.kleen@intel.com
27 Cc: dave.hansen@linux.intel.com
30 Fixes: ac72e7888a61 ("x86: add generic clearcpuid=... option")
31 Link: http://lkml.kernel.org/r/1482933340-11857-1-git-send-email-lukasz.odzioba@intel.com
32 Signed-off-by: Ingo Molnar <mingo@kernel.org>
33 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
36 arch/x86/kernel/cpu/common.c | 2 +-
37 1 file changed, 1 insertion(+), 1 deletion(-)
39 --- a/arch/x86/kernel/cpu/common.c
40 +++ b/arch/x86/kernel/cpu/common.c
41 @@ -1275,7 +1275,7 @@ static __init int setup_disablecpuid(cha
45 - if (get_option(&arg, &bit) && bit < NCAPINTS*32)
46 + if (get_option(&arg, &bit) && bit >= 0 && bit < NCAPINTS * 32)
47 setup_clear_cpu_cap(bit);