[GIT PULL] tracing: Fixes for v7.2

Steven Rostedt <[email protected]>
Newsgroups org.kernel.vger.linux-kernel
Message-ID <[email protected]>
[
  My ISP *finally* supports DKIM! So hopefully I will not end up in your
  spam folder again.
]

Linus,

tracing fixes for v7.2:

- Fix NULL pointer dereference when matching unloaded module wildcard event

  The set_event can take events for modules that have not been loaded
  yet. This is done by writing '<event>:mod:<module>'.

  If '<event>' is not added, then it means to add all events in <module>.
  This wildcard is represented by a NULL pointer. If one were to try to
  remove the same module item with a named event it would cause a NULL
  pointer dereference when comparing the NULL with the name in strcmp().

  echo ':mod:kvm' > /sys/kernel/tracing/set_event
  echo '!kvm_ack_irq:mod:kvm' >> /sys/kernel/tracing/set_event

  The above will do a strcmp("kvm_ack_irq", NULL) and crash the kernel.

  Test for NULL (wildcard) before doing the strcmp().

- Fix event data field race in loading two modules at the same time

  When a module loads, its trace events get registered. The fields
  of the events are also dynamically created and added to the events
  fields list. It also will call a function that will look at all the
  events for updates that need to be done. If two modules load at the
  same time, the one that scans all events and their fields may read
  the one being added as the scan doesn't take the event_mutex.
  This may cause a data race.

  Have the scan take the event_mutex to prevent the race.

  [
     Note, the scan should only look at the module being loaded.
     I'm working on a patch to fix that for the next merge window.
  ]

Please pull the latest trace-v7.2-rc7 tree, which can be found at:


  git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace-v7.2-rc7

Tag SHA1: ff59d39a1c59ea1eb204d56ec72f30c72059f303
Head SHA1: c3730b8373bb5059d735509b9e6a00d7eb337d7c


Hui Su (1):
      tracing: Fix NULL pointer dereference in module event cache removal

Michael Wu (1):
      tracing: Fix race between update_event_fields and, event_define_fields

----
 kernel/trace/trace_events.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
---------------------------
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index c01b10b99f67..3650d84d4f16 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -945,7 +945,7 @@ static int remove_cache_mod(struct trace_array *tr, const char *mod,
 		if (strcmp(event_mod->module, mod) != 0)
 			continue;
 
-		if (match && strcmp(event_mod->match, match) != 0)
+		if (match && (!event_mod->match || strcmp(event_mod->match, match) != 0))
 			continue;
 
 		if (system &&
@@ -3566,6 +3566,7 @@ void trace_event_update_all(struct trace_eval_map **map, int len)
 	int last_i;
 	int i;
 
+	mutex_lock(&event_mutex);
 	down_write(&trace_event_sem);
 	list_for_each_entry_safe(call, p, &ftrace_events, list) {
 		/* events are usually grouped together with systems */
@@ -3604,6 +3605,7 @@ void trace_event_update_all(struct trace_eval_map **map, int len)
 		cond_resched();
 	}
 	up_write(&trace_event_sem);
+	mutex_unlock(&event_mutex);
 }
 
 static bool event_in_systems(struct trace_event_call *call,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.