Skip to content

Commit a822741

Browse files
Alexander Z Lamrostedt
authored andcommitted
tracing: Protect ftrace_trace_arrays list in trace_events.c
There are multiple places where the ftrace_trace_arrays list is accessed in trace_events.c without the trace_types_lock held. Link: http://lkml.kernel.org/r/1372732674-22726-1-git-send-email-azl@google.com Cc: Vaibhav Nagarnaik <vnagarnaik@google.com> Cc: David Sharp <dhsharp@google.com> Cc: Alexander Z Lam <lambchop468@gmail.com> Cc: stable@vger.kernel.org # 3.10 Signed-off-by: Alexander Z Lam <azl@google.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 2d71619 commit a822741

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static struct tracer *trace_types __read_mostly;
266266
/*
267267
* trace_types_lock is used to protect the trace_types list.
268268
*/
269-
static DEFINE_MUTEX(trace_types_lock);
269+
DEFINE_MUTEX(trace_types_lock);
270270

271271
/*
272272
* serialize the access of the ring buffer

‎kernel/trace/trace.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ enum {
224224

225225
extern struct list_head ftrace_trace_arrays;
226226

227+
extern struct mutex trace_types_lock;
228+
227229
/*
228230
* The global tracer (top) should be the first trace array added,
229231
* but we check the flag anyway.

‎kernel/trace/trace_events.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ static int subsystem_open(struct inode *inode, struct file *filp)
10081008
int ret;
10091009

10101010
/* Make sure the system still exists */
1011+
mutex_lock(&trace_types_lock);
10111012
mutex_lock(&event_mutex);
10121013
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
10131014
list_for_each_entry(dir, &tr->systems, list) {
@@ -1023,6 +1024,7 @@ static int subsystem_open(struct inode *inode, struct file *filp)
10231024
}
10241025
exit_loop:
10251026
mutex_unlock(&event_mutex);
1027+
mutex_unlock(&trace_types_lock);
10261028

10271029
if (!system)
10281030
return -ENODEV;
@@ -1617,18 +1619,21 @@ static void __add_event_to_tracers(struct ftrace_event_call *call,
16171619
int trace_add_event_call(struct ftrace_event_call *call)
16181620
{
16191621
int ret;
1622+
mutex_lock(&trace_types_lock);
16201623
mutex_lock(&event_mutex);
16211624

16221625
ret = __register_event(call, NULL);
16231626
if (ret >= 0)
16241627
__add_event_to_tracers(call, NULL);
16251628

16261629
mutex_unlock(&event_mutex);
1630+
mutex_unlock(&trace_types_lock);
16271631
return ret;
16281632
}
16291633

16301634
/*
1631-
* Must be called under locking both of event_mutex and trace_event_sem.
1635+
* Must be called under locking of trace_types_lock, event_mutex and
1636+
* trace_event_sem.
16321637
*/
16331638
static void __trace_remove_event_call(struct ftrace_event_call *call)
16341639
{
@@ -1640,11 +1645,13 @@ static void __trace_remove_event_call(struct ftrace_event_call *call)
16401645
/* Remove an event_call */
16411646
void trace_remove_event_call(struct ftrace_event_call *call)
16421647
{
1648+
mutex_lock(&trace_types_lock);
16431649
mutex_lock(&event_mutex);
16441650
down_write(&trace_event_sem);
16451651
__trace_remove_event_call(call);
16461652
up_write(&trace_event_sem);
16471653
mutex_unlock(&event_mutex);
1654+
mutex_unlock(&trace_types_lock);
16481655
}
16491656

16501657
#define for_each_event(event, start, end) \
@@ -1788,6 +1795,7 @@ static int trace_module_notify(struct notifier_block *self,
17881795
{
17891796
struct module *mod = data;
17901797

1798+
mutex_lock(&trace_types_lock);
17911799
mutex_lock(&event_mutex);
17921800
switch (val) {
17931801
case MODULE_STATE_COMING:
@@ -1798,6 +1806,7 @@ static int trace_module_notify(struct notifier_block *self,
17981806
break;
17991807
}
18001808
mutex_unlock(&event_mutex);
1809+
mutex_unlock(&trace_types_lock);
18011810

18021811
return 0;
18031812
}

0 commit comments

Comments
 (0)