mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: LKML <linux-kernel@vger.kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Naresh Kamboju <naresh.kamboju@linaro.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Subject: [for-next][PATCH] function_graph: Add READ_ONCE() when accessing fgraph_array[]
Date: Sat, 15 Jun 2024 09:10:01 -0400	[thread overview]
Message-ID: <20240615091001.04a33174@rorschach.local.home> (raw)


  git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
ftrace/for-next

Head SHA1: 63a8dfb889112ab4a065aa60a9a1b590b410d055


Steven Rostedt (Google) (1):
      function_graph: Add READ_ONCE() when accessing fgraph_array[]

----
 kernel/trace/fgraph.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---------------------------
commit 63a8dfb889112ab4a065aa60a9a1b590b410d055
Author: Steven Rostedt (Google) <rostedt@goodmis.org>
Date:   Thu Jun 13 09:52:23 2024 -0400

    function_graph: Add READ_ONCE() when accessing fgraph_array[]
    
    In function_graph_enter() there's a loop that looks at fgraph_array[]
    elements which are fgraph_ops. It first tests if it is a fgraph_stub op,
    and if so skips it, as that's just there as a place holder. Then it checks
    the fgraph_ops filters to see if the ops wants to trace the current
    function.
    
    But if the compiler reloads the fgraph_array[] after the check against
    fgraph_stub, it could race with the fgraph_array[] being updated with the
    fgraph_stub. That would cause the stub to be processed. But the stub has a
    null "func_hash" field which will cause a NULL pointer dereference.
    
    Add a READ_ONCE() so that the gops that is compared against the
    fgraph_stub is also the gops that is processed later.
    
    Link: https://lore.kernel.org/all/CA+G9fYsSVJQZH=nM=1cjTc94PgSnMF9y65BnOv6XSoCG_b6wmw@mail.gmail.com/
    Link: https://lore.kernel.org/linux-trace-kernel/20240613095223.1f07e3a4@rorschach.local.home
    
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Fixes: cc60ee813b503 ("function_graph: Use static_call and branch to optimize entry function")
    Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index 8317d1a7f43a..fc205ad167a9 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -641,7 +641,7 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 	{
 		for_each_set_bit(i, &fgraph_array_bitmask,
 					 sizeof(fgraph_array_bitmask) * BITS_PER_BYTE) {
-			struct fgraph_ops *gops = fgraph_array[i];
+			struct fgraph_ops *gops = READ_ONCE(fgraph_array[i]);
 			int save_curr_ret_stack;
 
 			if (gops == &fgraph_stub)

                 reply	other threads:[~2024-06-15 13:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240615091001.04a33174@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=naresh.kamboju@linaro.org \
    /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®