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 1/2] ftrace: Update ftrace_ops->next pointer with rcu_assign_pointer()
Date: Wed, 17 Mar 2021 18:25:28 +0800	[thread overview]
Message-ID: <20210317102529.226734-2-lihuafei1@huawei.com> (raw)
In-Reply-To: <20210317102529.226734-1-lihuafei1@huawei.com>

The unregistered ftrace_ops may be freed by the caller, so we should use
rcu_assign_pointer() in remove_ftrace_ops() to remove the ftrace_ops,
which ensures that no more users will reference the ftrace_ops after
synchronize_rcu() is called.

Signed-off-by: Li Huafei <lihuafei1@huawei.com>
---
 kernel/trace/ftrace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 4d8e35575549..2e315a145d20 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -282,7 +282,7 @@ static int remove_ftrace_ops(struct ftrace_ops __rcu **list,
 			lockdep_is_held(&ftrace_lock)) == ops &&
 	    rcu_dereference_protected(ops->next,
 			lockdep_is_held(&ftrace_lock)) == &ftrace_list_end) {
-		*list = &ftrace_list_end;
+		rcu_assign_pointer(*list, &ftrace_list_end);
 		return 0;
 	}
 
@@ -293,7 +293,7 @@ static int remove_ftrace_ops(struct ftrace_ops __rcu **list,
 	if (*p != ops)
 		return -1;
 
-	*p = (*p)->next;
+	rcu_assign_pointer(*p, (*p)->next);
 	return 0;
 }
 
-- 
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 [PATCH 0/2] Fix the race on &event->ftrace_ops between perf and ftrace Li Huafei
2021-03-17 10:25 ` Li Huafei [this message]
2021-03-25  1:20   ` [PATCH 1/2] ftrace: Update ftrace_ops->next pointer with rcu_assign_pointer() 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-2-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®