From 3ee21298d5198e52f30894be766569baf4870985 Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Fri, 28 Nov 2014 14:31:27 +0300 Subject: [PATCH] [FIX] Task data searches symbols by substring This prevents issuses with changeable kernel functions names, for example, when copy_process changes its name to copy_process.part... Change-Id: I4c815609f9c8e3f02fcf72aab6297ebb48427fd2 Signed-off-by: Alexander Aksenov --- task_data/task_data.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/task_data/task_data.c b/task_data/task_data.c index 1363832..5398a4e 100644 --- a/task_data/task_data.c +++ b/task_data/task_data.c @@ -2,7 +2,9 @@ #include #include #include +#include #include +#include #include "task_data.h" /* lower bits are used as flags */ @@ -100,27 +102,35 @@ static int do_exit_handler(struct kprobe *p, struct pt_regs *regs) } static struct kretprobe copy_process_rp = { - .kp.symbol_name = "copy_process", .handler = copy_process_ret_handler }; static struct kprobe do_exit_probe = { - .symbol_name = "do_exit", .pre_handler = do_exit_handler }; static int __task_data_init(void *data) { struct task_struct *g, *t; - const char *sym; + unsigned long addr; int ret; - sym = copy_process_rp.kp.symbol_name; + addr = swap_ksyms_substr("copy_process"); + if (addr == 0) { + printk(TD_PREFIX "Cannot find address for copy_process\n"); + return -EINVAL; + } + copy_process_rp.kp.addr = (kprobe_opcode_t *)addr; ret = swap_register_kretprobe(©_process_rp); if (ret) goto reg_failed; - sym = do_exit_probe.symbol_name; + addr = swap_ksyms_substr("do_exit"); + if (addr == 0) { + printk(TD_PREFIX "Cannot find address for do_exit\n"); + return -EINVAL; + } + do_exit_probe.addr = (kprobe_opcode_t *)addr; ret = swap_register_kprobe(&do_exit_probe); if (ret) goto unreg_copy_process; @@ -135,7 +145,7 @@ unreg_copy_process: swap_unregister_kretprobe(©_process_rp); reg_failed: - printk(TD_PREFIX "%s: probe registration failed\n", sym); + printk(TD_PREFIX "0x%lx: probe registration failed\n", addr); return ret; } -- 2.7.4