From: "tip-bot2 for Peter Zijlstra" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: syzbot+b8e8c01c8ade4fe6e48f@syzkaller.appspotmail.com,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Chengming Zhou <zhouchengming@bytedance.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: perf/urgent] perf: Fix use-after-free in error path
Date: Tue, 27 Dec 2022 11:51:23 -0000 [thread overview]
Message-ID: <167214188359.4906.13483243274583965054.tip-bot2@tip-bot2> (raw)
In-Reply-To: <Y6B3xEgkbmFUCeni@hirez.programming.kicks-ass.net>
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: a551844e345ba2a1c533dee4b55cb0efddb1bcda
Gitweb: https://git.kernel.org/tip/a551844e345ba2a1c533dee4b55cb0efddb1bcda
Author: Peter Zijlstra <peterz@infradead.org>
AuthorDate: Mon, 19 Dec 2022 15:40:04 +01:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 27 Dec 2022 12:44:01 +01:00
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: bd2756811766 ("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
---
kernel/events/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 37c0f04..63d674c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -12671,7 +12671,8 @@ SYSCALL_DEFINE5(perf_event_open,
return event_fd;
err_context:
- /* event->pmu_ctx freed by free_event() */
+ put_pmu_ctx(event->pmu_ctx);
+ event->pmu_ctx = NULL; /* _free_event() */
err_locked:
mutex_unlock(&ctx->mutex);
perf_unpin_context(ctx);
@@ -12784,6 +12785,7 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
err_pmu_ctx:
put_pmu_ctx(pmu_ctx);
+ event->pmu_ctx = NULL; /* _free_event() */
err_unlock:
mutex_unlock(&ctx->mutex);
perf_unpin_context(ctx);
next prev parent reply other threads:[~2022-12-27 11:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-19 8:04 [syzbot] KASAN: use-after-free Read in put_pmu_ctx syzbot
2022-12-19 14:40 ` Peter Zijlstra
2022-12-19 19:33 ` sdf
2022-12-19 19:56 ` syzbot
2022-12-19 21:33 ` sdf
2022-12-19 22:24 ` syzbot
2022-12-20 8:22 ` Peter Zijlstra
2022-12-20 17:10 ` Stanislav Fomichev
2022-12-20 19:37 ` syzbot
2022-12-21 2:42 ` Chengming Zhou
2022-12-22 20:59 ` Peter Zijlstra
2022-12-23 10:08 ` Chengming Zhou
2022-12-27 11:51 ` tip-bot2 for Peter Zijlstra [this message]
2022-12-20 8:25 ` Peter Zijlstra
2022-12-20 8:43 ` syzbot
2022-12-20 10:04 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=167214188359.4906.13483243274583965054.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=syzbot+b8e8c01c8ade4fe6e48f@syzkaller.appspotmail.com \
--cc=x86@kernel.org \
--cc=zhouchengming@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®