linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix the race on &event->ftrace_ops between perf and ftrace
@ 2021-03-17 10:25 Li Huafei
  2021-03-17 10:25 ` [PATCH 1/2] ftrace: Update ftrace_ops->next pointer with rcu_assign_pointer() Li Huafei
  2021-03-17 10:25 ` [PATCH 2/2] perf, ftrace: Fix use-after-free in __ftrace_ops_list_func() Li Huafei
  0 siblings, 2 replies; 6+ messages in thread
From: Li Huafei @ 2021-03-17 10:25 UTC (permalink / raw)
  To: rostedt, mingo, jolsa
  Cc: linux-kernel, yangjihong1, xukuohai, zhangjinhao2, lihuafei1

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-25  1:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 10:25 [PATCH 0/2] Fix the race on &event->ftrace_ops between perf and ftrace Li Huafei
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).