tracing/uprobes: Fix the usage of uprobe_buffer_enable() in probe_event_enable()
authorOleg Nesterov <oleg@redhat.com>
Fri, 27 Jun 2014 17:01:46 +0000 (19:01 +0200)
committerSteven Rostedt <rostedt@goodmis.org>
Mon, 30 Jun 2014 17:22:33 +0000 (13:22 -0400)
The usage of uprobe_buffer_enable() added by dcad1a20 is very wrong,

1. uprobe_buffer_enable() and uprobe_buffer_disable() are not balanced,
   _enable() should be called only if !enabled.

2. If uprobe_buffer_enable() fails probe_event_enable() should clear
   tp.flags and free event_file_link.

3. If uprobe_register() fails it should do uprobe_buffer_disable().

Link: http://lkml.kernel.org/p/20140627170146.GA18332@redhat.com
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Fixes: dcad1a204f72 "tracing/uprobes: Fetch args before reserving a ring buffer"
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/trace_uprobe.c

index c4cf0abd60bab9312cc62f349cc94b4d432538b6..3c9b97e6b1f41b9fd3f0b45c1d073029013138fa 100644 (file)
@@ -911,26 +911,33 @@ probe_event_enable(struct trace_uprobe *tu, struct ftrace_event_file *file,
                tu->tp.flags |= TP_FLAG_PROFILE;
        }
 
-       ret = uprobe_buffer_enable();
-       if (ret < 0)
-               return ret;
-
        WARN_ON(!uprobe_filter_is_empty(&tu->filter));
 
        if (enabled)
                return 0;
 
+       ret = uprobe_buffer_enable();
+       if (ret)
+               goto err_flags;
+
        tu->consumer.filter = filter;
        ret = uprobe_register(tu->inode, tu->offset, &tu->consumer);
-       if (ret) {
-               if (file) {
-                       list_del(&link->list);
-                       kfree(link);
-                       tu->tp.flags &= ~TP_FLAG_TRACE;
-               } else
-                       tu->tp.flags &= ~TP_FLAG_PROFILE;
-       }
+       if (ret)
+               goto err_buffer;
 
+       return 0;
+
+ err_buffer:
+       uprobe_buffer_disable();
+
+ err_flags:
+       if (file) {
+               list_del(&link->list);
+               kfree(link);
+               tu->tp.flags &= ~TP_FLAG_TRACE;
+       } else {
+               tu->tp.flags &= ~TP_FLAG_PROFILE;
+       }
        return ret;
 }