On Fri, 2013-07-19 at 17:51 +0200, Oleg Nesterov wrote: > trace_array_get() scans the global ftrace_trace_arrays list > to ensure that "this_tr" was not removed by instance_delete(). > > This looks a bit confusing, we can simply use list_empty() with > the same result. list_empty() == F can not be false positive, > new_instance_create() does everything under the same lock and > tracer_alloc_buffers() which plays with global_trace is __init. > > Signed-off-by: Oleg Nesterov <[email protected]> > --- > kernel/trace/trace.c | 12 ++++-------- > 1 files changed, 4 insertions(+), 8 deletions(-) > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index 0cd500b..ee471fb 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -206,16 +206,12 @@ LIST_HEAD(ftrace_trace_arrays); > > int trace_array_get(struct trace_array *this_tr) > { > - struct trace_array *tr; > int ret = -ENODEV; > > mutex_lock(&trace_types_lock); > - list_for_each_entry(tr, &ftrace_trace_arrays, list) { > - if (tr == this_tr) { > - tr->ref++; > - ret = 0; > - break; > - } > + if (!list_empty(&this_tr->list)) {
Because this_tr can be freed outside the lock. Accessing this_tr->list can cause a crash. The point of the search is, if it's on the list, it will not be freed. -- Steve > + this_tr->ref++; > + ret = 0; > } > mutex_unlock(&trace_types_lock); > > @@ -6019,7 +6015,7 @@ static int instance_delete(const char *name) > if (tr->ref) > goto out_unlock; > > - list_del(&tr->list); > + list_del_init(&tr->list); /* trace_array_get() checks list_empty() */ > > event_trace_del_tracer(tr); > debugfs_remove_recursive(tr->dir); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/

