Commit fd3d664fef97cf01f8e28fe0b024ad52f3bbc1bc

Authored by Eric Dumazet
Committed by Linus Torvalds
1 parent fe102c71a6

percpu_counter: fix CPU unplug race in percpu_counter_destroy()

We should first delete the counter from percpu_counters list
before freeing memory, or a percpu_counter_hotcpu_callback()
could dereference a NULL pointer.

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Acked-by: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 2 additions and 2 deletions Side-by-side Diff

lib/percpu_counter.c
... ... @@ -104,13 +104,13 @@
104 104 if (!fbc->counters)
105 105 return;
106 106  
107   - free_percpu(fbc->counters);
108   - fbc->counters = NULL;
109 107 #ifdef CONFIG_HOTPLUG_CPU
110 108 mutex_lock(&percpu_counters_lock);
111 109 list_del(&fbc->list);
112 110 mutex_unlock(&percpu_counters_lock);
113 111 #endif
  112 + free_percpu(fbc->counters);
  113 + fbc->counters = NULL;
114 114 }
115 115 EXPORT_SYMBOL(percpu_counter_destroy);
116 116