public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [for-linus][PATCH 0/2] tracing: A few more updates to 6.3
@ 2023-04-06 19:10 Steven Rostedt
  2023-04-06 19:10 ` [for-linus][PATCH 1/2] ftrace: Fix issue that direct->addr not restored in modify_ftrace_direct() Steven Rostedt
  2023-04-06 19:11 ` [for-linus][PATCH 2/2] tracing/synthetic: Make lastcmd_mutex static Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-04-06 19:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton

Some more tracing fixes for 6.3:

- Reset direct->addr back to its original value on error in updating
  the direct trampoline code.

- Make lastcmd_mutex static.


  git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/urgent

Head SHA1: 31c683967174b487939efaf65e41f5ff1404e141


Steven Rostedt (Google) (1):
      tracing/synthetic: Make lastcmd_mutex static

Zheng Yejian (1):
      ftrace: Fix issue that 'direct->addr' not restored in modify_ftrace_direct()

----
 kernel/trace/ftrace.c             | 15 +++++++++------
 kernel/trace/trace_events_synth.c |  2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)

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

* [for-linus][PATCH 1/2] ftrace: Fix issue that direct->addr not restored in modify_ftrace_direct()
  2023-04-06 19:10 [for-linus][PATCH 0/2] tracing: A few more updates to 6.3 Steven Rostedt
@ 2023-04-06 19:10 ` Steven Rostedt
  2023-04-06 19:11 ` [for-linus][PATCH 2/2] tracing/synthetic: Make lastcmd_mutex static Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-04-06 19:10 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton, stable, ast,
	daniel, Zheng Yejian

From: Zheng Yejian <zhengyejian1@huawei.com>

Syzkaller report a WARNING: "WARN_ON(!direct)" in modify_ftrace_direct().

Root cause is 'direct->addr' was changed from 'old_addr' to 'new_addr' but
not restored if error happened on calling ftrace_modify_direct_caller().
Then it can no longer find 'direct' by that 'old_addr'.

To fix it, restore 'direct->addr' to 'old_addr' explicitly in error path.

Link: https://lore.kernel.org/linux-trace-kernel/20230330025223.1046087-1-zhengyejian1@huawei.com

Cc: stable@vger.kernel.org
Cc: <mhiramat@kernel.org>
Cc: <mark.rutland@arm.com>
Cc: <ast@kernel.org>
Cc: <daniel@iogearbox.net>
Fixes: 8a141dd7f706 ("ftrace: Fix modify_ftrace_direct.")
Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 0feea145bb29..c67bcc89a771 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5667,12 +5667,15 @@ int modify_ftrace_direct(unsigned long ip,
 		ret = 0;
 	}
 
-	if (unlikely(ret && new_direct)) {
-		direct->count++;
-		list_del_rcu(&new_direct->next);
-		synchronize_rcu_tasks();
-		kfree(new_direct);
-		ftrace_direct_func_count--;
+	if (ret) {
+		direct->addr = old_addr;
+		if (unlikely(new_direct)) {
+			direct->count++;
+			list_del_rcu(&new_direct->next);
+			synchronize_rcu_tasks();
+			kfree(new_direct);
+			ftrace_direct_func_count--;
+		}
 	}
 
  out_unlock:
-- 
2.39.2

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

* [for-linus][PATCH 2/2] tracing/synthetic: Make lastcmd_mutex static
  2023-04-06 19:10 [for-linus][PATCH 0/2] tracing: A few more updates to 6.3 Steven Rostedt
  2023-04-06 19:10 ` [for-linus][PATCH 1/2] ftrace: Fix issue that direct->addr not restored in modify_ftrace_direct() Steven Rostedt
@ 2023-04-06 19:11 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-04-06 19:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton, Tze-nan Wu,
	Mukesh Ojha, kernel test robot

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The lastcmd_mutex is only used in trace_events_synth.c and should be
static.

Link: https://lore.kernel.org/linux-trace-kernel/202304062033.cRStgOuP-lkp@intel.com/
Link: https://lore.kernel.org/linux-trace-kernel/20230406111033.6e26de93@gandalf.local.home

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Tze-nan Wu <Tze-nan.Wu@mediatek.com>
Fixes: 4ccf11c4e8a8e ("tracing/synthetic: Fix races on freeing last_cmd")
Reviewed-by: Mukesh Ojha <quic_mojha@quicinc.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace_events_synth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index f0ff730125bf..d6a70aff2410 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -44,7 +44,7 @@ enum { ERRORS };
 
 static const char *err_text[] = { ERRORS };
 
-DEFINE_MUTEX(lastcmd_mutex);
+static DEFINE_MUTEX(lastcmd_mutex);
 static char *last_cmd;
 
 static int errpos(const char *str)
-- 
2.39.2

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

end of thread, other threads:[~2023-04-06 19:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-06 19:10 [for-linus][PATCH 0/2] tracing: A few more updates to 6.3 Steven Rostedt
2023-04-06 19:10 ` [for-linus][PATCH 1/2] ftrace: Fix issue that direct->addr not restored in modify_ftrace_direct() Steven Rostedt
2023-04-06 19:11 ` [for-linus][PATCH 2/2] tracing/synthetic: Make lastcmd_mutex static Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox