]> Git Repo - linux.git/commitdiff
pids: de_thread: don't clear session/pgrp pids for the old leader
authorOleg Nesterov <[email protected]>
Wed, 30 Apr 2008 07:54:25 +0000 (00:54 -0700)
committerLinus Torvalds <[email protected]>
Wed, 30 Apr 2008 15:29:48 +0000 (08:29 -0700)
Based on Eric W. Biederman's idea.

Unless task == current, without tasklist_lock held task_session()/task_pgrp()
can return NULL if the caller races with de_thread() which switches the group
leader.

Change transfer_pid() to not clear old->pids[type].pid for the old leader.
This means that its .pid can point to "nowhere", but this is already true for
sub-threads, and the old leader is not group_leader() any longer.  IOW, with
or without this change we can't trust task's special pids unless it is the
group leader.

With this change the following code

rcu_read_lock();
task = find_task_by_xxx();
do_something(task_pgrp(task), task_session(task));
rcu_read_unlock();

can't race with exec and hit the NULL pid.

Signed-off-by: Oleg Nesterov <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: Roland McGrath <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
kernel/pid.c

index a9ae9f7fb229fd5b34d6d963d080f5c047714708..e9a31d362b2805f30cc4cb5ef67a6fe0ec14ee3d 100644 (file)
@@ -354,7 +354,6 @@ void transfer_pid(struct task_struct *old, struct task_struct *new,
 {
        new->pids[type].pid = old->pids[type].pid;
        hlist_replace_rcu(&old->pids[type].node, &new->pids[type].node);
-       old->pids[type].pid = NULL;
 }
 
 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
This page took 0.057977 seconds and 4 git commands to generate.