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 7/12 v2] ptrace: change __ptrace_link() to set ->flags, rename to ptrace_link()
Date: Thu, 28 May 2009 13:35:52 +0200	[thread overview]
Message-ID: <20090528113552.GA18705@redhat.com> (raw)

Every caller of __ptrace_link() must set ->flags, move this code into
this helper and rename it to ptrace_link().

Note that we do not pass PT_PTRACED, it is always set by ptrace_link().

 include/linux/ptrace.h |   11 +++++------
 kernel/ptrace.c        |   25 +++++++++++--------------
 2 files changed, 16 insertions(+), 20 deletions(-)

--- PTRACE/include/linux/ptrace.h~6_PTRACE_LINK	2009-05-28 08:29:11.000000000 +0200
+++ PTRACE/include/linux/ptrace.h	2009-05-28 08:35:41.000000000 +0200
@@ -91,8 +91,8 @@ extern void ptrace_disable(struct task_s
 extern int ptrace_check_attach(struct task_struct *task, int kill);
 extern int ptrace_request(struct task_struct *child, long request, long addr, long data);
 extern void ptrace_notify(int exit_code);
-extern void __ptrace_link(struct task_struct *child,
-			  struct task_struct *new_parent);
+extern void ptrace_link(struct task_struct *child, unsigned int flags,
+			struct task_struct *tracer);
 extern void __ptrace_unlink(struct task_struct *child);
 extern void exit_ptrace(struct task_struct *tracer);
 extern void ptrace_fork(struct task_struct *task, unsigned long clone_flags);
@@ -168,10 +168,9 @@ static inline void ptrace_init_task(stru
 	INIT_LIST_HEAD(&child->ptrace_entry);
 	INIT_LIST_HEAD(&child->ptraced);
 	child->parent = child->real_parent;
-	if (unlikely(child->ptrace_ctx) && task_ptrace(current)) {
-		child->ptrace_ctx->flags = task_ptrace(current);
-		__ptrace_link(child, current->parent);
-	}
+
+	if (unlikely(child->ptrace_ctx) && task_ptrace(current))
+		ptrace_link(child, task_ptrace(current), current->parent);
 }
 
 /**
--- PTRACE/kernel/ptrace.c~6_PTRACE_LINK	2009-05-28 08:23:13.000000000 +0200
+++ PTRACE/kernel/ptrace.c	2009-05-28 08:35:41.000000000 +0200
@@ -40,11 +40,14 @@ void ptrace_fork(struct task_struct *chi
  *
  * Must be called with the tasklist lock write-held.
  */
-void __ptrace_link(struct task_struct *child, struct task_struct *new_parent)
+void ptrace_link(struct task_struct *child, unsigned int flags,
+			struct task_struct *tracer)
 {
+	child->ptrace_ctx->flags = flags | PT_PTRACED;
+
 	BUG_ON(!list_empty(&child->ptrace_entry));
-	list_add(&child->ptrace_entry, &new_parent->ptraced);
-	child->parent = new_parent;
+	list_add(&child->ptrace_entry, &tracer->ptraced);
+	child->parent = tracer;
 }
 
 /*
@@ -202,7 +205,7 @@ int alloc_ptrace_context(struct task_str
 
 int ptrace_attach(struct task_struct *task)
 {
-	int retval;
+	int retval, flags;
 
 	audit_ptrace(task);
 
@@ -236,11 +239,8 @@ int ptrace_attach(struct task_struct *ta
 	if (task_ptrace(task))
 		goto unlock_tasklist;
 
-	task->ptrace_ctx->flags = PT_PTRACED;
-	if (capable(CAP_SYS_PTRACE))
-		task->ptrace_ctx->flags |= PT_PTRACE_CAP;
-
-	__ptrace_link(task, current);
+	flags = capable(CAP_SYS_PTRACE) ? PT_PTRACE_CAP : 0;
+	ptrace_link(task, flags, current);
 	send_sig_info(SIGSTOP, SEND_SIG_FORCED, task);
 
 	retval = 0;
@@ -255,7 +255,6 @@ out:
 /**
  * ptrace_traceme  --  helper for PTRACE_TRACEME
  *
- * Performs checks and sets PT_PTRACED.
  * Should be used by all ptrace implementations for PTRACE_TRACEME.
  */
 int ptrace_traceme(void)
@@ -275,10 +274,8 @@ int ptrace_traceme(void)
 		 * exit_ptrace(). Otherwise we don't report the error but
 		 * pretend ->real_parent untraces us right after return.
 		 */
-		if (!ret && !(current->real_parent->flags & PF_EXITING)) {
-			current->ptrace_ctx->flags = PT_PTRACED;
-			__ptrace_link(current, current->real_parent);
-		}
+		if (!ret && !(current->real_parent->flags & PF_EXITING))
+			ptrace_link(current, 0, current->real_parent);
 	}
 	write_unlock_irq(&tasklist_lock);
 


                 reply	other threads:[~2009-05-28 11:42 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=20090528113552.GA18705@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