3.13.11-ckt17 -stable review patch.  If anyone has any objections, please let 
me know.

------------------

From: Lai Jiangshan <la...@cn.fujitsu.com>

commit 4bee96860a65c3a62d332edac331b3cf936ba3ad 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 <la...@cn.fujitsu.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Rusty Russell <ru...@rustcorp.com.au>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Srivatsa S. Bhat <srivatsa.b...@linux.vnet.ibm.com>
Cc: David Rientjes <rient...@google.com>
Link: 
http://lkml.kernel.org/r/1406777421-12830-1-git-send-email-la...@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <t...@linutronix.de>
Signed-off-by: Kamal Mostafa <ka...@canonical.com>
---
 kernel/smpboot.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/smpboot.c b/kernel/smpboot.c
index eb89e18..60d35ac5 100644
--- a/kernel/smpboot.c
+++ b/kernel/smpboot.c
@@ -279,6 +279,7 @@ int smpboot_register_percpu_thread(struct 
smp_hotplug_thread *plug_thread)
        unsigned int cpu;
        int ret = 0;
 
+       get_online_cpus();
        mutex_lock(&smpboot_threads_lock);
        for_each_online_cpu(cpu) {
                ret = __smpboot_create_thread(plug_thread, cpu);
@@ -291,6 +292,7 @@ int smpboot_register_percpu_thread(struct 
smp_hotplug_thread *plug_thread)
        list_add(&plug_thread->list, &hotplug_threads);
 out:
        mutex_unlock(&smpboot_threads_lock);
+       put_online_cpus();
        return ret;
 }
 EXPORT_SYMBOL_GPL(smpboot_register_percpu_thread);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to