mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	stable@vger.kernel.org, Zheng Yejian <zhengyejian1@huawei.com>,
	Linux Kernel Functional Testing <lkft@linaro.org>,
	Naresh Kamboju <naresh.kamboju@linaro.org>
Subject: [for-linus][PATCH 05/15] tracing: Have tracing_max_latency inc the trace array ref count
Date: Fri, 08 Sep 2023 23:16:20 -0400	[thread overview]
Message-ID: <20230909032349.020450746@goodmis.org> (raw)
In-Reply-To: <20230909031615.047488015@goodmis.org>

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

The tracing_max_latency file points to the trace_array max_latency field.
For an instance, if the file is opened and the instance is deleted,
reading or writing to the file will cause a use after free.

Up the ref count of the trace_array when tracing_max_latency is opened.

Link: https://lkml.kernel.org/r/20230907024803.666889383@goodmis.org
Link: https://lore.kernel.org/all/1cb3aee2-19af-c472-e265-05176fe9bd84@huawei.com/

Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Zheng Yejian <zhengyejian1@huawei.com>
Fixes: 8530dec63e7b4 ("tracing: Add tracing_check_open_get_tr()")
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 0827037ee3b8..c8b8b4c6feaf 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1772,7 +1772,7 @@ static void trace_create_maxlat_file(struct trace_array *tr,
 	init_irq_work(&tr->fsnotify_irqwork, latency_fsnotify_workfn_irq);
 	tr->d_max_latency = trace_create_file("tracing_max_latency",
 					      TRACE_MODE_WRITE,
-					      d_tracer, &tr->max_latency,
+					      d_tracer, tr,
 					      &tracing_max_lat_fops);
 }
 
@@ -1805,7 +1805,7 @@ void latency_fsnotify(struct trace_array *tr)
 
 #define trace_create_maxlat_file(tr, d_tracer)				\
 	trace_create_file("tracing_max_latency", TRACE_MODE_WRITE,	\
-			  d_tracer, &tr->max_latency, &tracing_max_lat_fops)
+			  d_tracer, tr, &tracing_max_lat_fops)
 
 #endif
 
@@ -6717,14 +6717,18 @@ static ssize_t
 tracing_max_lat_read(struct file *filp, char __user *ubuf,
 		     size_t cnt, loff_t *ppos)
 {
-	return tracing_nsecs_read(filp->private_data, ubuf, cnt, ppos);
+	struct trace_array *tr = filp->private_data;
+
+	return tracing_nsecs_read(&tr->max_latency, ubuf, cnt, ppos);
 }
 
 static ssize_t
 tracing_max_lat_write(struct file *filp, const char __user *ubuf,
 		      size_t cnt, loff_t *ppos)
 {
-	return tracing_nsecs_write(filp->private_data, ubuf, cnt, ppos);
+	struct trace_array *tr = filp->private_data;
+
+	return tracing_nsecs_write(&tr->max_latency, ubuf, cnt, ppos);
 }
 
 #endif
@@ -7778,10 +7782,11 @@ static const struct file_operations tracing_thresh_fops = {
 
 #ifdef CONFIG_TRACER_MAX_TRACE
 static const struct file_operations tracing_max_lat_fops = {
-	.open		= tracing_open_generic,
+	.open		= tracing_open_generic_tr,
 	.read		= tracing_max_lat_read,
 	.write		= tracing_max_lat_write,
 	.llseek		= generic_file_llseek,
+	.release	= tracing_release_generic_tr,
 };
 #endif
 
-- 
2.40.1

  parent reply	other threads:[~2023-09-09  3:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-09  3:16 [for-linus][PATCH 00/15] tracing: Fixes for 6.6 Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 01/15] tracefs: Add missing lockdown check to tracefs_create_dir() Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 02/15] tracefs/eventfs: Add missing lockdown checks Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 03/15] tracefs/eventfs: Use dput to free the toplevel events directory Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 04/15] tracing: Increase trace array ref count on enable and filter files Steven Rostedt
2023-09-09  3:16 ` Steven Rostedt [this message]
2023-09-09  3:16 ` [for-linus][PATCH 06/15] tracing: Have current_trace inc the trace array ref count Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 07/15] tracing: Have option files " Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 08/15] tracing: Have event inject " Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 09/15] ring-buffer: Avoid softlockup in ring_buffer_resize() Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 10/15] tracefs/eventfs: Free top level files on removal Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 11/15] ring-buffer: Do not attempt to read past "commit" Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 12/15] tracing: Use the new eventfs descriptor for print trigger Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 13/15] tracing: Remove unused trace_event_file dir field Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 14/15] selftests/ftrace: Fix dependencies for some of the synthetic event tests Steven Rostedt
2023-09-09  3:16 ` [for-linus][PATCH 15/15] tracing/synthetic: Fix order of struct trace_dynamic_info 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=20230909032349.020450746@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkft@linaro.org \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=naresh.kamboju@linaro.org \
    --cc=stable@vger.kernel.org \
    --cc=zhengyejian1@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®