From 29d4d74e3c7b7f3cd86b5f0053422885eb950f40 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Sat, 22 Aug 2015 14:44:19 +0300 Subject: [PATCH] [FIX] Preload: use get_user to obtain current linker state Change-Id: I90bd7d09c6106a3324fa810d5cdc344a122a49c7 Signed-off-by: Vyacheslav Cherkashin --- preload/Kbuild | 1 - preload/preload_debugfs.c | 1 - preload/preload_module.c | 11 +++---- preload/preload_patcher.c | 76 ----------------------------------------------- preload/preload_patcher.h | 18 ----------- preload/preload_threads.c | 1 - 6 files changed, 4 insertions(+), 104 deletions(-) delete mode 100644 preload/preload_patcher.c delete mode 100644 preload/preload_patcher.h diff --git a/preload/Kbuild b/preload/Kbuild index 6d6cf84..84aa787 100644 --- a/preload/Kbuild +++ b/preload/Kbuild @@ -7,5 +7,4 @@ swap_preload-y := preload_module.o \ preload_probe.o \ preload_control.o \ preload_threads.o \ - preload_patcher.o \ preload_pd.o diff --git a/preload/preload_debugfs.c b/preload/preload_debugfs.c index 9e412c9..caeb022 100644 --- a/preload/preload_debugfs.c +++ b/preload/preload_debugfs.c @@ -12,7 +12,6 @@ #include "preload_debugfs.h" #include "preload_module.h" #include "preload_control.h" -#include "preload_patcher.h" #include "preload_storage.h" static const char PRELOAD_FOLDER[] = "preload"; diff --git a/preload/preload_module.c b/preload/preload_module.c index 4269000..547edf9 100644 --- a/preload/preload_module.c +++ b/preload/preload_module.c @@ -27,7 +27,6 @@ #include "preload_storage.h" #include "preload_control.h" #include "preload_threads.h" -#include "preload_patcher.h" #include "preload_pd.h" #define page_to_proc(page) ((page)->file->proc) @@ -377,7 +376,7 @@ static bool __is_proc_mmap_mappable(struct task_struct *task) struct vm_area_struct *linker_vma = __get_linker_vma(task); unsigned long r_debug_addr; unsigned int state; - int ret; + enum { r_state_offset = sizeof(int) + sizeof(void *) + sizeof(long) }; if (linker_vma == NULL) return false; @@ -386,13 +385,11 @@ static bool __is_proc_mmap_mappable(struct task_struct *task) if (r_debug_addr == 0) return false; - ret = preload_patcher_get_ui((void *)r_debug_addr + sizeof(int) + - sizeof(void *) + sizeof(unsigned long), - &state, task); - if (ret != sizeof(state)) + r_debug_addr += r_state_offset; + if (get_user(state, (unsigned long *)r_debug_addr)) return false; - return ( state == 0 ? true : false ); + return !state; } static bool __not_system_caller(struct task_struct *task, diff --git a/preload/preload_patcher.c b/preload/preload_patcher.c deleted file mode 100644 index d2457b7..0000000 --- a/preload/preload_patcher.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include - -#include - -#include "preload_patcher.h" -#include "preload_debugfs.h" -#include "preload_storage.h" - - -static inline bool check_vma(struct vm_area_struct *vma, struct dentry *dentry) -{ - struct file *file = vma->vm_file; - - return (file && (vma->vm_flags & VM_EXEC) && (file->f_dentry == dentry)); -} - - -static inline int __patch_proc_mem(struct task_struct *task, unsigned long addr, - void *buf, int size) -{ - return write_proc_vm_atomic(task, addr, buf, size); -} - -static inline int __read_proc_mem(struct task_struct *task, unsigned long addr, - void *value, size_t value_size) -{ - return read_proc_vm_atomic(task, addr, value, value_size); -} - - - - -int preload_patcher_patch_proc(void *addr, unsigned long val, - struct task_struct *task) -{ - return __patch_proc_mem(task, (unsigned long)addr, &val, sizeof(val)); -} - -int preload_patcher_write_string(void *addr, char *string, size_t len, - struct task_struct *task) -{ - return __patch_proc_mem(task, (unsigned long)addr, string, len); -} - -int preload_patcher_get_ul(void *addr, unsigned long *val, - struct task_struct *task) -{ - return __read_proc_mem(task, (unsigned long)addr, val, sizeof(*val)); -} - -int preload_patcher_get_ui(void *addr, unsigned int *val, - struct task_struct *task) -{ - return __read_proc_mem(task, (unsigned long)addr, val, sizeof(*val)); -} - -int preload_patcher_null_mem(void *addr, int size, struct task_struct *task) -{ - char *buf; - int ret; - - buf = kmalloc(size, GFP_KERNEL); - if (buf == NULL) - return -ENOMEM; - - memset(buf, 0, size); - - ret = __patch_proc_mem(task, (unsigned long)addr, buf, size); - - kfree(buf); - - return ret; -} diff --git a/preload/preload_patcher.h b/preload/preload_patcher.h deleted file mode 100644 index 492a2c0..0000000 --- a/preload/preload_patcher.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __PRELOAD_PATCHER_H__ -#define __PRELOAD_PATCHER_H__ - -struct task_struct; - -int preload_patcher_patch_proc(void *addr, unsigned long val, - struct task_struct *task); -int preload_patcher_write_string(void *addr, char *string, size_t len, - struct task_struct *task); -int preload_patcher_get_ul(void *addr, unsigned long *val, - struct task_struct *task); -int preload_patcher_null_mem(void *addr, int size, struct task_struct *task); -int preload_patcher_get_ui(void *addr, unsigned int *val, - struct task_struct *task); - - - -#endif /* __PRELOAD_PATCHER_H__ */ diff --git a/preload/preload_threads.c b/preload/preload_threads.c index 7c881d4..20840ac 100644 --- a/preload/preload_threads.c +++ b/preload/preload_threads.c @@ -9,7 +9,6 @@ #include "preload.h" #include "preload_threads.h" #include "preload_debugfs.h" -#include "preload_patcher.h" #include "preload_pd.h" struct preload_td { -- 2.7.4