From 9c5ea7902b87e45eb410488738fd4e73ce404bca Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Wed, 10 Apr 2013 19:08:19 +0400 Subject: [PATCH] [REFACTOR] improve method of setting the auxiliary kprobe on mm_release() --- driver/probes_manager.c | 39 --------------------------------------- driver/probes_manager.h | 2 -- driver/storage.c | 1 - driver/us_proc_inst.c | 33 +++++++++++++++++++-------------- driver/us_proc_inst.h | 3 --- 5 files changed, 19 insertions(+), 59 deletions(-) diff --git a/driver/probes_manager.c b/driver/probes_manager.c index 8acd8cd..d061c88 100644 --- a/driver/probes_manager.c +++ b/driver/probes_manager.c @@ -42,7 +42,6 @@ unsigned long mr_addr; unsigned long exit_addr; unsigned long unmap_addr; kernel_probe_t *pf_probe = NULL; -kernel_probe_t *mr_probe = NULL; kernel_probe_t *exit_probe = NULL; kernel_probe_t *unmap_probe = NULL; unsigned int probes_flags = 0; @@ -99,7 +98,6 @@ register_kernel_jprobe (kernel_probe_t * probe) { int result; if( ((probe == pf_probe) && (us_proc_probes & US_PROC_PF_INSTLD)) || - ((probe == mr_probe) && (us_proc_probes & US_PROC_MR_INSTLD)) || ((probe == unmap_probe) && (us_proc_probes & US_PROC_UNMAP_INSTLD)) || ((probe == exit_probe) && (us_proc_probes & US_PROC_EXIT_INSTLD))) { @@ -118,7 +116,6 @@ static int unregister_kernel_jprobe (kernel_probe_t * probe) { if( ((probe == pf_probe) && (us_proc_probes & US_PROC_PF_INSTLD)) || - ((probe == mr_probe) && (us_proc_probes & US_PROC_MR_INSTLD)) || ((probe == unmap_probe) && (us_proc_probes & US_PROC_UNMAP_INSTLD)) || ((probe == exit_probe) && (us_proc_probes & US_PROC_EXIT_INSTLD)) ) { return 0; // probe is necessary for user space instrumentation @@ -132,7 +129,6 @@ register_kernel_retprobe (kernel_probe_t * probe) { int result; if( ((probe == pf_probe) && (us_proc_probes & US_PROC_PF_INSTLD)) || - ((probe == mr_probe) && (us_proc_probes & US_PROC_MR_INSTLD)) || ((probe == unmap_probe) && (us_proc_probes & US_PROC_UNMAP_INSTLD)) || ((probe == exit_probe) && (us_proc_probes & US_PROC_EXIT_INSTLD)) ) { @@ -152,7 +148,6 @@ static int unregister_kernel_retprobe (kernel_probe_t * probe) { if( ((probe == pf_probe) && (us_proc_probes & US_PROC_PF_INSTLD)) || - ((probe == mr_probe) && (us_proc_probes & US_PROC_MR_INSTLD)) || ((probe == unmap_probe) && (us_proc_probes & US_PROC_UNMAP_INSTLD)) || ((probe == exit_probe) && (us_proc_probes & US_PROC_EXIT_INSTLD)) ) { return 0; // probe is necessary for user space instrumentation @@ -243,13 +238,6 @@ add_probe (unsigned long addr) } pprobe = &exit_probe; } - else if (addr == mr_addr) { - probes_flags |= PROBE_FLAG_MR_INSTLD; - if (us_proc_probes & US_PROC_MR_INSTLD) { - return 0; - } - pprobe = &mr_probe; - } else if (addr == unmap_addr) { probes_flags |= PROBE_FLAG_UNMAP_INSTLD; if (us_proc_probes & US_PROC_UNMAP_INSTLD) @@ -265,8 +253,6 @@ add_probe (unsigned long addr) probes_flags &= ~PROBE_FLAG_PF_INSTLD; else if (addr == exit_addr) probes_flags &= ~PROBE_FLAG_EXIT_INSTLD; - else if (addr == mr_addr) - probes_flags &= ~PROBE_FLAG_MR_INSTLD; else if (addr == unmap_addr) probes_flags &= ~PROBE_FLAG_UNMAP_INSTLD; } @@ -285,9 +271,6 @@ int reset_probes(void) } else if (p->addr == exit_addr) { probes_flags &= ~PROBE_FLAG_EXIT_INSTLD; exit_probe = NULL; - } else if (p->addr == mr_addr) { - probes_flags &= ~PROBE_FLAG_MR_INSTLD; - mr_probe = NULL; } else if (p->addr == unmap_addr) { probes_flags &= ~PROBE_FLAG_UNMAP_INSTLD; unmap_probe = NULL; @@ -303,9 +286,6 @@ int reset_probes(void) } else if (p->addr == exit_addr) { probes_flags &= ~PROBE_FLAG_EXIT_INSTLD; exit_probe = NULL; - } else if (p->addr == mr_addr) { - probes_flags &= ~PROBE_FLAG_MR_INSTLD; - mr_probe = NULL; } else if (p->addr == unmap_addr) { probes_flags &= ~PROBE_FLAG_UNMAP_INSTLD; unmap_probe = NULL; @@ -336,13 +316,6 @@ remove_probe (unsigned long addr) } pf_probe = NULL; } - else if (addr == mr_addr) { - probes_flags &= ~PROBE_FLAG_MR_INSTLD; - if (us_proc_probes & US_PROC_MR_INSTLD) { - return 0; - } - mr_probe = NULL; - } else if (addr == exit_addr) { probes_flags &= ~PROBE_FLAG_EXIT_INSTLD; if (us_proc_probes & US_PROC_EXIT_INSTLD) @@ -401,13 +374,6 @@ def_jprobe_event_handler (unsigned long arg1, unsigned long arg2, unsigned long skip = 1; #endif /* CONFIG_X86 */ } - else if (mr_probe == probe) - { - if (us_proc_probes & US_PROC_MR_INSTLD) - mm_release_probe_pre_code(); - if (!(probes_flags & PROBE_FLAG_MR_INSTLD)) - skip = 1; - } else if (exit_probe == probe) { if (us_proc_probes & US_PROC_EXIT_INSTLD) @@ -441,11 +407,6 @@ def_retprobe_event_handler (struct kretprobe_instance *pi, struct pt_regs *regs, if (!(probes_flags & PROBE_FLAG_PF_INSTLD)) skip = 1; } - else if (mr_probe == probe) - { - if (!(probes_flags & PROBE_FLAG_MR_INSTLD)) - skip = 1; - } else if (exit_probe == probe) { if (!(probes_flags & PROBE_FLAG_EXIT_INSTLD)) diff --git a/driver/probes_manager.h b/driver/probes_manager.h index 2910142..526063a 100644 --- a/driver/probes_manager.h +++ b/driver/probes_manager.h @@ -58,7 +58,6 @@ extern unsigned long mr_addr; extern unsigned long exit_addr; extern unsigned long unmap_addr; extern kernel_probe_t *pf_probe; -extern kernel_probe_t *mr_probe; extern kernel_probe_t *exit_probe; extern kernel_probe_t *unmap_probe; extern unsigned int probes_flags; @@ -68,7 +67,6 @@ extern spinlock_t ec_probe_spinlock; enum { PROBE_FLAG_PF_INSTLD = (1 << 0), - PROBE_FLAG_MR_INSTLD = (1 << 2), PROBE_FLAG_EXIT_INSTLD = (1 << 3), PROBE_FLAG_UNMAP_INSTLD = (1 << 4) }; diff --git a/driver/storage.c b/driver/storage.c index b28594a..39c3e8f 100644 --- a/driver/storage.c +++ b/driver/storage.c @@ -1130,7 +1130,6 @@ void pack_task_event_info(struct task_struct *task, probe_id_t probe_id, addr = get_probe_func_addr(fmt, args); va_end(args); if( ((addr == pf_addr) && !(probes_flags & PROBE_FLAG_PF_INSTLD)) || - ((addr == mr_addr) && !(probes_flags & PROBE_FLAG_MR_INSTLD)) || ((addr == unmap_addr) && !(probes_flags & PROBE_FLAG_UNMAP_INSTLD)) || ((addr == exit_addr) && !(probes_flags & PROBE_FLAG_EXIT_INSTLD)) ) { return; diff --git a/driver/us_proc_inst.c b/driver/us_proc_inst.c index f0b2e5a..5fef1cd 100644 --- a/driver/us_proc_inst.c +++ b/driver/us_proc_inst.c @@ -171,6 +171,12 @@ static struct kretprobe cp_kretprobe = { .handler = ret_handler_cp, }; +static void jmm_release(struct task_struct *tsk, struct mm_struct *mm); + +static struct jprobe mr_jprobe = { + .entry = jmm_release +}; + static struct sspt_procs *get_proc_probes_by_task(struct task_struct *task) { struct sspt_procs *procs, *tmp; @@ -418,10 +424,8 @@ int deinst_usr_space_proc (void) /* uninstall kretprobe with 'copy_process' */ dbi_unregister_kretprobe(&cp_kretprobe); - iRet = uninstall_kernel_probe (mr_addr, US_PROC_MR_INSTLD, - 0, &mr_probe); - if (iRet) - EPRINTF ("uninstall_kernel_probe(mm_release) result=%d!", iRet); + /* uninstall jprobe with 'mm_release' */ + dbi_unregister_jprobe(&mr_jprobe); iRet = uninstall_kernel_probe (exit_addr, US_PROC_EXIT_INSTLD, 0, &exit_probe); @@ -595,11 +599,11 @@ int inst_usr_space_proc (void) return ret; } - // enable 'mm_release' probe to detect when for remove user space probes - ret = install_kernel_probe (mr_addr, US_PROC_MR_INSTLD, 0, &mr_probe); - if (ret != 0) - { - EPRINTF ("install_kernel_probe(mm_release) result=%d!", ret); + /* install jprobe on 'mm_release' to detect when for remove user space probes */ + mr_jprobe.kp.addr = mr_addr; + ret = dbi_register_jprobe(&mr_jprobe); + if (ret != 0) { + EPRINTF("dbi_register_jprobe(mm_release) result=%d!", ret); return ret; } @@ -1037,13 +1041,13 @@ void do_munmap_probe_pre_code(struct mm_struct *mm, unsigned long start, size_t } EXPORT_SYMBOL_GPL(do_munmap_probe_pre_code); -void mm_release_probe_pre_code(void) +/* Detects when target process removes IPs. */ +static void jmm_release(struct task_struct *task, struct mm_struct *mm) { - struct task_struct *task = current; struct sspt_procs *procs = NULL; if (!is_us_instrumentation() || task->tgid != task->pid) { - return; + goto out; } if (is_libonly()) { @@ -1063,9 +1067,10 @@ void mm_release_probe_pre_code(void) dbi_unregister_all_uprobes(task, 1); } -} -EXPORT_SYMBOL_GPL(mm_release_probe_pre_code); +out: + dbi_jprobe_return(); +} static void recover_child(struct task_struct *child_task, struct sspt_procs *procs) { diff --git a/driver/us_proc_inst.h b/driver/us_proc_inst.h index d00fe3f..1af66b9 100644 --- a/driver/us_proc_inst.h +++ b/driver/us_proc_inst.h @@ -38,15 +38,12 @@ extern void do_exit_probe_pre_code (void); /* Detects when target removes IPs. */ extern void do_munmap_probe_pre_code(struct mm_struct *mm, unsigned long start, size_t len); -/* Detects when target process removes IPs. */ -extern void mm_release_probe_pre_code(void); extern int us_proc_probes; extern pid_t gl_nNotifyTgid; enum { US_PROC_PF_INSTLD = (1 << 0), - US_PROC_MR_INSTLD = (1 << 2), US_PROC_EXIT_INSTLD = (1 << 3), US_PROC_UNMAP_INSTLD = (1 << 4) }; -- 2.7.4