Skip to content

Commit 3a7e58a

Browse files
tracing: tprobe-events: Fix leakage of module refcount
JIRA: https://issues.redhat.com/browse/RHEL-86682 Conflicts: Context change from missing commit 8275637 ("tracing: Adopt __free() and guard() for trace_fprobe.c") commit ac91052 Author: Masami Hiramatsu (Google) <mhiramat@kernel.org> Date: Thu Mar 13 10:00:10 2025 +0900 tracing: tprobe-events: Fix leakage of module refcount When enabling the tracepoint at loading module, the target module refcount is incremented by find_tracepoint_in_module(). But it is unnecessary because the module is not unloaded while processing module loading callbacks. Moreover, the refcount is not decremented in that function. To be clear the module refcount handling, move the try_module_get() callsite to trace_fprobe_create_internal(), where it is actually required. Link: https://lore.kernel.org/all/174182761071.83274.18334217580449925882.stgit@devnote2/ Fixes: 57a7e6d ("tracing/fprobe: Support raw tracepoints on future loaded modules") Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Cc: stable@vger.kernel.org Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
1 parent 824c833 commit 3a7e58a

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

kernel/trace/trace_fprobe.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -889,13 +889,8 @@ static void __find_tracepoint_module_cb(struct tracepoint *tp, struct module *mo
889889

890890
if (!data->tpoint && !strcmp(data->tp_name, tp->name)) {
891891
data->tpoint = tp;
892-
if (!data->mod) {
892+
if (!data->mod)
893893
data->mod = mod;
894-
if (!try_module_get(data->mod)) {
895-
data->tpoint = NULL;
896-
data->mod = NULL;
897-
}
898-
}
899894
}
900895
}
901896

@@ -907,13 +902,7 @@ static void __find_tracepoint_cb(struct tracepoint *tp, void *priv)
907902
data->tpoint = tp;
908903
}
909904

910-
/*
911-
* Find a tracepoint from kernel and module. If the tracepoint is in a module,
912-
* this increments the module refcount to prevent unloading until the
913-
* trace_fprobe is registered to the list. After registering the trace_fprobe
914-
* on the trace_fprobe list, the module refcount is decremented because
915-
* tracepoint_probe_module_cb will handle it.
916-
*/
905+
/* Find a tracepoint from kernel and module. */
917906
static struct tracepoint *find_tracepoint(const char *tp_name,
918907
struct module **tp_mod)
919908
{
@@ -942,6 +931,7 @@ static void reenable_trace_fprobe(struct trace_fprobe *tf)
942931
}
943932
}
944933

934+
/* Find a tracepoint from specified module. */
945935
static struct tracepoint *find_tracepoint_in_module(struct module *mod,
946936
const char *tp_name)
947937
{
@@ -1177,6 +1167,11 @@ static int __trace_fprobe_create(int argc, const char *argv[])
11771167
if (is_tracepoint) {
11781168
ctx.flags |= TPARG_FL_TPOINT;
11791169
tpoint = find_tracepoint(symbol, &tp_mod);
1170+
/* lock module until register this tprobe. */
1171+
if (tp_mod && !try_module_get(tp_mod)) {
1172+
tpoint = NULL;
1173+
tp_mod = NULL;
1174+
}
11801175
if (tpoint) {
11811176
ctx.funcname = kallsyms_lookup(
11821177
(unsigned long)tpoint->probestub,

0 commit comments

Comments
 (0)