linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jim Newsome <jnewsome@torproject.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: linux-kernel@vger.kernel.org, Jim Newsome <jnewsome@torproject.org>
Subject: [PATCH] ptrace: Allow other threads to access tracee
Date: Wed, 10 Mar 2021 14:59:08 -0600	[thread overview]
Message-ID: <20210310205908.23447-1-jnewsome@torproject.org> (raw)

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>
---
 kernel/ptrace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 821cf1723814..bd9968a35784 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -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()
-- 
2.30.1


             reply	other threads:[~2021-03-10 21:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10 20:59 Jim Newsome [this message]
2021-03-11  1:31 ` [PATCH] ptrace: Allow other threads to access tracee kernel test robot
2021-03-11 15:21 ` Oleg Nesterov
2021-03-11 16:49   ` Jim Newsome
2021-03-12 17:07     ` Oleg Nesterov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210310205908.23447-1-jnewsome@torproject.org \
    --to=jnewsome@torproject.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).