return !!us_proc_info.path;
}
-struct sspt_procs *get_proc_probes_by_task(struct task_struct *task)
+static struct sspt_procs *get_proc_probes_by_task(struct task_struct *task)
{
struct sspt_procs *procs, *tmp;
return NULL;
}
-void add_proc_probes(struct task_struct *task, struct sspt_procs *procs)
+static void add_proc_probes(struct task_struct *task, struct sspt_procs *procs)
{
list_add_tail(&procs->list, &proc_probes_list);
}
-struct sspt_procs *get_proc_probes_by_task_or_new(struct task_struct *task)
+static struct sspt_procs *get_proc_probes_by_task_or_new(struct task_struct *task)
{
struct sspt_procs *procs = get_proc_probes_by_task(task);
if (procs == NULL) {
struct mm_struct *mm;
struct dentry *dentry = dentry_by_path(path);
- *p_task = 0;
+ *p_task = NULL;
/* find corresponding dir entry, this is also check for valid path */
// TODO: test - try to instrument process with non-existing path
return 0;
}
-
-static void us_vtp_event_pre_handler (us_proc_vtp_t * vtp, struct pt_regs *regs)
-{
- __get_cpu_var(gpVtp) = vtp;
- __get_cpu_var(gpCurVtpRegs) = regs;
-}
-
-static void us_vtp_event_handler (unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6)
-{
- us_proc_vtp_t *vtp = __get_cpu_var(gpVtp);
-#if !defined(CONFIG_X86)
- struct pt_regs *regs = __get_cpu_var(gpCurVtpRegs);
-#endif
- char fmt[4];
- unsigned long vaddr;
- long ival;
- char cval, *sval;
- us_proc_vtp_data_t *vtp_data;
-unsigned long ll;
- fmt[0] = 'p';
- fmt[3] = 0;
- fmt[2] = 's';
-
- list_for_each_entry_rcu (vtp_data, &vtp->list, list) {
- // DPRINTF ("[%d]proc %s(%d): %lx", nCount++, current->comm, current->pid, vtp->addr);
- fmt[1] = vtp_data->type;
- if (vtp_data->reg == -1)
- vaddr = vtp_data->off;
- else
- vaddr = ARCH_REG_VAL (regs, vtp_data->reg) + vtp_data->off;
- // DPRINTF ("VTP type '%c'", vtp_data->type);
- switch (vtp_data->type)
- {
- case 'd':
- case 'x':
- case 'p':
- if (read_proc_vm_atomic (current, vaddr, &ival, sizeof (ival)) < sizeof (ival))
- EPRINTF ("failed to read vm of proc %s/%u addr %lu!", current->comm, current->pid, vaddr);
- else
- pack_event_info (VTP_PROBE_ID, RECORD_ENTRY, fmt, vtp->jprobe.kp.addr, ival, vtp_data->name);
- break;
- case 'f':
- if (read_proc_vm_atomic (current, vaddr, &ival, sizeof (ival)) < sizeof (ival))
- EPRINTF ("failed to read vm of proc %s/%u addr %lu!", current->comm, current->pid, vaddr);
- else
- pack_event_info (VTP_PROBE_ID, RECORD_ENTRY, fmt, vtp->jprobe.kp.addr, ival, vtp_data->name);
- break;
- case 'c':
- if (read_proc_vm_atomic (current, vaddr, &cval, sizeof (cval)) < sizeof (cval))
- EPRINTF ("failed to read vm of proc %s/%u addr %lu!", current->comm, current->pid, vaddr);
- else
- pack_event_info (VTP_PROBE_ID, RECORD_ENTRY, fmt, vtp->jprobe.kp.addr, cval, vtp_data->name);
- break;
- case 's':
- if (current->active_mm) {
- struct page *page;
- struct vm_area_struct *vma;
- void *maddr;
- int len;
- if (get_user_pages_atomic (current, current->active_mm, vaddr, 1, 0, 1, &page, &vma) <= 0) {
- EPRINTF ("get_user_pages_atomic failed for proc %s/%u addr %lu!", current->comm, current->pid, vaddr);
- break;
- }
- maddr = kmap_atomic (page, KM_USER0);
- len = strlen (maddr + (vaddr & ~PAGE_MASK));
- sval = kmalloc (len + 1, GFP_KERNEL);
- if (!sval)
- EPRINTF ("failed to alloc memory for string in proc %s/%u addr %lu!", current->comm, current->pid, vaddr);
- else {
- copy_from_user_page (vma, page, vaddr, sval, maddr + (vaddr & ~PAGE_MASK), len + 1);
- pack_event_info (VTP_PROBE_ID, RECORD_ENTRY, fmt, vtp->jprobe.kp.addr, sval, vtp_data->name);
- kfree (sval);
- }
- kunmap_atomic (maddr, KM_USER0);
- page_cache_release (page);
- }
- else
- EPRINTF ("task %s/%u has no mm!", current->comm, current->pid);
- break;
- default:
- EPRINTF ("unknown variable type '%c'", vtp_data->type);
- }
- }
- dbi_uprobe_return ();
-}
-
-static int install_mapped_ips (struct task_struct *task, inst_us_proc_t* task_inst_info, int atomic)
-{
- struct vm_area_struct *vma;
- int i, k, err;
- unsigned long addr;
- unsigned int old_ips_count, old_vtps_count;
- struct task_struct *t;
- struct mm_struct *mm;
-
- mm = atomic ? task->active_mm : get_task_mm (task);
- if (!mm) {
- return task_inst_info->unres_ips_count + task_inst_info->unres_vtps_count;
- }
- old_ips_count = task_inst_info->unres_ips_count;
- old_vtps_count = task_inst_info->unres_vtps_count;
- if(!atomic)
- down_read (&mm->mmap_sem);
- vma = mm->mmap;
- while (vma) {
- // skip non-text section
-#ifndef __ANDROID
- if (vma->vm_pgoff != 0 || !(vma->vm_flags & VM_EXEC) || !vma->vm_file || (vma->vm_flags & VM_ACCOUNT) ||
- !(vma->vm_flags & (VM_WRITE | VM_MAYWRITE)) ||
- !(vma->vm_flags & (VM_READ | VM_MAYREAD))) {
-#else // __ANDROID
- if (vma->vm_pgoff != 0 || !(vma->vm_flags & VM_EXEC) || !vma->vm_file) {
-#endif // __ANDROID
- vma = vma->vm_next;
- continue;
- }
- /**
- * After process was forked, some time it inherits parent process environment.
- * We need to renew instrumentation when we detect that process gets own environment.
- */
- for (i = 0; i < task_inst_info->libs_count; i++) {
-// struct path tmp_path;
-// tmp_path.dentry = task_inst_info->p_libs[i].m_f_dentry;
-// tmp_path.mnt = task_inst_info->p_libs[i].m_vfs_mount;
-// char* p_path = d_path ( &tmp_path, path_buffer, 255 );
-// DPRINTF("f_dentry:%x m_f_dentry:%x path:%s", vma->vm_file->f_dentry,
-// task_inst_info->p_libs[i].m_f_dentry, p_path );
-
- //TODO: test - try to instrument non-existing libs
- if (vma->vm_file->f_dentry == task_inst_info->p_libs[i].m_f_dentry) {
-// DPRINTF("vm_flags:%x loaded:%x ips_count:%d vtps_count:%d",
-// vma->vm_flags, task_inst_info->p_libs[i].loaded,
-// task_inst_info->p_libs[i].ips_count, task_inst_info->p_libs[i].vtps_count );
- if (!task_inst_info->p_libs[i].loaded) {
-// DPRINTF("!VM_EXECUTABLE && !loaded");
- char *p;
- int app_flag = (vma->vm_file->f_dentry == task_inst_info->m_f_dentry);
- DPRINTF ("post dyn lib event %s/%s", current->comm, task_inst_info->p_libs[i].path);
- // if we installed something, post library info for those IPs
- p = strrchr(task_inst_info->p_libs[i].path, '/');
- if(!p)
- p = task_inst_info->p_libs[i].path;
- else
- p++;
- task_inst_info->p_libs[i].loaded = 1;
- task_inst_info->p_libs[i].vma_start = vma->vm_start;
- task_inst_info->p_libs[i].vma_end = vma->vm_end;
- task_inst_info->p_libs[i].vma_flag = vma->vm_flags;
- pack_event_info (DYN_LIB_PROBE_ID, RECORD_ENTRY, "dspdd",
- task->tgid, p, vma->vm_start, vma->vm_end-vma->vm_start, app_flag);
- }
- for (k = 0; k < task_inst_info->p_libs[i].ips_count; k++) {
- DPRINTF("ips_count current:%d", k);
- if (!task_inst_info->p_libs[i].p_ips[k].installed) {
- DPRINTF("!installed");
- addr = task_inst_info->p_libs[i].p_ips[k].offset;
- addr += vma->vm_start;
- if (page_present (mm, addr)) {
- DPRINTF ("pid %d, %s sym is loaded at %lx/%lx.",
- task->pid, task_inst_info->p_libs[i].path,
- task_inst_info->p_libs[i].p_ips[k].offset, addr);
- task_inst_info->p_libs[i].p_ips[k].jprobe.kp.addr = (kprobe_opcode_t *) addr;
- task_inst_info->p_libs[i].p_ips[k].retprobe.kp.addr = (kprobe_opcode_t *) addr;
- task_inst_info->unres_ips_count--;
- err = register_usprobe(task, &task_inst_info->p_libs[i].p_ips[k], atomic);
- if (err != 0) {
- DPRINTF ("failed to install IP at %lx/%p. Error %d!",
- task_inst_info->p_libs[i].p_ips[k].offset,
- task_inst_info->p_libs[i].p_ips[k].jprobe.kp.addr, err);
- }
- }
- }
- }
- for (k = 0; k < task_inst_info->p_libs[i].vtps_count; k++) {
- DPRINTF("vtps_count current:%d", k);
- if (!task_inst_info->p_libs[i].p_vtps[k].installed) {
- DPRINTF("!installed");
- addr = task_inst_info->p_libs[i].p_vtps[k].addr;
- if (!(vma->vm_flags & VM_EXECUTABLE))
- addr += vma->vm_start;
- if (page_present (mm, addr)) {
- DPRINTF ("pid %d, %s sym is loaded at %lx/%lx.",
- task->pid, task_inst_info->p_libs[i].path,
- task_inst_info->p_libs[i].p_ips[k].offset, addr);
- task_inst_info->p_libs[i].p_vtps[k].jprobe.kp.tgid = task_inst_info->tgid;
- task_inst_info->p_libs[i].p_vtps[k].jprobe.kp.addr = (kprobe_opcode_t *) addr;
- task_inst_info->p_libs[i].p_vtps[k].jprobe.entry = (kprobe_opcode_t *) us_vtp_event_handler;
- task_inst_info->p_libs[i].p_vtps[k].jprobe.pre_entry = (kprobe_pre_entry_handler_t) us_vtp_event_pre_handler;
- task_inst_info->p_libs[i].p_vtps[k].jprobe.priv_arg = &task_inst_info->p_libs[i].p_vtps[k];
- task_inst_info->p_libs[i].p_vtps[k].installed = 1;
- task_inst_info->unres_vtps_count--;
- err = dbi_register_ujprobe(task, &task_inst_info->p_libs[i].p_vtps[k].jprobe, atomic);
- if ( err != 0 ) {
- EPRINTF ("failed to install VTP at %p. Error %d!",
- task_inst_info->p_libs[i].p_vtps[k].jprobe.kp.addr, err);
- }
- }
- }
- }
- }
- }
-
- vma = vma->vm_next;
- }
-
- if (!atomic) {
- up_read (&mm->mmap_sem);
- mmput (mm);
- }
- return task_inst_info->unres_ips_count + task_inst_info->unres_vtps_count;
-}
-
static void set_mapping_file(struct sspt_file *file,
const struct sspt_procs *procs,
const struct task_struct *task,
}
EXPORT_SYMBOL_GPL(install_otg_ip);
-
-static int uninstall_mapped_ips (struct task_struct *task, inst_us_proc_t* task_inst_info, int atomic)
-{
- int i, k, err;
-
- for (i = 0; i < task_inst_info->libs_count; i++)
- {
- DPRINTF ("clear lib %s.", task_inst_info->p_libs[i].path);
- for (k = 0; k < task_inst_info->p_libs[i].ips_count; k++)
- {
- if (task_inst_info->p_libs[i].p_ips[k].installed)
- {
- DPRINTF ("remove IP at %p.", task_inst_info->p_libs[i].p_ips[k].jprobe.kp.addr);
- err = unregister_usprobe (task, &task_inst_info->p_libs[i].p_ips[k], atomic, 0);
- if (err != 0)
- {
- EPRINTF ("failed to uninstall IP at %p. Error %d!", task_inst_info->p_libs[i].p_ips[k].jprobe.kp.addr, err);
- continue;
- }
- task_inst_info->unres_ips_count++;
- }
- }
- for (k = 0; k < task_inst_info->p_libs[i].vtps_count; k++)
- {
- if (task_inst_info->p_libs[i].p_vtps[k].installed)
- {
- dbi_unregister_ujprobe (task, &task_inst_info->p_libs[i].p_vtps[k].jprobe, atomic);
- task_inst_info->unres_vtps_count++;
- task_inst_info->p_libs[i].p_vtps[k].installed = 0;
- }
- }
- task_inst_info->p_libs[i].loaded = 0;
- }
-
- DPRINTF ("Ures IPs %d.", task_inst_info->unres_ips_count);
- DPRINTF ("Ures VTPs %d.", task_inst_info->unres_vtps_count);
- return 0;
-}
-
static int uninstall_kernel_probe (unsigned long addr, int uflag, int kflag, kernel_probe_t ** pprobe)
{
kernel_probe_t *probe = NULL;
int deinst_usr_space_proc (void)
{
int iRet = 0, found = 0;
- struct task_struct *task = 0;
- inst_us_proc_t *task_inst_info = NULL;
+ struct task_struct *task = NULL;
if (!is_us_instrumentation()) {
return 0;
int inst_usr_space_proc (void)
{
int ret, i;
- struct task_struct *task = 0;
+ struct task_struct *task = NULL;
if (!is_us_instrumentation()) {
return 0;
static int register_us_page_probe(struct sspt_page *page,
const struct sspt_file *file,
- const struct task_struct *task)
+ struct task_struct *task)
{
int err = 0;
struct us_ip *ip;
spin_lock(&page->lock);
if (sspt_page_is_install(page)) {
- printk("page %x in %s task[tgid=%u, pid=%u] already installed\n",
+ printk("page %lx in %s task[tgid=%u, pid=%u] already installed\n",
page->offset, file->dentry->d_iname, task->tgid, task->pid);
print_vma(task->mm);
- return 0;
+ goto unlock;
}
sspt_page_assert_install(page);
err = register_usprobe_my(task, ip);
if (err != 0) {
//TODO: ERROR
- return err;
+ goto unlock;
}
}
sspt_page_installed(page);
+unlock:
spin_unlock(&page->lock);
- return 0;
+ return err;
}
-static int unregister_us_page_probe(const struct task_struct *task,
+static int unregister_us_page_probe(struct task_struct *task,
struct sspt_page *page, enum US_FLAGS flag)
{
int err = 0;
struct dentry *dentry = vma->vm_file->f_dentry;
struct sspt_file *file = sspt_procs_find_file(procs, dentry);
if (file) {
- struct page_probes *page;
+ struct sspt_page *page;
if (!file->loaded) {
set_mapping_file(file, procs, task, vma);
file->loaded = 1;
static int uninstall_us_proc_probes(struct task_struct *task, struct sspt_procs *procs, enum US_FLAGS flag)
{
- int err;
+ int err = 0;
struct sspt_file *file;
list_for_each_entry_rcu(file, &procs->file_list, list) {
return err;
}
-static pid_t find_proc_by_task(const struct task_struct *task, const struct dentry *dentry)
+static pid_t find_proc_by_task(const struct task_struct *task, struct dentry *dentry)
{
struct vm_area_struct *vma;
struct mm_struct *mm = task->active_mm;
{
struct task_struct *task = current->group_leader;
struct mm_struct *mm = task->mm;
- struct vm_area_struct *vma = 0;
struct sspt_procs *procs = NULL;
/*
* Because process threads have same address space
}
EXPORT_SYMBOL_GPL(do_exit_probe_pre_code);
-int check_vma_area(struct vm_area_struct *vma, unsigned long start, unsigned long end)
-{
- return (vma->vm_start >= start && vma->vm_end <= end);
-}
-
void print_vma(struct mm_struct *mm)
{
struct vm_area_struct *vma;
char *x = vma->vm_flags & VM_EXEC ? "x" : "-";
char *r = vma->vm_flags & VM_READ ? "r" : "-";
char *w = vma->vm_flags & VM_WRITE ? "w" : "-";
- char *name = vma->vm_file ? vma->vm_file->f_dentry->d_iname : "N/A";
+ char *name = vma->vm_file ? (char *)vma->vm_file->f_dentry->d_iname : "N/A";
- printk("### [%8x..%8x] %s%s%s pgoff=\'%8u\' %s\n",
+ printk("### [%8lx..%8lx] %s%s%s pgoff=\'%8lu\' %s\n",
vma->vm_start, vma->vm_end, x, r, w, vma->vm_pgoff, name);
}
printk("### print_vma: END\n");
{
struct mm_struct *mm = task->mm;
struct vm_area_struct *vma;
- unsigned long end, pointer, step;
if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE - start) {
return -EINVAL;
if (procs) {
if (remove_unmap_probes(task, procs, start, len)) {
- printk("ERROR do_munmap: start=%x, len=%x\n", start, len);
+ printk("ERROR do_munmap: start=%lx, len=%x\n", start, len);
}
}
}
dbi_uprobe_return ();
}
-void send_plt(struct us_ip *ip)
+static void send_plt(struct us_ip *ip)
{
unsigned long addr = (unsigned long)ip->jprobe.kp.addr;
struct vm_area_struct *vma = find_vma(current->mm, addr);
ip->got_addr + vma->vm_start;
if (!read_proc_vm_atomic(current, real_got, &real_addr, sizeof(real_addr))) {
- printk("Failed to read got %p at memory address %p!\n", ip->got_addr, real_got);
+ printk("Failed to read got %lx at memory address %lx!\n", ip->got_addr, real_got);
return;
}
if (vma && (vma->vm_start <= real_addr) && (vma->vm_end > real_addr)) {
name = vma->vm_file ? vma->vm_file->f_dentry->d_iname : NULL;
} else {
- printk("Failed to get vma, includes %x address\n", real_addr);
+ printk("Failed to get vma, includes %lx address\n", real_addr);
return;
}