From: tip-bot for Alexei Starovoitov <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@infradead.org, torvalds@linux-foundation.org,
linux-kernel@vger.kernel.org, hpa@zytor.com, tglx@linutronix.de,
peterz@infradead.org, ast@plumgrid.com, wangnan0@huawei.com,
mingo@kernel.org
Subject: [tip:perf/core] perf: Fix race in BPF program unregister
Date: Wed, 27 May 2015 03:01:07 -0700 [thread overview]
Message-ID: <tip-dead9f29ddcc69551f35529a252d2704047870d3@git.kernel.org> (raw)
In-Reply-To: <1431717321-28772-1-git-send-email-ast@plumgrid.com>
Commit-ID: dead9f29ddcc69551f35529a252d2704047870d3
Gitweb: http://git.kernel.org/tip/dead9f29ddcc69551f35529a252d2704047870d3
Author: Alexei Starovoitov <ast@plumgrid.com>
AuthorDate: Fri, 15 May 2015 12:15:21 -0700
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 27 May 2015 08:46:15 +0200
perf: Fix race in BPF program unregister
there is a race between perf_event_free_bpf_prog() and free_trace_kprobe():
__free_event()
event->destroy(event)
tp_perf_event_destroy()
perf_trace_destroy()
perf_trace_event_unreg()
which is dropping event->tp_event->perf_refcount and allows to proceed in:
unregister_trace_kprobe()
unregister_kprobe_event()
trace_remove_event_call()
probe_remove_event_call()
free_trace_kprobe()
while __free_event does:
call_rcu(&event->rcu_head, free_event_rcu);
free_event_rcu()
perf_event_free_bpf_prog()
To fix the race simply move perf_event_free_bpf_prog() before
event->destroy(), since event->tp_event is still valid at that point.
Note, perf_trace_destroy() is not racing with trace_remove_event_call()
since they both grab event_mutex.
Reported-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: lizefan@huawei.com
Cc: pi3orama@163.com
Fixes: 2541517c32be ("tracing, perf: Implement BPF programs attached to kprobes")
Link: http://lkml.kernel.org/r/1431717321-28772-1-git-send-email-ast@plumgrid.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/events/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 1a3bf48..eddf1ed 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3442,7 +3442,6 @@ static void free_event_rcu(struct rcu_head *head)
if (event->ns)
put_pid_ns(event->ns);
perf_event_free_filter(event);
- perf_event_free_bpf_prog(event);
kfree(event);
}
@@ -3573,6 +3572,8 @@ static void __free_event(struct perf_event *event)
put_callchain_buffers();
}
+ perf_event_free_bpf_prog(event);
+
if (event->destroy)
event->destroy(event);
prev parent reply other threads:[~2015-05-27 11:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-15 19:15 [PATCH tip] perf/events/core: fix race in bpf program unregister Alexei Starovoitov
2015-05-20 5:27 ` Alexei Starovoitov
2015-05-20 6:58 ` Peter Zijlstra
2015-05-27 10:01 ` tip-bot for Alexei Starovoitov [this message]
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=tip-dead9f29ddcc69551f35529a252d2704047870d3@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@infradead.org \
--cc=ast@plumgrid.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=wangnan0@huawei.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