Skip to content

Commit 3b1e5c4

Browse files
LeviYeoReumgregkh
authored andcommitted
perf: Fix dangling cgroup pointer in cpuctx
[ Upstream commit 3b7a34a ] Commit a3c3c66("perf/core: Fix child_total_time_enabled accounting bug at task exit") moves the event->state update to before list_del_event(). This makes the event->state test in list_del_event() always false; never calling perf_cgroup_event_disable(). As a result, cpuctx->cgrp won't be cleared properly; causing havoc. Fixes: a3c3c66("perf/core: Fix child_total_time_enabled accounting bug at task exit") Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: David Wang <00107082@163.com> Link: https://lore.kernel.org/all/aD2TspKH%2F7yvfYoO@e129823.arm.com/ Stable-dep-of: 42c5ca1 ("perf/core: Fix group leader use-after-free after sibling detach") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6449c42 commit 3b1e5c4

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

kernel/events/core.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,18 +2031,6 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
20312031
if (event->group_leader == event)
20322032
del_event_from_groups(event, ctx);
20332033

2034-
/*
2035-
* If event was in error state, then keep it
2036-
* that way, otherwise bogus counts will be
2037-
* returned on read(). The only way to get out
2038-
* of error state is by explicit re-enabling
2039-
* of the event
2040-
*/
2041-
if (event->state > PERF_EVENT_STATE_OFF) {
2042-
perf_cgroup_event_disable(event, ctx);
2043-
perf_event_set_state(event, PERF_EVENT_STATE_OFF);
2044-
}
2045-
20462034
ctx->generation++;
20472035
}
20482036

@@ -2396,6 +2384,10 @@ __perf_remove_from_context(struct perf_event *event,
23962384
state = PERF_EVENT_STATE_DEAD;
23972385
}
23982386
event_sched_out(event, cpuctx, ctx);
2387+
2388+
if (event->state > PERF_EVENT_STATE_OFF)
2389+
perf_cgroup_event_disable(event, ctx);
2390+
23992391
perf_event_set_state(event, min(event->state, state));
24002392
if (flags & DETACH_GROUP)
24012393
perf_group_detach(event);

0 commit comments

Comments
 (0)