public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Alexei Starovoitov <ast@plumgrid.com>
Cc: Ingo Molnar <mingo@kernel.org>,
	Arnaldo Carvalho de Melo <acme@infradead.org>,
	Wang Nan <wangnan0@huawei.com>,
	lizefan@huawei.com, pi3orama@163.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH tip] perf/events/core: fix race in bpf program unregister
Date: Wed, 20 May 2015 08:58:23 +0200	[thread overview]
Message-ID: <20150520065823.GJ3644@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <555C1B29.1070404@plumgrid.com>

On Tue, May 19, 2015 at 10:27:05PM -0700, Alexei Starovoitov wrote:
> On 5/15/15 12:15 PM, Alexei Starovoitov wrote:
> >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.
> >
> >Fixes: 2541517c32be ("tracing, perf: Implement BPF programs attached to kprobes")
> >Reported-by: Wang Nan <wangnan0@huawei.com>
> >Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
> 
> ping.
> This is needed in 4.1.

Thanks, queued for perf/urgent.

  reply	other threads:[~2015-05-20  6:58 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 [this message]
2015-05-27 10:01 ` [tip:perf/core] perf: Fix race in BPF " tip-bot for Alexei Starovoitov

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=20150520065823.GJ3644@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@infradead.org \
    --cc=ast@plumgrid.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=mingo@kernel.org \
    --cc=pi3orama@163.com \
    --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