Skip to content

Commit 1c3a363

Browse files
Lai Jiangshangregkh
authored andcommitted
smpboot: Add missing get_online_cpus() in smpboot_register_percpu_thread()
commit 4bee968 upstream. The following race exists in the smpboot percpu threads management: CPU0 CPU1 cpu_up(2) get_online_cpus(); smpboot_create_threads(2); smpboot_register_percpu_thread(); for_each_online_cpu(); __smpboot_create_thread(); __cpu_up(2); This results in a missing per cpu thread for the newly onlined cpu2 and in a NULL pointer dereference on a consecutive offline of that cpu. Proctect smpboot_register_percpu_thread() with get_online_cpus() to prevent that. [ tglx: Massaged changelog and removed the change in smpboot_unregister_percpu_thread() because that's an optimization and therefor not stable material. ] Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com> Cc: David Rientjes <rientjes@google.com> Link: http://lkml.kernel.org/r/1406777421-12830-1-git-send-email-laijs@cn.fujitsu.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ff0d188 commit 1c3a363

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎kernel/smpboot.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
279279
unsigned int cpu;
280280
int ret = 0;
281281

282+
get_online_cpus();
282283
mutex_lock(&smpboot_threads_lock);
283284
for_each_online_cpu(cpu) {
284285
ret = __smpboot_create_thread(plug_thread, cpu);
@@ -291,6 +292,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
291292
list_add(&plug_thread->list, &hotplug_threads);
292293
out:
293294
mutex_unlock(&smpboot_threads_lock);
295+
put_online_cpus();
294296
return ret;
295297
}
296298
EXPORT_SYMBOL_GPL(smpboot_register_percpu_thread);

0 commit comments

Comments
 (0)