1e6dda8
From 6b1292e2e61669457398e3b55e46490e7efca5f0 Mon Sep 17 00:00:00 2001
1e6dda8
From: Thomas Gleixner <tglx@linutronix.de>
1e6dda8
Date: Fri, 18 Mar 2016 08:35:29 +0100
1e6dda8
Subject: [PATCH] x86/tsc: Prevent NULL pointer deref in
1e6dda8
 calibrate_delay_is_known()
1e6dda8
1e6dda8
The topology_core_cpumask is used to find a neighbour cpu in
1e6dda8
calibrate_delay_is_known(). It might not be allocated at the first invocation
1e6dda8
of that function on the boot cpu, when CONFIG_CPUMASK_OFFSTACK is set.
1e6dda8
1e6dda8
The mask is allocated later in native_smp_prepare_cpus. As a consequence the
1e6dda8
underlying find_next_bit() call dereferences a NULL pointer.
1e6dda8
1e6dda8
Add a proper check to prevent this.
1e6dda8
1e6dda8
Reported-by: Richard W.M. Jones <rjones@redhat.com>
1e6dda8
Fixes: c25323c07345 "x86/tsc: Use topology functions"
1e6dda8
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1e6dda8
Cc: Josh Boyer <jwboyer@fedoraproject.org>
1e6dda8
---
1e6dda8
 arch/x86/kernel/tsc.c | 6 +++++-
1e6dda8
 1 file changed, 5 insertions(+), 1 deletion(-)
1e6dda8
1e6dda8
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
1e6dda8
index 56380440d862..99b5e0809ead 100644
1e6dda8
--- a/arch/x86/kernel/tsc.c
1e6dda8
+++ b/arch/x86/kernel/tsc.c
1e6dda8
@@ -1306,11 +1306,15 @@ void __init tsc_init(void)
1e6dda8
 unsigned long calibrate_delay_is_known(void)
1e6dda8
 {
1e6dda8
 	int sibling, cpu = smp_processor_id();
1e6dda8
+	struct cpumask *mask = topology_core_cpumask(cpu);
1e6dda8
 
1e6dda8
 	if (!tsc_disabled && !cpu_has(&cpu_data(cpu), X86_FEATURE_CONSTANT_TSC))
1e6dda8
 		return 0;
1e6dda8
 
1e6dda8
-	sibling = cpumask_any_but(topology_core_cpumask(cpu), cpu);
1e6dda8
+	if (!mask)
1e6dda8
+		return 0;
1e6dda8
+
1e6dda8
+	sibling = cpumask_any_but(mask, cpu);
1e6dda8
 	if (sibling < nr_cpu_ids)
1e6dda8
 		return cpu_data(sibling).loops_per_jiffy;
1e6dda8
 	return 0;
1e6dda8
-- 
1e6dda8
2.5.0
1e6dda8