aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/events
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2014-05-29 13:00:24 -0400
committerIngo Molnar <mingo@kernel.org>2014-06-05 06:29:52 -0400
commitebf905fc7a6e7c99c53b5afc888d8f950da90aff (patch)
tree9b0c9289f1ac0f30fe14f9bb5a6a646023134f66 /kernel/events
parent10b0256496fd6c162478547f7c6df1e052e87644 (diff)
perf: Fix use after free in perf_remove_from_context()
While that mutex should guard the elements, it doesn't guard against the use-after-free that's from list_for_each_entry_rcu(). __perf_event_exit_task() can actually free the event. And because list addition/deletion is guarded by both ctx->mutex and ctx->lock, holding ctx->mutex is sufficient for reading the list, so we don't actually need the rcu list iteration. Fixes: 3a497f48637e ("perf: Simplify perf_event_exit_task_context()") Reported-by: Sasha Levin <sasha.levin@oracle.com> Tested-by: Sasha Levin <sasha.levin@oracle.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Dave Jones <davej@redhat.com> Cc: acme@ghostprotocols.net Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/20140529170024.GA2315@laptop.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/events')
-rw-r--r--kernel/events/core.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c
index ed50b0943213..a62d142ad498 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7431,7 +7431,7 @@ __perf_event_exit_task(struct perf_event *child_event,
7431 7431
7432static void perf_event_exit_task_context(struct task_struct *child, int ctxn) 7432static void perf_event_exit_task_context(struct task_struct *child, int ctxn)
7433{ 7433{
7434 struct perf_event *child_event; 7434 struct perf_event *child_event, *next;
7435 struct perf_event_context *child_ctx; 7435 struct perf_event_context *child_ctx;
7436 unsigned long flags; 7436 unsigned long flags;
7437 7437
@@ -7485,7 +7485,7 @@ static void perf_event_exit_task_context(struct task_struct *child, int ctxn)
7485 */ 7485 */
7486 mutex_lock(&child_ctx->mutex); 7486 mutex_lock(&child_ctx->mutex);
7487 7487
7488 list_for_each_entry_rcu(child_event, &child_ctx->event_list, event_entry) 7488 list_for_each_entry_safe(child_event, next, &child_ctx->event_list, event_entry)
7489 __perf_event_exit_task(child_event, child_ctx, child); 7489 __perf_event_exit_task(child_event, child_ctx, child);
7490 7490
7491 mutex_unlock(&child_ctx->mutex); 7491 mutex_unlock(&child_ctx->mutex);