From: Oleg Nesterov <oleg@tv-sign.ru>
Date: Fri, 8 Feb 2008 12:19:19 +0000 (-0800)
Subject: uglify while_each_pid_task() to make sure we don't count the execing pricess twice
X-Git-Tag: v2.6.25-rc1~207
X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=46f382d2b69d2221086b823f0dbc8f32c027cac2;p=linux-2.6-omap-h63xx.git

uglify while_each_pid_task() to make sure we don't count the execing pricess twice

There is a window when de_thread() switches the leader and drops
tasklist_lock.  In that window do_each_pid_task(PIDTYPE_PID) finds both new
and old leaders.

The problem is pretty much theoretical and probably can be ignored.  Currently
the only users of do_each_pid_task(PIDTYPE_PID) are send_sigio/send_sigurg, so
they can send the signal to the same process twice.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Davide Libenzi <davidel@xmailserver.org>
Cc: Pavel Emelyanov <xemul@openvz.org>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

diff --git a/include/linux/pid.h b/include/linux/pid.h
index b91f4732dc1..f84d532b5d2 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -152,7 +152,13 @@ pid_t pid_vnr(struct pid *pid);
 			hlist_for_each_entry_rcu((task), pos___,	\
 				&pid->tasks[type], pids[type].node) {
 
+			/*
+			 * Both old and new leaders may be attached to
+			 * the same pid in the middle of de_thread().
+			 */
 #define while_each_pid_task(pid, type, task)				\
+				if (type == PIDTYPE_PID)		\
+					break;				\
 			}						\
 	} while (0)