Skip to content

Commit c9c7e0c

Browse files
ciq-sahlbergPlaidCat
authored andcommitted
perf: Fix perf_event_validate_size() lockdep splat
jira SECO-54 cve-bugfix CVE-2023-6931 commit 7e2c1e4 When lockdep is enabled, the for_each_sibling_event(sibling, event) macro checks that event->ctx->mutex is held. When creating a new group leader event, we call perf_event_validate_size() on a partially initialized event where event->ctx is NULL, and so when for_each_sibling_event() attempts to check event->ctx->mutex, we get a splat, as reported by Lucas De Marchi: WARNING: CPU: 8 PID: 1471 at kernel/events/core.c:1950 __do_sys_perf_event_open+0xf37/0x1080 This only happens for a new event which is its own group_leader, and in this case there cannot be any sibling events. Thus it's safe to skip the check for siblings, which avoids having to make invasive and ugly changes to for_each_sibling_event(). Avoid the splat by bailing out early when the new event is its own group_leader. Fixes: 382c27f ("perf: Fix perf_event_validate_size()") Closes: https://lore.kernel.org/lkml/[email protected]/ Closes: https://lore.kernel.org/lkml/ZXpm6gQ%[email protected]/ Reported-by: Lucas De Marchi <[email protected]> Reported-by: Pengfei Xu <[email protected]> Signed-off-by: Mark Rutland <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected] (cherry picked from commit 7e2c1e4) Signed-off-by: Ronnie Sahlberg <[email protected]>
1 parent fa73c0a commit c9c7e0c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

kernel/events/core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,16 @@ static bool perf_event_validate_size(struct perf_event *event)
19801980
group_leader->nr_siblings + 1) > 16*1024)
19811981
return false;
19821982

1983+
/*
1984+
* When creating a new group leader, group_leader->ctx is initialized
1985+
* after the size has been validated, but we cannot safely use
1986+
* for_each_sibling_event() until group_leader->ctx is set. A new group
1987+
* leader cannot have any siblings yet, so we can safely skip checking
1988+
* the non-existent siblings.
1989+
*/
1990+
if (event == group_leader)
1991+
return true;
1992+
19831993
for_each_sibling_event(sibling, group_leader) {
19841994
if (__perf_event_read_size(sibling->attr.read_format,
19851995
group_leader->nr_siblings + 1) > 16*1024)

0 commit comments

Comments
 (0)