From: Budimir Markovic Date: Wed, 15 Mar 2023 07:29:01 +0000 (-0700) Subject: perf: Fix check before add_event_to_groups() in perf_group_detach() X-Git-Tag: baikal/mips/sdk6.1~4 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=929f9f4684191f9a9038f14b27129ee46fcf383f;p=kernel.git perf: Fix check before add_event_to_groups() in perf_group_detach() commit 762145c78d87c20c4d94cf997d97e4246accb849 upstream. Events should only be added to a groups rb tree if they have not been removed from their context by list_del_event(). Since remove_on_exec made it possible to call list_del_event() on individual events before they are detached from their group, perf_group_detach() should check each sibling's attach_state before calling add_event_to_groups() on it. Fixes: f080088de594 ("perf: Add support for event removal on exec") Signed-off-by: Budimir Markovic Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/ZBFzvQV9tEqoHEtH@gentoo Signed-off-by: Greg Kroah-Hartman --- diff --git a/kernel/events/core.c b/kernel/events/core.c index 3b9e86108f435..227ada7240295 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -2170,7 +2170,7 @@ static void perf_group_detach(struct perf_event *event) /* Inherit group flags from the previous leader */ sibling->group_caps = event->group_caps; - if (!RB_EMPTY_NODE(&event->group_node)) { + if (sibling->attach_state & PERF_ATTACH_CONTEXT) { add_event_to_groups(sibling, event->ctx); if (sibling->state == PERF_EVENT_STATE_ACTIVE)