]> git.karo-electronics.de Git - karo-tx-linux.git/commit
Use get_online_cpus to avoid races involving CPU hotplug
authorSilas Boyd-Wickizer <sbw@mit.edu>
Fri, 3 Aug 2012 19:33:27 +0000 (12:33 -0700)
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Tue, 4 Sep 2012 23:54:02 +0000 (16:54 -0700)
commit0aac66f4dbc6d76b685d779ab9109e4caa6311c7
treef9dd7bef4f96dbc5b8e8b788d825cdf0b1b01b42
parentd7278a37c72ae30fc84c4d78bf0e4466789a0228
Use get_online_cpus to avoid races involving CPU hotplug

If arch/x86/kernel/msr.c is a module, a CPU might offline or online
between the for_each_online_cpu(i) loop and the call to
register_hotcpu_notifier in msr_init or the call to
unregister_hotcpu_notifier in msr_exit. The potential races can lead
to leaks/duplicates, attempts to destroy non-existant devices, or
random pointer dereferences.

For example, in msr_init if:

        for_each_online_cpu(i) {
                err = msr_device_create(i);
                if (err != 0)
                        goto out_class;
        }
        <----- CPU offlines
        register_hotcpu_notifier(&msr_class_cpu_notifier);

and the CPU never onlines before msr_exit, then the module will never
call msr_device_destroy for the associated CPU.

This fix surrounds for_each_online_cpu and register_hotcpu_notifier or
unregister_hotcpu_notifier with get_online_cpus+put_online_cpus.

Tested on a VM.

Signed-off-by: Silas Boyd-Wickizer <sbw@mit.edu>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
arch/x86/kernel/msr.c