From f2d55ea45b009e6f5019e55fa6a1057846d02b91 Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Tue, 6 Nov 2012 21:33:29 +0400 Subject: [PATCH] Optimized plt instrumentation --- driver/storage.c | 5 ++-- driver/storage.h | 1 + driver/us_proc_inst.c | 74 +++++++++++++++++++++++---------------------------- 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/driver/storage.c b/driver/storage.c index c22d5a4..67fbf29 100644 --- a/driver/storage.c +++ b/driver/storage.c @@ -971,6 +971,7 @@ void unlink_bundle(void) } d_lib->plt_count = 0; kfree((void*) d_lib->p_plt); + us_proc_info.is_plt = 0; } kfree ((void *) us_proc_info.p_libs); us_proc_info.p_libs = 0; @@ -1080,6 +1081,7 @@ int link_bundle() len = *(u_int32_t *)p; /* App path len */ p += sizeof(u_int32_t); + us_proc_info.is_plt = 0; if ( len == 0 ) { us_proc_info.path = NULL; @@ -1147,8 +1149,6 @@ int link_bundle() DPRINTF("d_lib->path = %s", d_lib->path); p += lib_name_len; - printk("+++ lib_name = %s\n", d_lib->path); - if ( i != 0 ) { lib_name_len = *(u_int32_t *)p; p += sizeof(u_int32_t); @@ -1287,6 +1287,7 @@ int link_bundle() if (d_lib->plt_count > 0) { int j; + us_proc_info.is_plt = 1; d_lib->p_plt = kmalloc(d_lib->plt_count * sizeof(us_proc_plt_t), GFP_KERNEL); if (!d_lib->p_plt) { diff --git a/driver/storage.h b/driver/storage.h index 4d0d4e4..d9dfc96 100644 --- a/driver/storage.h +++ b/driver/storage.h @@ -221,6 +221,7 @@ typedef struct unsigned unres_vtps_count; unsigned unres_otg_ips_count; //kprobe_opcode_t *mapped_codelets; + int is_plt; unsigned libs_count; us_proc_lib_t *p_libs; #ifdef __ANDROID diff --git a/driver/us_proc_inst.c b/driver/us_proc_inst.c index 0867341..5b84cd4 100644 --- a/driver/us_proc_inst.c +++ b/driver/us_proc_inst.c @@ -1571,7 +1571,7 @@ void find_plt_address(struct kretprobe_instance *probe, us_proc_ip_t * ip) // If lib only instrumentation task_inst_info = get_task_inst_node(current); } - if (task_inst_info != NULL) + if ((task_inst_info != NULL) && (task_inst_info->is_plt != 0)) { for (i = 0; i < task_inst_info->libs_count; i++) { @@ -1581,55 +1581,49 @@ void find_plt_address(struct kretprobe_instance *probe, us_proc_ip_t * ip) break; } } - } - else - { - printk("task_inst_info not found!\n"); - return; - } - - if (p_lib != NULL) - { - for (i = 0; i < p_lib->plt_count; i++) + if (p_lib != NULL) { - if (addr == p_lib->p_plt[i].func_addr + p_lib->vma_start) + for (i = 0; i < p_lib->plt_count; i++) { - unsigned real_got; - if (strcmp(p_lib->path, task_inst_info->path)) - { - real_got = p_lib->p_plt[i].got_addr + p_lib->vma_start; - } - else - { - real_got = p_lib->p_plt[i].got_addr; - } - if (!read_proc_vm_atomic(current, (unsigned long)(real_got), &real_addr, sizeof(unsigned long))) - { - printk("Failed to read got %p at memory address %p!\n", p_lib->p_plt[i].got_addr, real_got); - break; - } - if (real_addr != p_lib->p_plt[i].real_func_addr) + if (addr == p_lib->p_plt[i].func_addr + p_lib->vma_start) { - p_lib->p_plt[i].real_func_addr = real_addr; - vma = find_vma(current->mm, real_addr); - if ((vma->vm_start <= real_addr) && (vma->vm_end > real_addr)) + unsigned real_got; + if (strcmp(p_lib->path, task_inst_info->path)) { - if (vma->vm_file != NULL) - { - szLibPath = &(vma->vm_file->f_dentry->d_iname); - } + real_got = p_lib->p_plt[i].got_addr + p_lib->vma_start; } - - if (szLibPath) + else { - pack_event_info(PLT_ADDR_PROBE_ID, RECORD_RET, "ppsp", addr, real_addr, szLibPath, real_addr - vma->vm_start); - break; + real_got = p_lib->p_plt[i].got_addr; } - else + if (!read_proc_vm_atomic(current, (unsigned long)(real_got), &real_addr, sizeof(unsigned long))) { - pack_event_info(PLT_ADDR_PROBE_ID, RECORD_RET, "ppp", addr, real_addr, real_addr - vma->vm_start); + printk("Failed to read got %p at memory address %p!\n", p_lib->p_plt[i].got_addr, real_got); break; } + if (real_addr != p_lib->p_plt[i].real_func_addr) + { + p_lib->p_plt[i].real_func_addr = real_addr; + vma = find_vma(current->mm, real_addr); + if ((vma->vm_start <= real_addr) && (vma->vm_end > real_addr)) + { + if (vma->vm_file != NULL) + { + szLibPath = &(vma->vm_file->f_dentry->d_iname); + } + } + + if (szLibPath) + { + pack_event_info(PLT_ADDR_PROBE_ID, RECORD_RET, "ppsp", addr, real_addr, szLibPath, real_addr - vma->vm_start); + break; + } + else + { + pack_event_info(PLT_ADDR_PROBE_ID, RECORD_RET, "ppp", addr, real_addr, real_addr - vma->vm_start); + break; + } + } } } } -- 2.7.4