mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 11:11:45 -04:00
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 <[email protected]> Cc: Oleg Nesterov <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
dae33574dc
commit
0d094efeb1
4 changed files with 37 additions and 25 deletions
|
|
@ -80,6 +80,7 @@
|
|||
#include <linux/delayacct.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/pid_namespace.h>
|
||||
#include <linux/tracehook.h>
|
||||
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/processor.h>
|
||||
|
|
@ -168,8 +169,12 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
|
|||
rcu_read_lock();
|
||||
ppid = pid_alive(p) ?
|
||||
task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
|
||||
tpid = pid_alive(p) && p->ptrace ?
|
||||
task_pid_nr_ns(rcu_dereference(p->parent), ns) : 0;
|
||||
tpid = 0;
|
||||
if (pid_alive(p)) {
|
||||
struct task_struct *tracer = tracehook_tracer_task(p);
|
||||
if (tracer)
|
||||
tpid = task_pid_nr_ns(tracer, ns);
|
||||
}
|
||||
seq_printf(m,
|
||||
"State:\t%s\n"
|
||||
"Tgid:\t%d\n"
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@
|
|||
#include <linux/mount.h>
|
||||
#include <linux/security.h>
|
||||
#include <linux/ptrace.h>
|
||||
#include <linux/tracehook.h>
|
||||
#include <linux/cgroup.h>
|
||||
#include <linux/cpuset.h>
|
||||
#include <linux/audit.h>
|
||||
|
|
@ -231,10 +232,14 @@ static int check_mem_permission(struct task_struct *task)
|
|||
* If current is actively ptrace'ing, and would also be
|
||||
* permitted to freshly attach with ptrace now, permit it.
|
||||
*/
|
||||
if (task->parent == current && (task->ptrace & PT_PTRACED) &&
|
||||
task_is_stopped_or_traced(task) &&
|
||||
ptrace_may_access(task, PTRACE_MODE_ATTACH))
|
||||
return 0;
|
||||
if (task_is_stopped_or_traced(task)) {
|
||||
int match;
|
||||
rcu_read_lock();
|
||||
match = (tracehook_tracer_task(task) == current);
|
||||
rcu_read_unlock();
|
||||
if (match && ptrace_may_access(task, PTRACE_MODE_ATTACH))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Noone else is allowed.
|
||||
|
|
|
|||
Loading…
Reference in a new issue