[REFACTOR] improve method of setting the auxiliary kprobe on copy_process()
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 10 Apr 2013 13:59:41 +0000 (17:59 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 10 Apr 2013 13:59:41 +0000 (17:59 +0400)
driver/probes_manager.c
driver/probes_manager.h
driver/storage.c
driver/us_proc_inst.c
driver/us_proc_inst.h

index 9d3df69..8acd8cd 100644 (file)
@@ -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 *cp_probe = NULL;
 kernel_probe_t *mr_probe = NULL;
 kernel_probe_t *exit_probe = NULL;
 kernel_probe_t *unmap_probe = NULL;
@@ -100,7 +99,6 @@ register_kernel_jprobe (kernel_probe_t * probe)
 {
        int result;
        if( ((probe == pf_probe) && (us_proc_probes & US_PROC_PF_INSTLD)) ||
-           ((probe == cp_probe) && (us_proc_probes & US_PROC_CP_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)))
@@ -120,7 +118,6 @@ static int
 unregister_kernel_jprobe (kernel_probe_t * probe)
 {
        if( ((probe == pf_probe) && (us_proc_probes & US_PROC_PF_INSTLD)) ||
-           ((probe == cp_probe) && (us_proc_probes & US_PROC_CP_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)) ) {
@@ -135,7 +132,6 @@ register_kernel_retprobe (kernel_probe_t * probe)
 {
        int result;
        if( ((probe == pf_probe) && (us_proc_probes & US_PROC_PF_INSTLD)) ||
-           ((probe == cp_probe) && (us_proc_probes & US_PROC_CP_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)) ) {
@@ -156,7 +152,6 @@ static int
 unregister_kernel_retprobe (kernel_probe_t * probe)
 {
        if( ((probe == pf_probe) && (us_proc_probes & US_PROC_PF_INSTLD)) ||
-           ((probe == cp_probe) && (us_proc_probes & US_PROC_CP_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)) ) {
@@ -240,14 +235,6 @@ add_probe (unsigned long addr)
                }
                pprobe = &pf_probe;
        }
-       else if (addr == cp_addr) {
-               probes_flags |= PROBE_FLAG_CP_INSTLD;
-               if (us_proc_probes & US_PROC_CP_INSTLD)
-               {
-                       return 0;
-               }
-               pprobe = &cp_probe;
-       }
        else if (addr == exit_addr) {
                probes_flags |= PROBE_FLAG_EXIT_INSTLD;
                if (us_proc_probes & US_PROC_EXIT_INSTLD)
@@ -276,8 +263,6 @@ add_probe (unsigned long addr)
        if (result) {
                if (addr == pf_addr)
                        probes_flags &= ~PROBE_FLAG_PF_INSTLD;
-               else if (addr == cp_addr)
-                       probes_flags &= ~PROBE_FLAG_CP_INSTLD;
                else if (addr == exit_addr)
                        probes_flags &= ~PROBE_FLAG_EXIT_INSTLD;
                else if (addr == mr_addr)
@@ -297,9 +282,6 @@ int reset_probes(void)
                if (p->addr == pf_addr) {
                        probes_flags &= ~PROBE_FLAG_PF_INSTLD;
                        pf_probe = NULL;
-               } else if (p->addr == cp_addr) {
-                       probes_flags &= ~PROBE_FLAG_CP_INSTLD;
-                       cp_probe = NULL;
                } else if (p->addr == exit_addr) {
                        probes_flags &= ~PROBE_FLAG_EXIT_INSTLD;
                        exit_probe = NULL;
@@ -318,9 +300,6 @@ int reset_probes(void)
                if (p->addr == pf_addr) {
                        probes_flags &= ~PROBE_FLAG_PF_INSTLD;
                        pf_probe = NULL;
-               } else if (p->addr == cp_addr) {
-                       probes_flags &= ~PROBE_FLAG_CP_INSTLD;
-                       cp_probe = NULL;
                } else if (p->addr == exit_addr) {
                        probes_flags &= ~PROBE_FLAG_EXIT_INSTLD;
                        exit_probe = NULL;
@@ -357,14 +336,6 @@ remove_probe (unsigned long addr)
                }
                pf_probe = NULL;
        }
-       else if (addr == cp_addr) {
-               probes_flags &= ~PROBE_FLAG_CP_INSTLD;
-               if (us_proc_probes & US_PROC_CP_INSTLD)
-               {
-                       return 0;
-               }
-               cp_probe = NULL;
-       }
        else if (addr == mr_addr) {
                probes_flags &= ~PROBE_FLAG_MR_INSTLD;
                if (us_proc_probes & US_PROC_MR_INSTLD) {
@@ -430,11 +401,6 @@ def_jprobe_event_handler (unsigned long arg1, unsigned long arg2, unsigned long
                        skip = 1;
 #endif /* CONFIG_X86 */
        }
-       else if (cp_probe == probe)
-       {
-               if (!(probes_flags & PROBE_FLAG_CP_INSTLD))
-                       skip = 1;
-       }
        else if (mr_probe == probe)
        {
                if (us_proc_probes & US_PROC_MR_INSTLD)
@@ -475,14 +441,6 @@ def_retprobe_event_handler (struct kretprobe_instance *pi, struct pt_regs *regs,
                if (!(probes_flags & PROBE_FLAG_PF_INSTLD))
                        skip = 1;
        }
-       if (cp_probe == probe)
-       {
-               if (us_proc_probes & US_PROC_CP_INSTLD)
-                       copy_process_ret_pre_code((struct task_struct*)(regs_return_value(regs)));
-
-               if (!(probes_flags & PROBE_FLAG_CP_INSTLD))
-                       skip = 1;
-       }
        else if (mr_probe == probe)
        {
                if (!(probes_flags & PROBE_FLAG_MR_INSTLD))
index afe0664..2910142 100644 (file)
@@ -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 *cp_probe;
 extern kernel_probe_t *mr_probe;
 extern kernel_probe_t *exit_probe;
 extern kernel_probe_t *unmap_probe;
@@ -69,7 +68,6 @@ extern spinlock_t ec_probe_spinlock;
 
 enum {
        PROBE_FLAG_PF_INSTLD    = (1 << 0),
-       PROBE_FLAG_CP_INSTLD    = (1 << 1),
        PROBE_FLAG_MR_INSTLD    = (1 << 2),
        PROBE_FLAG_EXIT_INSTLD  = (1 << 3),
        PROBE_FLAG_UNMAP_INSTLD = (1 << 4)
index 5949b41..b28594a 100644 (file)
@@ -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 == cp_addr) && !(probes_flags & PROBE_FLAG_CP_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)) ) {
index 4d13f45..f0b2e5a 100644 (file)
@@ -156,6 +156,21 @@ void free_sm_us(struct slot_manager *sm)
        /* FIXME: free */
 }
 
+static void copy_process_ret_pre_code(struct task_struct *p);
+
+static int ret_handler_cp(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+       struct task_struct* task = (struct task_struct *)regs_return_value(regs);
+
+       copy_process_ret_pre_code(task);
+
+       return 0;
+}
+
+static struct kretprobe cp_kretprobe = {
+       .handler = ret_handler_cp,
+};
+
 static struct sspt_procs *get_proc_probes_by_task(struct task_struct *task)
 {
        struct sspt_procs *procs, *tmp;
@@ -400,10 +415,8 @@ int deinst_usr_space_proc (void)
        if (iRet)
                EPRINTF ("uninstall_kernel_probe(do_page_fault) result=%d!", iRet);
 
-       iRet = uninstall_kernel_probe (cp_addr, US_PROC_CP_INSTLD,
-                       0, &cp_probe);
-       if (iRet)
-               EPRINTF ("uninstall_kernel_probe(copy_process) result=%d!", iRet);
+       /* uninstall kretprobe with 'copy_process' */
+       dbi_unregister_kretprobe(&cp_kretprobe);
 
         iRet = uninstall_kernel_probe (mr_addr, US_PROC_MR_INSTLD,
                         0, &mr_probe);
@@ -574,11 +587,11 @@ int inst_usr_space_proc (void)
                EPRINTF ("install_kernel_probe(do_exit) result=%d!", ret);
                return ret;
        }
-       /* enable 'copy_process' */
-       ret = install_kernel_probe (cp_addr, US_PROC_CP_INSTLD, 0, &cp_probe);
-       if (ret != 0)
-       {
-               EPRINTF ("instpall_kernel_probe(copy_process) result=%d!", ret);
+       /* install kretprobe on 'copy_process' */
+       cp_kretprobe.kp.addr = cp_addr;
+       ret = dbi_register_kretprobe(&cp_kretprobe);
+       if (ret) {
+               EPRINTF("dbi_register_kretprobe(copy_process) result=%d!", ret);
                return ret;
        }
 
@@ -1074,7 +1087,8 @@ static void rm_uprobes_child(struct task_struct *new_task)
        }
 }
 
-void copy_process_ret_pre_code(struct task_struct *p)
+/* Delete uprobs in children at fork */
+static void copy_process_ret_pre_code(struct task_struct *p)
 {
        if(!p || IS_ERR(p))
                return;
index 8f935f7..d00fe3f 100644 (file)
@@ -41,15 +41,11 @@ extern void do_munmap_probe_pre_code(struct mm_struct *mm, unsigned long start,
 /* Detects when target process removes IPs. */
 extern void mm_release_probe_pre_code(void);
 
-/* Delete uprobs in children at fork */
-extern void copy_process_ret_pre_code(struct task_struct *p);
-
 extern int us_proc_probes;
 extern pid_t gl_nNotifyTgid;
 
 enum {
        US_PROC_PF_INSTLD    = (1 << 0),
-       US_PROC_CP_INSTLD    = (1 << 1),
        US_PROC_MR_INSTLD    = (1 << 2),
        US_PROC_EXIT_INSTLD  = (1 << 3),
        US_PROC_UNMAP_INSTLD = (1 << 4)