]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tracing/fprobe: Roll back on enable_trace_fprobe() failure
authorRaushan Patel <raushan.jhon@gmail.com>
Fri, 24 Jul 2026 06:42:08 +0000 (12:12 +0530)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Tue, 28 Jul 2026 15:27:52 +0000 (00:27 +0900)
enable_trace_fprobe() sets the file link or the TP_FLAG_PROFILE flag and
then registers each trace_fprobe in the probe list. If
__register_trace_fprobe() fails partway through, the function returns
immediately without unregistering the trace_fprobes it already registered
or undoing the file link / flag it set, leaving the event half-enabled and
leaking the registered fprobe(s).

enable_trace_kprobe() already handles this with a rollback path. Do the
same for fprobe: on failure, unregister all probes and clear the file link
or profile flag.

Link: https://lore.kernel.org/all/20260724064208.480030-1-raushan.jhon@gmail.com/
Fixes: 334e5519c375 ("tracing/probes: Add fprobe events for tracing function entry and exit.")
Cc: stable@vger.kernel.org
Signed-off-by: Raushan Patel <raushan.jhon@gmail.com>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
kernel/trace/trace_fprobe.c

index 9f5f08c0e7c2f76983ad341237a8a8c207a19ccd..3120403a5b6044b5f5682fa8e6ba91d6644d4669 100644 (file)
@@ -1481,11 +1481,21 @@ static int enable_trace_fprobe(struct trace_event_call *call,
                list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list) {
                        ret = __register_trace_fprobe(tf);
                        if (ret < 0)
-                               return ret;
+                               goto err;
                }
        }
 
        return 0;
+
+err:
+       /* Failed to enable one of them. Roll back all */
+       list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list)
+               __unregister_trace_fprobe(tf);
+       if (file)
+               trace_probe_remove_file(tp, file);
+       else
+               trace_probe_clear_flag(tp, TP_FLAG_PROFILE);
+       return ret;
 }
 
 /*