Skip to content
Permalink
Browse files
ptrace: Allow other threads to access tracee
Currently only the tracing thread can call ptrace on a given pid. This
patch allows any task in the tracing thread's thread group to also call
ptrace. This makes it easier and more performant to write multi-threaded
applications that use ptrace.

In our ptrace-based simulator, we currently work-around this limitation
by stopping and detaching inactive tracees, so that any thread in our
worker thread pool can later re-attach and resume control of the tracee.
This detaching and reattaching carries with it a significant performance
overhead. With this patch, detaching and reattaching is no longer
necessary.

Signed-off-by: James Newsome <jnewsome@torproject.org>
  • Loading branch information
sporksmith authored and intel-lab-lkp committed Mar 10, 2021
1 parent 144c79e commit 874466f21257b7eb31b17d2bdb19da3f365436d7
Showing 1 changed file with 3 additions and 3 deletions.
@@ -50,7 +50,7 @@ int ptrace_access_vm(struct task_struct *tsk, unsigned long addr,
return 0;

if (!tsk->ptrace ||
(current != tsk->parent) ||
!same_thread_group(current, tsk->parent) ||
((get_dumpable(mm) != SUID_DUMP_USER) &&
!ptracer_capable(tsk, mm->user_ns))) {
mmput(mm);
@@ -193,7 +193,7 @@ static void ptrace_unfreeze_traced(struct task_struct *task)
if (task->state != __TASK_TRACED)
return;

WARN_ON(!task->ptrace || task->parent != current);
WARN_ON(!task->ptrace || !same_thread_group(task->parent, current));

/*
* PTRACE_LISTEN can allow ptrace_trap_notify to wake us up remotely.
@@ -238,7 +238,7 @@ static int ptrace_check_attach(struct task_struct *child, bool ignore_state)
* be changed by us so it's not changing right after this.
*/
read_lock(&tasklist_lock);
if (child->ptrace && child->parent == current) {
if (child->ptrace && same_thread_group(child->parent, current)) {
WARN_ON(child->state == __TASK_TRACED);
/*
* child->sighand can't be NULL, release_task()

0 comments on commit 874466f

Please sign in to comment.