From 840002f98adcabae0e547560753d3b9d0c20bba5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Wed, 28 Oct 2015 18:11:02 +0300 Subject: [PATCH] [FEATURE] already running use taskctx_run() for installing uprobes to already running processes Change-Id: I00ce9f057cb2b39175d4d757ccad8112c6cd657e Signed-off-by: Vyacheslav Cherkashin --- us_manager/pf/pf_group.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/us_manager/pf/pf_group.c b/us_manager/pf/pf_group.c index 9a24cf1..69715c0 100644 --- a/us_manager/pf/pf_group.c +++ b/us_manager/pf/pf_group.c @@ -38,6 +38,8 @@ #include #include #include +#include + struct pf_group { struct list_head list; @@ -610,6 +612,37 @@ void uninstall_page(unsigned long addr) } + +static struct task_struct *get_untracked_task(void) +{ + struct task_struct *task; + + rcu_read_lock(); + for_each_process(task) { + if (task->flags & PF_KTHREAD) + continue; + + if (sspt_proc_get_by_task(task)) + continue; + + if (check_task_on_filters(task)) { + get_task_struct(task); + goto unlock; + } + } + + task = NULL; + +unlock: + rcu_read_unlock(); + return task; +} + +static void install_cb(void *unused) +{ + check_task_and_install(current); +} + /** * @brief Install probes on running processes * @@ -617,7 +650,33 @@ void uninstall_page(unsigned long addr) */ void install_all(void) { - /* TODO: to be implemented */ + int ret; + struct task_struct *task, *first; + + first = get_untracked_task(); + if (first == NULL) + return; + + + ret = taskctx_get(); + if (ret) { + put_task_struct(first); + + pr_err("taskctx_get ret=%d\n", ret);; + return; + } + + for (task = first; task; task = get_untracked_task()) { + ret = taskctx_run(task, install_cb, NULL); + if (ret) { + pr_err("cannot tracking task[%u %u %s] ret=%d\n", + task->tgid, task->pid, task->comm, ret); + } + + put_task_struct(task); + } + + taskctx_put(); } /** -- 2.7.4