From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751958AbcCRHtr (ORCPT ); Fri, 18 Mar 2016 03:49:47 -0400 Received: from www.linutronix.de ([62.245.132.108]:35492 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750914AbcCRHtj (ORCPT ); Fri, 18 Mar 2016 03:49:39 -0400 Date: Fri, 18 Mar 2016 08:48:06 +0100 (CET) From: Thomas Gleixner To: "Richard W.M. Jones" cc: Josh Boyer , x86 , "Linux-Kernel@Vger. Kernel. Org" , Peter Zijlstra Subject: [PATCH] x86/tsc: Prevent NULL pointer deref in calibrate_delay_is_known() Message-ID: User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Subject: x86/tsc: Prevent NULL pointer deref in calibrate_delay_is_known() From: Thomas Gleixner Date: Fri, 18 Mar 2016 08:35:29 +0100 The topology_core_cpumask is used to find a neighbour cpu in calibrate_delay_is_known(). It might not be allocated at the first invocation of that function on the boot cpu, when CONFIG_CPUMASK_OFFSTACK is set. The mask is allocated later in native_smp_prepare_cpus. As a consequence the underlying find_next_bit() call dereferences a NULL pointer. Add a proper check to prevent this. Reported-by: Richard W.M. Jones Fixes: c25323c07345 "x86/tsc: Use topology functions" Signed-off-by: Thomas Gleixner Cc: Josh Boyer --- arch/x86/kernel/tsc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1306,11 +1306,15 @@ void __init tsc_init(void) unsigned long calibrate_delay_is_known(void) { int sibling, cpu = smp_processor_id(); + struct cpumask *mask = topology_core_cpumask(cpu); if (!tsc_disabled && !cpu_has(&cpu_data(cpu), X86_FEATURE_CONSTANT_TSC)) return 0; - sibling = cpumask_any_but(topology_core_cpumask(cpu), cpu); + if (!mask) + return 0; + + sibling = cpumask_any_but(mask, cpu); if (sibling < nr_cpu_ids) return cpu_data(sibling).loops_per_jiffy; return 0;