Skip to content

Commit 059fcd8

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
perf/core: Plug potential memory leak in CPU_UP_PREPARE
If CPU_UP_PREPARE is called it is not guaranteed, that a previously allocated and assigned hash has been freed already, but perf_event_init_cpu() unconditionally allocates and assignes a new hash if the swhash is referenced. By overwriting the pointer the existing hash is not longer accessible. Verify that there is no hash assigned on this cpu before allocating and assigning a new one. Signed-off-by: Thomas Gleixner <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Vince Weaver <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 27ca923 commit 059fcd8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9206,7 +9206,7 @@ static void perf_event_init_cpu(int cpu)
92069206
struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
92079207

92089208
mutex_lock(&swhash->hlist_mutex);
9209-
if (swhash->hlist_refcount > 0) {
9209+
if (swhash->hlist_refcount > 0 && !swevent_hlist_deref(swhash)) {
92109210
struct swevent_hlist *hlist;
92119211

92129212
hlist = kzalloc_node(sizeof(*hlist), GFP_KERNEL, cpu_to_node(cpu));

0 commit comments

Comments
 (0)