swap_driver-y := error_storage.o device_driver.o ec.o legacy.o module.o probes.o \
probes_manager.o storage.o us_proc_inst.o helper.o us_slot_manager.o \
sspt/ip.o sspt/sspt_page.o sspt/sspt_file.o sspt/sspt_procs.o \
- filters/filters_core.o
+ filters/filters_core.o filters/filter_by_pach.o
--- /dev/null
+/*
+ * Dynamic Binary Instrumentation Module based on KProbes
+ * modules/driver/filters/filter_by_pach.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2013
+ *
+ * 2013 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+#include <linux/sched.h>
+#include <us_proc_inst.h>
+#include "filters_core.h"
+
+static struct dentry *dentry = NULL;
+
+static int check_dentry(struct task_struct *task, struct dentry *dentry)
+{
+ struct vm_area_struct *vma;
+ struct mm_struct *mm = task->mm;
+
+ if (mm == NULL) {
+ return 0;
+ }
+
+ for (vma = mm->mmap; vma; vma = vma->vm_next) {
+ if (check_vma(vma) && vma->vm_file->f_dentry == dentry) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static int init_by_pach(void *data, size_t size)
+{
+ if (dentry) {
+ return -EPERM;
+ }
+
+ dentry = (struct dentry *)data;
+
+ return 0;
+}
+
+static void uninit_by_pach(void)
+{
+ dentry = NULL;
+}
+
+static struct task_struct *call_by_pach(struct task_struct *task)
+{
+ if (dentry && check_dentry(task, dentry))
+ return task;
+
+ return NULL;
+}
+
+static struct task_filter ts_filter = {
+ .init = init_by_pach,
+ .uninit = uninit_by_pach,
+ .call = call_by_pach
+};
+
+struct task_filter *get_filter_by_pach(void)
+{
+ return &ts_filter;
+}
--- /dev/null
+#ifndef _FILTER_BY_PACH_H
+#define _FILTER_BY_PACH_H
+
+/*
+ * Dynamic Binary Instrumentation Module based on KProbes
+ * modules/driver/filters/filter_by_pach.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2013
+ *
+ * 2013 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+struct task_filter;
+
+struct task_filter *get_filter_by_pach(void);
+
+#endif /* _FILTER_BY_PACH_H */
#include "sspt/sspt.h"
#include "filters/filters_core.h"
+#include "filters/filter_by_pach.h"
#include "helper.h"
#include "us_slot_manager.h"
+static const char *app_filter = "app";
+
unsigned long ujprobe_event_pre_handler (struct us_ip *ip, struct pt_regs *regs);
void ujprobe_event_handler (unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6);
int uretprobe_event_handler(struct uretprobe_instance *probe, struct pt_regs *regs, struct us_ip *ip);
}
}
+ uninit_filter();
+ unregister_filter(app_filter);
+
return iRet;
}
DPRINTF("User space instr");
+ ret = register_filter(app_filter, get_filter_by_pach());
+ if (ret)
+ return ret;
+
+ if (strcmp(us_proc_info.path, "*")) {
+ ret = set_filter(app_filter);
+ if (ret)
+ return ret;
+
+ ret = init_filter(us_proc_info.m_f_dentry, 0);
+ if (ret)
+ return ret;
+ }
+
ret = register_helper();
if (ret) {
return ret;
return err;
}
-int check_dentry(struct task_struct *task, struct dentry *dentry)
-{
- struct vm_area_struct *vma;
- struct mm_struct *mm = task->active_mm;
-
- if (mm == NULL) {
- return 0;
- }
-
- for (vma = mm->mmap; vma; vma = vma->vm_next) {
- if (check_vma(vma) && vma->vm_file->f_dentry == dentry) {
- return 1;
- }
- }
-
- return 0;
-}
-
void print_vma(struct mm_struct *mm)
{
struct vm_area_struct *vma;
unsigned long jp_handler,
uretprobe_handler_t rp_handler);
-int check_dentry(struct task_struct *task, struct dentry *dentry);
int uninstall_us_proc_probes(struct task_struct *task, struct sspt_procs *procs, enum US_FLAGS flag);
int check_vma(struct vm_area_struct *vma);
int unregister_us_file_probes(struct task_struct *task, struct sspt_file *file, enum US_FLAGS flag);