Skip to content

Commit ac91052

Browse files
committed
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
1 parent 0a8bb68 commit ac91052

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
@@ -920,13 +920,8 @@ static void __find_tracepoint_module_cb(struct tracepoint *tp, struct module *mo
920920

921921
if (!data->tpoint && !strcmp(data->tp_name, tp->name)) {
922922
data->tpoint = tp;
923-
if (!data->mod) {
923+
if (!data->mod)
924924
data->mod = mod;
925-
if (!try_module_get(data->mod)) {
926-
data->tpoint = NULL;
927-
data->mod = NULL;
928-
}
929-
}
930925
}
931926
}
932927

@@ -938,13 +933,7 @@ static void __find_tracepoint_cb(struct tracepoint *tp, void *priv)
938933
data->tpoint = tp;
939934
}
940935

941-
/*
942-
* Find a tracepoint from kernel and module. If the tracepoint is in a module,
943-
* this increments the module refcount to prevent unloading until the
944-
* trace_fprobe is registered to the list. After registering the trace_fprobe
945-
* on the trace_fprobe list, the module refcount is decremented because
946-
* tracepoint_probe_module_cb will handle it.
947-
*/
936+
/* Find a tracepoint from kernel and module. */
948937
static struct tracepoint *find_tracepoint(const char *tp_name,
949938
struct module **tp_mod)
950939
{
@@ -973,6 +962,7 @@ static void reenable_trace_fprobe(struct trace_fprobe *tf)
973962
}
974963
}
975964

965+
/* Find a tracepoint from specified module. */
976966
static struct tracepoint *find_tracepoint_in_module(struct module *mod,
977967
const char *tp_name)
978968
{
@@ -1179,6 +1169,11 @@ static int trace_fprobe_create_internal(int argc, const char *argv[],
11791169
if (is_tracepoint) {
11801170
ctx->flags |= TPARG_FL_TPOINT;
11811171
tpoint = find_tracepoint(symbol, &tp_mod);
1172+
/* lock module until register this tprobe. */
1173+
if (tp_mod && !try_module_get(tp_mod)) {
1174+
tpoint = NULL;
1175+
tp_mod = NULL;
1176+
}
11821177
if (tpoint) {
11831178
ctx->funcname = kallsyms_lookup(
11841179
(unsigned long)tpoint->probestub,

0 commit comments

Comments
 (0)