Skip to content

Commit 59158ec

Browse files
mhiramatrostedt
authored andcommitted
tracing/kprobes: Check the probe on unloaded module correctly
Current kprobe event doesn't checks correctly whether the given event is on unloaded module or not. It just checks the event has ":" in the name. That is not enough because if we define a probe on non-exist symbol on loaded module, it allows to define that (with warning message) To ensure it correctly, this searches the module name on loaded module list and only if there is not, it allows to define it. (this event will be available when the target module is loaded) Link: http://lkml.kernel.org/r/153547309528.26502.8300278470528281328.stgit@devbox Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent f3f5893 commit 59158ec

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

kernel/trace/trace_kprobe.c

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,23 @@ static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk,
6262
return strncmp(mod->name, name, len) == 0 && name[len] == ':';
6363
}
6464

65-
static nokprobe_inline bool trace_kprobe_is_on_module(struct trace_kprobe *tk)
65+
static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)
6666
{
67-
return !!strchr(trace_kprobe_symbol(tk), ':');
67+
char *p;
68+
bool ret;
69+
70+
if (!tk->symbol)
71+
return false;
72+
p = strchr(tk->symbol, ':');
73+
if (!p)
74+
return true;
75+
*p = '\0';
76+
mutex_lock(&module_mutex);
77+
ret = !!find_module(tk->symbol);
78+
mutex_unlock(&module_mutex);
79+
*p = ':';
80+
81+
return ret;
6882
}
6983

7084
static nokprobe_inline unsigned long trace_kprobe_nhit(struct trace_kprobe *tk)
@@ -374,19 +388,13 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)
374388
else
375389
ret = register_kprobe(&tk->rp.kp);
376390

377-
if (ret == 0)
391+
if (ret == 0) {
378392
tk->tp.flags |= TP_FLAG_REGISTERED;
379-
else {
380-
if (ret == -ENOENT && trace_kprobe_is_on_module(tk)) {
381-
pr_warn("This probe might be able to register after target module is loaded. Continue.\n");
382-
ret = 0;
383-
} else if (ret == -EILSEQ) {
384-
pr_warn("Probing address(0x%p) is not an instruction boundary.\n",
385-
tk->rp.kp.addr);
386-
ret = -EINVAL;
387-
}
393+
} else if (ret == -EILSEQ) {
394+
pr_warn("Probing address(0x%p) is not an instruction boundary.\n",
395+
tk->rp.kp.addr);
396+
ret = -EINVAL;
388397
}
389-
390398
return ret;
391399
}
392400

@@ -449,6 +457,11 @@ static int register_trace_kprobe(struct trace_kprobe *tk)
449457

450458
/* Register k*probe */
451459
ret = __register_trace_kprobe(tk);
460+
if (ret == -ENOENT && !trace_kprobe_module_exist(tk)) {
461+
pr_warn("This probe might be able to register after target module is loaded. Continue.\n");
462+
ret = 0;
463+
}
464+
452465
if (ret < 0)
453466
unregister_kprobe_event(tk);
454467
else

0 commit comments

Comments
 (0)