return NULL;
}
+static struct vm_area_struct *__get_libpthread_vma(struct task_struct *task)
+{
+ struct vm_area_struct *vma = NULL;
+ struct bin_info *libpthread_info;
+
+ libpthread_info = preload_storage_get_libpthread_info();
+
+ if (!libpthread_info) {
+ printk(PRELOAD_PREFIX "Cannot get libpthread info [%u %u %s]!\n",
+ task->tgid, task->pid, task->comm);
+ return NULL;
+ }
+
+ for (vma = task->mm->mmap; vma; vma = vma->vm_next) {
+ if (vma->vm_file && vma->vm_flags & VM_EXEC
+ && vma->vm_file->f_dentry == libpthread_info->dentry) {
+ preload_storage_put_libpthread_info(libpthread_info);
+ return vma;
+ }
+ }
+
+ preload_storage_put_libpthread_info(libpthread_info);
+ return NULL;
+}
+
+static struct vm_area_struct *__get_libsmack_vma(struct task_struct *task)
+{
+ struct vm_area_struct *vma = NULL;
+ struct bin_info *libsmack_info;
+
+ libsmack_info = preload_storage_get_libsmack_info();
+
+ if (!libsmack_info) {
+ printk(PRELOAD_PREFIX "Cannot get libsmack info [%u %u %s]!\n",
+ task->tgid, task->pid, task->comm);
+ return NULL;
+ }
+
+ for (vma = task->mm->mmap; vma; vma = vma->vm_next) {
+ if (vma->vm_file && vma->vm_flags & VM_EXEC
+ && vma->vm_file->f_dentry == libsmack_info->dentry) {
+ preload_storage_put_libsmack_info(libsmack_info);
+ return vma;
+ }
+ }
+
+ preload_storage_put_libsmack_info(libsmack_info);
+ return NULL;
+}
+
static inline struct vm_area_struct *__get_vma_by_addr(struct task_struct *task,
unsigned long caller_addr)
{
{
struct vm_area_struct *linker_vma = __get_linker_vma(task);
struct vm_area_struct *libc_vma = __get_libc_vma(task);
-
- if (linker_vma == NULL || libc_vma == NULL || caller == NULL ||
- caller == linker_vma || caller == libc_vma)
+ struct vm_area_struct *libpthread_vma = __get_libpthread_vma(task);
+ struct vm_area_struct *libsmack_vma = __get_libsmack_vma(task);
+
+ if (linker_vma == NULL ||
+ libc_vma == NULL ||
+ libpthread_vma == NULL ||
+ libsmack_vma == NULL ||
+ caller == NULL ||
+ caller == linker_vma ||
+ caller == libc_vma ||
+ caller == libpthread_vma ||
+ caller == libsmack_vma)
return false;
return true;
struct pt_regs *regs)
{
unsigned long caller_addr = get_regs_ret_func(regs);
- struct vm_area_struct *cvma = __get_vma_by_addr(current, caller_addr);
+ struct vm_area_struct *cvma = __get_vma_by_addr(current, caller_addr);
if (!__is_proc_mmap_mappable(task) ||
!__not_system_caller(task, cvma))
static struct bin_info __handlers_info = { NULL, NULL };
static struct bin_info __linker_info = { NULL, NULL };
static struct bin_info __libc_info;
+static struct bin_info __libpthread_info;
+static struct bin_info __libsmack_info;
static inline struct bin_info *__get_handlers_info(void)
{
__libc_info.dentry = NULL;
}
+static inline void __drop_libpthread_info(void)
+{
+ if (__libpthread_info.dentry)
+ put_dentry(__libpthread_info.dentry);
+
+ __libpthread_info.path = NULL;
+ __libpthread_info.dentry = NULL;
+}
+
+static inline void __drop_libsmack_info(void)
+{
+ if (__libsmack_info.dentry)
+ put_dentry(__libsmack_info.dentry);
+
+ __libsmack_info.path = NULL;
+ __libsmack_info.dentry = NULL;
+}
+
void preload_storage_put_linker_info(struct bin_info *info)
{
}
return &__libc_info;
}
+struct bin_info *preload_storage_get_libpthread_info(void)
+{
+ return &__libpthread_info;
+}
+
+struct bin_info *preload_storage_get_libsmack_info(void)
+{
+ return &__libsmack_info;
+}
+
void preload_storage_put_libc_info(struct bin_info *info)
{
}
+void preload_storage_put_libpthread_info(struct bin_info *info)
+{
+}
+
+void preload_storage_put_libsmack_info(struct bin_info *info)
+{
+}
+
int preload_storage_init(void)
{
__libc_info.path = "/lib/libc.so.6";
if (!__libc_info.dentry)
return -ENOENT;
+ /* TODO check if we have not library */
+ __libpthread_info.path = "/lib/libpthread.so.0";
+ __libpthread_info.dentry = get_dentry(__libpthread_info.path);
+
+ if (!__libpthread_info.dentry)
+ return -ENOENT;
+
+ /* TODO check if we have not library */
+ __libsmack_info.path = "/usr/lib/libsmack.so.1.0.0";
+ __libsmack_info.dentry = get_dentry(__libsmack_info.path);
+
+ if (!__libsmack_info.dentry)
+ return -ENOENT;
+
return 0;
}
void preload_storage_exit(void)
{
+ __drop_libsmack_info();
+ __drop_libpthread_info();
__drop_libc_info();
__drop_handlers_info();
__drop_linker_info();