Skip to content

Commit a551844

Browse files
author
Peter Zijlstra
committed
perf: Fix use-after-free in error path
The syscall error path has a use-after-free; put_pmu_ctx() will reference ctx, therefore we must ensure ctx is destroyed after pmu_ctx is. Fixes: bd27568 ("perf: Rewrite core context handling") Reported-by: syzbot+b8e8c01c8ade4fe6e48f@syzkaller.appspotmail.com Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Chengming Zhou <zhouchengming@bytedance.com> Link: https://lkml.kernel.org/r/Y6B3xEgkbmFUCeni@hirez.programming.kicks-ass.net
1 parent 0824567 commit a551844

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/events/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12671,7 +12671,8 @@ SYSCALL_DEFINE5(perf_event_open,
1267112671
return event_fd;
1267212672

1267312673
err_context:
12674-
/* event->pmu_ctx freed by free_event() */
12674+
put_pmu_ctx(event->pmu_ctx);
12675+
event->pmu_ctx = NULL; /* _free_event() */
1267512676
err_locked:
1267612677
mutex_unlock(&ctx->mutex);
1267712678
perf_unpin_context(ctx);
@@ -12784,6 +12785,7 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
1278412785

1278512786
err_pmu_ctx:
1278612787
put_pmu_ctx(pmu_ctx);
12788+
event->pmu_ctx = NULL; /* _free_event() */
1278712789
err_unlock:
1278812790
mutex_unlock(&ctx->mutex);
1278912791
perf_unpin_context(ctx);

0 commit comments

Comments
 (0)