Skip to content

Commit cf0a624

Browse files
tzstoyanovmhiramat
authored andcommitted
kernel/trace: Fix cleanup logic of enable_trace_eprobe
The enable_trace_eprobe() function enables all event probes, attached to given trace probe. If an error occurs in enabling one of the event probes, all others should be roll backed. There is a bug in that roll back logic - instead of all event probes, only the failed one is disabled. Link: https://lore.kernel.org/all/20230703042853.1427493-1-tz.stoyanov@gmail.com/ Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Fixes: 7491e2c ("tracing: Add a probe that attaches to trace events") Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
1 parent 5f81018 commit cf0a624

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

kernel/trace/trace_eprobe.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,
675675
struct trace_eprobe *ep;
676676
bool enabled;
677677
int ret = 0;
678+
int cnt = 0;
678679

679680
tp = trace_probe_primary_from_call(call);
680681
if (WARN_ON_ONCE(!tp))
@@ -698,12 +699,25 @@ static int enable_trace_eprobe(struct trace_event_call *call,
698699
if (ret)
699700
break;
700701
enabled = true;
702+
cnt++;
701703
}
702704

703705
if (ret) {
704706
/* Failed to enable one of them. Roll back all */
705-
if (enabled)
706-
disable_eprobe(ep, file->tr);
707+
if (enabled) {
708+
/*
709+
* It's a bug if one failed for something other than memory
710+
* not being available but another eprobe succeeded.
711+
*/
712+
WARN_ON_ONCE(ret != -ENOMEM);
713+
714+
list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
715+
ep = container_of(pos, struct trace_eprobe, tp);
716+
disable_eprobe(ep, file->tr);
717+
if (!--cnt)
718+
break;
719+
}
720+
}
707721
if (file)
708722
trace_probe_remove_file(tp, file);
709723
else

0 commit comments

Comments
 (0)