Skip to content

Commit 65450ce

Browse files
Oleg Nesterovtorvalds
authored andcommitted
pids: de_thread: don't clear session/pgrp pids for the old leader
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 <oleg@tv-sign.ru> Cc: "Eric W. Biederman" <ebiederm@xmission.com> 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>
1 parent 5cd2045 commit 65450ce

1 file changed

Lines changed: 0 additions & 1 deletion

File tree

‎kernel/pid.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ void transfer_pid(struct task_struct *old, struct task_struct *new,
354354
{
355355
new->pids[type].pid = old->pids[type].pid;
356356
hlist_replace_rcu(&old->pids[type].node, &new->pids[type].node);
357-
old->pids[type].pid = NULL;
358357
}
359358

360359
struct task_struct *pid_task(struct pid *pid, enum pid_type type)

0 commit comments

Comments
 (0)