mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Li Huafei <lihuafei1@huawei.com>
To: <rostedt@goodmis.org>, <mingo@redhat.com>, <jolsa@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <yangjihong1@huawei.com>,
	<xukuohai@huawei.com>, <zhangjinhao2@huawei.com>,
	<lihuafei1@huawei.com>
Subject: [PATCH 0/2] Fix the race on &event->ftrace_ops between perf and ftrace
Date: Wed, 17 Mar 2021 18:25:27 +0800	[thread overview]
Message-ID: <20210317102529.226734-1-lihuafei1@huawei.com> (raw)

There is a race on &event->ftrace_ops between perf_alloc_event() and
__ftrace_ops_list_func(). When adding a perf event, if the event needs
to use the ftrace framework, it needs to register ftrace_ops with
ftrace, which is a structural member of perf event. If perf_alloc_event()
fails, it will free the allocated event directly, but if ftrace_ops has
been successfully registered, and the probe point is triggered, then
__ftrace_ops_list_func() may still reference the ftrace_ops that perf
just registered, but it has been freed with the event is freed,
so use-after-free happens.

This race condition was triggered when we did the fuzz test, see the commit
message of PATCH 2 for detailed logs. This patch set fixes this race.

Li Huafei (2):
  ftrace: Update ftrace_ops->next pointer with rcu_assign_pointer()
  perf, ftrace: Fix use-after-free in __ftrace_ops_list_func()

 include/linux/ftrace.h          | 15 +++++++++++++++
 kernel/trace/ftrace.c           |  4 ++--
 kernel/trace/trace_event_perf.c |  7 +++++++
 3 files changed, 24 insertions(+), 2 deletions(-)

-- 
2.17.1


             reply	other threads:[~2021-03-17 10:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 10:25 Li Huafei [this message]
2021-03-17 10:25 ` [PATCH 1/2] ftrace: Update ftrace_ops->next pointer with rcu_assign_pointer() Li Huafei
2021-03-25  1:20   ` Steven Rostedt
2021-03-17 10:25 ` [PATCH 2/2] perf, ftrace: Fix use-after-free in __ftrace_ops_list_func() Li Huafei
2021-03-25  1:11   ` Steven Rostedt
2021-03-25  1:14     ` Steven Rostedt

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=20210317102529.226734-1-lihuafei1@huawei.com \
    --to=lihuafei1@huawei.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=xukuohai@huawei.com \
    --cc=yangjihong1@huawei.com \
    --cc=zhangjinhao2@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

all inboxes | Powered by JetHome®