]> Git Repo - linux.git/commitdiff
smp/hotplug: Handle removal correctly in cpuhp_store_callbacks()
authorEthan Barnes <[email protected]>
Wed, 19 Jul 2017 22:36:00 +0000 (22:36 +0000)
committerThomas Gleixner <[email protected]>
Thu, 20 Jul 2017 14:40:24 +0000 (16:40 +0200)
If cpuhp_store_callbacks() is called for CPUHP_AP_ONLINE_DYN or
CPUHP_BP_PREPARE_DYN, which are the indicators for dynamically allocated
states, then cpuhp_store_callbacks() allocates a new dynamic state. The
first allocation in each range returns CPUHP_AP_ONLINE_DYN or
CPUHP_BP_PREPARE_DYN.

If cpuhp_remove_state() is invoked for one of these states, then there is
no protection against the allocation mechanism. So the removal, which
should clear the callbacks and the name, gets a new state assigned and
clears that one.

As a consequence the state which should be cleared stays initialized. A
consecutive CPU hotplug operation dereferences the state callbacks and
accesses either freed or reused memory, resulting in crashes.

Add a protection against this by checking the name argument for NULL. If
it's NULL it's a removal. If not, it's an allocation.

[ tglx: Added a comment and massaged changelog ]

Fixes: 5b7aa87e0482 ("cpu/hotplug: Implement setup/removal interface")
Signed-off-by: Ethan Barnes <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "Srivatsa S. Bhat" <[email protected]>
Cc: Sebastian Siewior <[email protected]>
Cc: Paul McKenney <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/DM2PR04MB398242FC7776D603D9F99C894A60@DM2PR04MB398.namprd04.prod.outlook.com
kernel/cpu.c

index eee0331342628f09a02720ffe34aba2f8fb12f31..a88c29ab09be7bdb28ef6a484ad1bdcffca03a7c 100644 (file)
@@ -1252,7 +1252,17 @@ static int cpuhp_store_callbacks(enum cpuhp_state state, const char *name,
        struct cpuhp_step *sp;
        int ret = 0;
 
-       if (state == CPUHP_AP_ONLINE_DYN || state == CPUHP_BP_PREPARE_DYN) {
+       /*
+        * If name is NULL, then the state gets removed.
+        *
+        * CPUHP_AP_ONLINE_DYN and CPUHP_BP_PREPARE_DYN are handed out on
+        * the first allocation from these dynamic ranges, so the removal
+        * would trigger a new allocation and clear the wrong (already
+        * empty) state, leaving the callbacks of the to be cleared state
+        * dangling, which causes wreckage on the next hotplug operation.
+        */
+       if (name && (state == CPUHP_AP_ONLINE_DYN ||
+                    state == CPUHP_BP_PREPARE_DYN)) {
                ret = cpuhp_reserve_state(state);
                if (ret < 0)
                        return ret;
This page took 0.049134 seconds and 4 git commands to generate.