public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Steven Rostedt <srostedt@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
	rostedt@goodmis.org, lizf@cn.fujitsu.com, srostedt@redhat.com,
	tglx@linutronix.de
Subject: [tip:tracing/core] tracing: reset ring buffer when removing modules with events
Date: Thu, 7 May 2009 09:19:37 GMT	[thread overview]
Message-ID: <tip-9456f0fa6d3cb944d3b9fc31c9a244e0362c26ea@git.kernel.org> (raw)
In-Reply-To: <49FEAFD0.30106@cn.fujitsu.com>

Commit-ID:  9456f0fa6d3cb944d3b9fc31c9a244e0362c26ea
Gitweb:     http://git.kernel.org/tip/9456f0fa6d3cb944d3b9fc31c9a244e0362c26ea
Author:     Steven Rostedt <srostedt@redhat.com>
AuthorDate: Wed, 6 May 2009 21:54:09 -0400
Committer:  Steven Rostedt <rostedt@goodmis.org>
CommitDate: Wed, 6 May 2009 23:11:41 -0400

tracing: reset ring buffer when removing modules with events

Li Zefan found that there's a race using the event ids of events and
modules. When a module is loaded, an event id is incremented. We only
have 16 bits for event ids (65536) and there is a possible (but highly
unlikely) race that we could load and unload a module that registers
events so many times that the event id counter overflows.

When it overflows, it then restarts and goes looking for available
ids. An id is available if it was added by a module and released.

The race is if you have one module add an id, and then is removed.
Another module loaded can use that same event id. But if the old module
still had events in the ring buffer, the new module's call back would
get bogus data.  At best (and most likely) the output would just be
garbage. But if the module for some reason used pointers (not recommended)
then this could potentially crash.

The safest thing to do is just reset the ring buffer if a module that
registered events is removed.

[ Impact: prevent unpredictable results of event id overflows ]

Reported-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <49FEAFD0.30106@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>


---
 kernel/trace/trace.c        |   10 ++++++++++
 kernel/trace/trace.h        |    2 ++
 kernel/trace/trace_events.c |    9 +++++++++
 3 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 4164a34..dd40d23 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -639,6 +639,16 @@ void tracing_reset_online_cpus(struct trace_array *tr)
 		tracing_reset(tr, cpu);
 }
 
+void tracing_reset_current(int cpu)
+{
+	tracing_reset(&global_trace, cpu);
+}
+
+void tracing_reset_current_online_cpus(void)
+{
+	tracing_reset_online_cpus(&global_trace);
+}
+
 #define SAVED_CMDLINES 128
 #define NO_CMDLINE_MAP UINT_MAX
 static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 777c6c3..ba25793 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -409,6 +409,8 @@ int tracing_is_enabled(void);
 void trace_wake_up(void);
 void tracing_reset(struct trace_array *tr, int cpu);
 void tracing_reset_online_cpus(struct trace_array *tr);
+void tracing_reset_current(int cpu);
+void tracing_reset_current_online_cpus(void);
 int tracing_open_generic(struct inode *inode, struct file *filp);
 struct dentry *trace_create_file(const char *name,
 				 mode_t mode,
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 8d579ff..6d2c842 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -932,9 +932,11 @@ static void trace_module_remove_events(struct module *mod)
 {
 	struct ftrace_module_file_ops *file_ops;
 	struct ftrace_event_call *call, *p;
+	bool found = false;
 
 	list_for_each_entry_safe(call, p, &ftrace_events, list) {
 		if (call->mod == mod) {
+			found = true;
 			if (call->enabled) {
 				call->enabled = 0;
 				call->unregfunc();
@@ -957,6 +959,13 @@ static void trace_module_remove_events(struct module *mod)
 		list_del(&file_ops->list);
 		kfree(file_ops);
 	}
+
+	/*
+	 * It is safest to reset the ring buffer if the module being unloaded
+	 * registered any events.
+	 */
+	if (found)
+		tracing_reset_current_online_cpus();
 }
 
 static int trace_module_notify(struct notifier_block *self,

  parent reply	other threads:[~2009-05-07  9:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-24  4:30 [PATCH 0/6] [GIT PULL] x86,ring_buffer,tracing: updates for tip Steven Rostedt
2009-04-24  4:30 ` [PATCH 1/6] tracing/wakeup: move access to wakeup_cpu into spinlock Steven Rostedt
2009-04-24  4:30 ` [PATCH 2/6] tracing: increase size of number of possible events Steven Rostedt
2009-04-24  6:02   ` Li Zefan
2009-04-24  7:09     ` Ingo Molnar
2009-04-24 12:29       ` Steven Rostedt
2009-04-24 12:27     ` Steven Rostedt
2009-04-24 14:04     ` Steven Rostedt
2009-04-24 14:05       ` Steven Rostedt
2009-04-26  6:53         ` Li Zefan
2009-04-26 13:44           ` Steven Rostedt
2009-05-04  9:05             ` Li Zefan
2009-05-04 14:12               ` Steven Rostedt
2009-05-05  1:32                 ` Li Zefan
2009-05-07  9:19               ` tip-bot for Steven Rostedt [this message]
2009-04-24  7:12   ` Ingo Molnar
2009-04-24 12:30     ` Steven Rostedt
2009-04-24  4:30 ` [PATCH 3/6] tracing: add size checks for exported ftrace internal structures Steven Rostedt
2009-04-24  4:30 ` [PATCH 4/6] x86: use native register access for native tlb flushing Steven Rostedt
2009-04-24  4:30 ` [PATCH 5/6] tracing: fix cut and paste macro error Steven Rostedt
2009-04-24  4:30 ` [PATCH 6/6] ring_buffer: compressed event header 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=tip-9456f0fa6d3cb944d3b9fc31c9a244e0362c26ea@git.kernel.org \
    --to=srostedt@redhat.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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