public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Roland McGrath <roland@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 9/12 v2] ptrace: introduce ptrace_tracer() helper
Date: Thu, 28 May 2009 13:35:57 +0200	[thread overview]
Message-ID: <20090528113557.GA18715@redhat.com> (raw)

Introduce ptrace_tracer() to simplify/cleanup the code which needs the
tracer and checks task_ptrace(). From now nobody else uses ->pt_tracer
except ptrace_link/ptrace_unlink.

 include/linux/ptrace.h |   17 ++++++++++++-----
 kernel/ptrace.c        |    2 +-
 kernel/signal.c        |   20 +++++++++-----------
 3 files changed, 22 insertions(+), 17 deletions(-)

--- PTRACE/include/linux/ptrace.h~8_PT_TRACER	2009-05-28 08:41:11.000000000 +0200
+++ PTRACE/include/linux/ptrace.h	2009-05-28 10:03:01.000000000 +0200
@@ -119,10 +119,17 @@ static inline int task_ptrace(struct tas
 		task->ptrace_ctx->flags : 0;
 }
 
-static inline int ptrace_reparented(struct task_struct *child)
+static inline struct task_struct *ptrace_tracer(struct task_struct *task)
 {
-	return unlikely(task_ptrace(child)) &&
-		child->ptrace_ctx->tracer != child->real_parent;
+	if (task->ptrace_ctx)
+		return task->ptrace_ctx->tracer;
+	return NULL;
+}
+
+static inline bool ptrace_reparented(struct task_struct *child)
+{
+	struct task_struct *tracer = ptrace_tracer(child);
+	return unlikely(tracer) && tracer != child->real_parent;
 }
 
 static inline void ptrace_unlink(struct task_struct *child)
@@ -170,9 +177,9 @@ static inline void ptrace_init_task(stru
 	INIT_LIST_HEAD(&child->ptrace_entry);
 	INIT_LIST_HEAD(&child->ptraced);
 
-	if (unlikely(child->ptrace_ctx) && task_ptrace(current))
+	if (unlikely(child->ptrace_ctx) && ptrace_tracer(current))
 		ptrace_link(child, task_ptrace(current),
-				current->ptrace_ctx->tracer);
+				ptrace_tracer(current));
 }
 
 /**
--- PTRACE/kernel/ptrace.c~8_PT_TRACER	2009-05-28 08:41:11.000000000 +0200
+++ PTRACE/kernel/ptrace.c	2009-05-28 10:42:55.000000000 +0200
@@ -108,7 +108,7 @@ int ptrace_check_attach(struct task_stru
 	 * be changed by us so it's not changing right after this.
 	 */
 	read_lock(&tasklist_lock);
-	if (task_ptrace(child) && child->ptrace_ctx->tracer == current) {
+	if (ptrace_tracer(child) == current) {
 		ret = 0;
 		/*
 		 * child->sighand can't be NULL, release_task()
--- PTRACE/kernel/signal.c~8_PT_TRACER	2009-05-28 08:43:12.000000000 +0200
+++ PTRACE/kernel/signal.c	2009-05-28 10:03:01.000000000 +0200
@@ -1411,10 +1411,7 @@ int do_notify_parent(struct task_struct 
 	BUG_ON(!task_ptrace(tsk) &&
 	       (tsk->group_leader != tsk || !thread_group_empty(tsk)));
 
-	if (task_ptrace(tsk))
-		parent = tsk->ptrace_ctx->tracer;
-	else
-		parent = tsk->real_parent;
+	parent = ptrace_tracer(tsk) ?: tsk->real_parent;
 
 	info.si_signo = sig;
 	info.si_errno = 0;
@@ -1489,9 +1486,8 @@ static void do_notify_parent_cldstop(str
 	struct task_struct *parent;
 	struct sighand_struct *sighand;
 
-	if (task_ptrace(tsk))
-		parent = tsk->ptrace_ctx->tracer;
-	else {
+	parent = ptrace_tracer(tsk);
+	if (likely(!parent)) {
 		tsk = tsk->group_leader;
 		parent = tsk->real_parent;
 	}
@@ -1538,7 +1534,9 @@ static void do_notify_parent_cldstop(str
 
 static inline int may_ptrace_stop(void)
 {
-	if (!likely(task_ptrace(current)))
+	struct task_struct *tracer = ptrace_tracer(current);
+
+	if (!likely(tracer))
 		return 0;
 	/*
 	 * Are we in the middle of do_coredump?
@@ -1550,7 +1548,7 @@ static inline int may_ptrace_stop(void)
 	 * is safe to enter schedule().
 	 */
 	if (unlikely(current->mm->core_state) &&
-	    unlikely(current->mm == current->ptrace_ctx->tracer->mm))
+	    unlikely(current->mm == tracer->mm))
 		return 0;
 
 	return 1;
@@ -1783,8 +1781,8 @@ static int ptrace_signal(int signr, sigi
 		info->si_code = SI_USER;
 
 		rcu_read_lock();
-		tracer = current->ptrace_ctx->tracer;
-		if (task_ptrace(current)) {
+		tracer = ptrace_tracer(current);
+		if (likely(tracer)) {
 			info->si_pid = task_pid_vnr(tracer);
 			info->si_uid = task_uid(tracer);
 		} else {


                 reply	other threads:[~2009-05-28 11:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20090528113557.GA18715@redhat.com \
    --to=oleg@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=roland@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