tracehook: tracehook_tracer_task

This adds the tracehook_tracer_task() hook to consolidate all forms of
"Who is using ptrace on me?" logic.  This is used for "TracerPid:" in
/proc and for permission checks.  We also clean up the selinux code the
called an identical accessor.

Signed-off-by: Roland McGrath <roland@redhat.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Reviewed-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Roland McGrath
2008-07-25 19:45:49 -07:00
committed by Linus Torvalds
parent dae33574dc
commit 0d094efeb1
4 changed files with 37 additions and 25 deletions

View File

@@ -72,6 +72,24 @@ static inline int tracehook_unsafe_exec(struct task_struct *task)
return unsafe;
}
/**
* tracehook_tracer_task - return the task that is tracing the given task
* @tsk: task to consider
*
* Returns NULL if noone is tracing @task, or the &struct task_struct
* pointer to its tracer.
*
* Must called under rcu_read_lock(). The pointer returned might be kept
* live only by RCU. During exec, this may be called with task_lock()
* held on @task, still held from when tracehook_unsafe_exec() was called.
*/
static inline struct task_struct *tracehook_tracer_task(struct task_struct *tsk)
{
if (task_ptrace(tsk) & PT_PTRACED)
return rcu_dereference(tsk->parent);
return NULL;
}
/**
* tracehook_report_exec - a successful exec was completed
* @fmt: &struct linux_binfmt that performed the exec