Skip to content

Commit c7411a1

Browse files
mhiramatrostedt
authored andcommitted
tracing/kprobe: Check whether the non-suffixed symbol is notrace
Check whether the non-suffixed symbol is notrace, since suffixed symbols are generated by the compilers for optimization. Based on these suffixed symbols, notrace check might not work because some of them are just a partial code of the original function. (e.g. cold-cache (unlikely) code is separated from original function as FUNCTION.cold.XX) For example, without this fix, # echo p device_add.cold.67 > /sys/kernel/debug/tracing/kprobe_events sh: write error: Invalid argument # cat /sys/kernel/debug/tracing/error_log [ 135.491035] trace_kprobe: error: Failed to register probe event Command: p device_add.cold.67 ^ # dmesg | tail -n 1 [ 135.488599] trace_kprobe: Could not probe notrace function device_add.cold.67 With this, # echo p device_add.cold.66 > /sys/kernel/debug/tracing/kprobe_events # cat /sys/kernel/debug/kprobes/list ffffffff81599de9 k device_add.cold.66+0x0 [DISABLED] Actually, kprobe blacklist already did similar thing, see within_kprobe_blacklist(). Link: http://lkml.kernel.org/r/157233790394.6706.18243942030937189679.stgit@devnote2 Fixes: 45408c4 ("tracing: kprobes: Prohibit probing on notrace function") Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 6ee4051 commit c7411a1

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

kernel/trace/trace_kprobe.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,10 @@ static int disable_trace_kprobe(struct trace_event_call *call,
435435

436436
#if defined(CONFIG_KPROBES_ON_FTRACE) && \
437437
!defined(CONFIG_KPROBE_EVENTS_ON_NOTRACE)
438-
static bool within_notrace_func(struct trace_kprobe *tk)
438+
static bool __within_notrace_func(unsigned long addr)
439439
{
440-
unsigned long offset, size, addr;
440+
unsigned long offset, size;
441441

442-
addr = trace_kprobe_address(tk);
443442
if (!addr || !kallsyms_lookup_size_offset(addr, &size, &offset))
444443
return false;
445444

@@ -452,6 +451,28 @@ static bool within_notrace_func(struct trace_kprobe *tk)
452451
*/
453452
return !ftrace_location_range(addr, addr + size - 1);
454453
}
454+
455+
static bool within_notrace_func(struct trace_kprobe *tk)
456+
{
457+
unsigned long addr = addr = trace_kprobe_address(tk);
458+
char symname[KSYM_NAME_LEN], *p;
459+
460+
if (!__within_notrace_func(addr))
461+
return false;
462+
463+
/* Check if the address is on a suffixed-symbol */
464+
if (!lookup_symbol_name(addr, symname)) {
465+
p = strchr(symname, '.');
466+
if (!p)
467+
return true;
468+
*p = '\0';
469+
addr = (unsigned long)kprobe_lookup_name(symname, 0);
470+
if (addr)
471+
return __within_notrace_func(addr);
472+
}
473+
474+
return true;
475+
}
455476
#else
456477
#define within_notrace_func(tk) (false)
457478
#endif

0 commit comments

Comments
 (0)