ftrace: Keep the resolved addr in kallsyms_callback
authorJiri Olsa <jolsa@kernel.org>
Mon, 26 Sep 2022 15:33:36 +0000 (17:33 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 27 Sep 2022 03:30:39 +0000 (20:30 -0700)
Keeping the resolved 'addr' in kallsyms_callback, instead of taking
ftrace_location value, because we depend on symbol address in the
cookie related code.

With CONFIG_X86_KERNEL_IBT option the ftrace_location value differs
from symbol address, which screwes the symbol address cookies matching.

There are 2 users of this function:
- bpf_kprobe_multi_link_attach
    for which this fix is for

- get_ftrace_locations
    which is used by register_fprobe_syms

    this function needs to get symbols resolved to addresses,
    but does not need 'ftrace location addresses' at this point
    there's another ftrace location translation in the path done
    by ftrace_set_filter_ips call:

     register_fprobe_syms
       addrs = get_ftrace_locations

       register_fprobe_ips(addrs)
         ...
         ftrace_set_filter_ips
           ...
             __ftrace_match_addr
               ip = ftrace_location(ip);
               ...

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20220926153340.1621984-3-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/trace/ftrace.c

index 439e2ab6905ee1e05e6f68c508b7e759e87fc86a..447d2e2a8549a3bfd9e876b19e9d87ef1c3f2b94 100644 (file)
@@ -8265,8 +8265,7 @@ static int kallsyms_callback(void *data, const char *name,
        if (args->addrs[idx])
                return 0;
 
-       addr = ftrace_location(addr);
-       if (!addr)
+       if (!ftrace_location(addr))
                return 0;
 
        args->addrs[idx] = addr;