lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Date:	Sun, 31 May 2009 00:38:41 +0200
From:	Oleg Nesterov <oleg@...hat.com>
To:	Roland McGrath <roland@...hat.com>
Cc:	Christoph Hellwig <hch@...radead.org>, Ingo Molnar <mingo@...e.hu>,
	linux-kernel@...r.kernel.org
Subject: [RFC PATCH 09/12 v3] ptrace: introduce ptrace_tracer() helper

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

Signed-off-by: Oleg Nesterov <oleg@...hat.com>
---

 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~09_PT_TRACER	2009-05-30 23:32:47.000000000 +0200
+++ PTRACE/include/linux/ptrace.h	2009-05-30 23:50:49.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~09_PT_TRACER	2009-05-30 23:32:47.000000000 +0200
+++ PTRACE/kernel/ptrace.c	2009-05-30 23:55:26.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~09_PT_TRACER	2009-05-30 23:32:47.000000000 +0200
+++ PTRACE/kernel/signal.c	2009-05-30 23:50:49.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 {

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ