summaryrefslogtreecommitdiffstats
path: root/kernel/pid.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2013-07-03 18:08:31 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 19:08:03 -0400
commit8190773985141f063e1d6dc10200527c655abfb5 (patch)
tree5c148834f047748dfa2ce3500236b89656976567 /kernel/pid.c
parent80628ca06c5d42929de6bc22c0a41589a834d151 (diff)
kernel/fork.c:copy_process(): don't add the uninitialized child to thread/task/pid lists
copy_process() adds the new child to thread_group/init_task.tasks list and then does attach_pid(child, PIDTYPE_PID). This means that the lockless next_thread() or next_task() can see this thread with the wrong pid. Say, "ls /proc/pid/task" can list the same inode twice. We could move attach_pid(child, PIDTYPE_PID) up, but in this case find_task_by_vpid() can find the new thread before it was fully initialized. And this is already true for PIDTYPE_PGID/PIDTYPE_SID, With this patch copy_process() initializes child->pids[*].pid first, then calls attach_pid() to insert the task into the pid->tasks list. attach_pid() no longer need the "struct pid*" argument, it is always called after pid_link->pid was already set. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Michal Hocko <mhocko@suse.cz> Cc: Pavel Emelyanov <xemul@parallels.com> Cc: Sergey Dyasly <dserrg@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/pid.c')
-rw-r--r--kernel/pid.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/kernel/pid.c b/kernel/pid.c
index 0db3e791a06d..61980cefb1f5 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -373,14 +373,10 @@ EXPORT_SYMBOL_GPL(find_vpid);
373/* 373/*
374 * attach_pid() must be called with the tasklist_lock write-held. 374 * attach_pid() must be called with the tasklist_lock write-held.
375 */ 375 */
376void attach_pid(struct task_struct *task, enum pid_type type, 376void attach_pid(struct task_struct *task, enum pid_type type)
377 struct pid *pid)
378{ 377{
379 struct pid_link *link; 378 struct pid_link *link = &task->pids[type];
380 379 hlist_add_head_rcu(&link->node, &link->pid->tasks[type]);
381 link = &task->pids[type];
382 link->pid = pid;
383 hlist_add_head_rcu(&link->node, &pid->tasks[type]);
384} 380}
385 381
386static void __change_pid(struct task_struct *task, enum pid_type type, 382static void __change_pid(struct task_struct *task, enum pid_type type,
@@ -412,7 +408,7 @@ void change_pid(struct task_struct *task, enum pid_type type,
412 struct pid *pid) 408 struct pid *pid)
413{ 409{
414 __change_pid(task, type, pid); 410 __change_pid(task, type, pid);
415 attach_pid(task, type, pid); 411 attach_pid(task, type);
416} 412}
417 413
418/* transfer_pid is an optimization of attach_pid(new), detach_pid(old) */ 414/* transfer_pid is an optimization of attach_pid(new), detach_pid(old) */