mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Zanussi <tom.zanussi@linux.intel.com>
To: rostedt@goodmis.org
Cc: masami.hiramatsu.pt@hitachi.com, linux-kernel@vger.kernel.org,
	Tom Zanussi <tom.zanussi@linux.intel.com>
Subject: [PATCH v4 11/11] tracing: change event_trigger_open to verify i_private != NULL
Date: Mon, 29 Jul 2013 11:41:07 -0500	[thread overview]
Message-ID: <167fe38d53bbfdfb40ffe9bb2f7d122c08cddad5.1375111640.git.tom.zanussi@linux.intel.com> (raw)
In-Reply-To: <cover.1375111640.git.tom.zanussi@linux.intel.com>
In-Reply-To: <cover.1375111640.git.tom.zanussi@linux.intel.com>

Similar to the other fixes for the same thing elsewhere by Oleg
Nesterov...

event_trigger_regex_open() is racy, ftrace_event_file can be already
freed by rmdir or trace_remove_event_call().

Change event_trigger_open() to read and verify "file = i_private"
under event_mutex.

This also moves event_file_data() into trace.h so it can be used
outside of trace_events.c.

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
 kernel/trace/trace.h                | 4 ++++
 kernel/trace/trace_events.c         | 5 -----
 kernel/trace/trace_events_trigger.c | 7 ++++++-
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index c56a773..a6ef810 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1023,6 +1023,10 @@ extern int event_trace_del_tracer(struct trace_array *tr);
 extern struct ftrace_event_file *find_event_file(struct trace_array *tr,
 						 const char *system,
 						 const char *event);
+static inline void *event_file_data(struct file *filp)
+{
+	return ACCESS_ONCE(file_inode(filp)->i_private);
+}
 
 extern struct mutex event_mutex;
 extern struct list_head ftrace_events;
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 6b4cb04..a444f65 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -427,11 +427,6 @@ static void remove_subsystem(struct ftrace_subsystem_dir *dir)
 	}
 }
 
-static void *event_file_data(struct file *filp)
-{
-	return ACCESS_ONCE(file_inode(filp)->i_private);
-}
-
 static void remove_event_file_dir(struct ftrace_event_file *file)
 {
 	struct dentry *dir = file->dir;
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index 54112be..011bdfb 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -133,7 +133,12 @@ static int event_trigger_regex_open(struct inode *inode, struct file *file)
 
 	mutex_lock(&event_mutex);
 
-	iter->file = inode->i_private;
+	iter->file = event_file_data(file);
+	if (!iter->file) {
+		kfree(iter);
+		mutex_unlock(&event_mutex);
+		return -ENODEV;
+	}
 
 	if (file->f_mode & FMODE_READ) {
 		ret = seq_open(file, &event_triggers_seq_ops);
-- 
1.7.11.4


  parent reply	other threads:[~2013-07-29 16:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-29 16:40 [PATCH v4 00/11] tracing: trace event triggers Tom Zanussi
2013-07-29 16:40 ` [PATCH v4 01/11] tracing: Add support for SOFT_DISABLE to syscall events Tom Zanussi
2013-08-05 11:42   ` Masami Hiramatsu
2013-07-29 16:40 ` [PATCH v4 02/11] tracing: add basic event trigger framework Tom Zanussi
2013-08-08  8:30   ` Masami Hiramatsu
2013-08-22 19:54     ` Tom Zanussi
2013-07-29 16:40 ` [PATCH v4 03/11] tracing: add 'traceon' and 'traceoff' event trigger commands Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 04/11] tracing: add 'snapshot' event trigger command Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 05/11] tracing: add 'stacktrace' " Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 06/11] tracing: add 'enable_event' and 'disable_event' event trigger commands Tom Zanussi
2013-08-08  5:54   ` Masami Hiramatsu
2013-07-29 16:41 ` [PATCH v4 07/11] tracing: add and use generic set_trigger_filter() implementation Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 08/11] tracing: update event filters for multibuffer Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 09/11] tracing: add documentation for trace event triggers Tom Zanussi
2013-07-29 16:41 ` [PATCH v4 10/11] tracing: make register/unregister_ftrace_command __init Tom Zanussi
2013-07-29 16:41 ` Tom Zanussi [this message]
2013-08-08  2:02 ` [PATCH v4 00/11] tracing: trace event triggers Masami Hiramatsu
2013-08-08  2:15   ` Steven Rostedt
2013-08-22 19:48   ` Tom Zanussi
2013-08-22 23:26     ` Tom Zanussi

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=167fe38d53bbfdfb40ffe9bb2f7d122c08cddad5.1375111640.git.tom.zanussi@linux.intel.com \
    --to=tom.zanussi@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=rostedt@goodmis.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®