[PATCH] introduce get_task_pid() to fix unsafe get_pid()

proc_pid_make_inode:

	ei->pid = get_pid(task_pid(task));

I think this is not safe.  get_pid() can be preempted after checking "pid
!= NULL".  Then the task exits, does detach_pid(), and RCU frees the pid.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Oleg Nesterov
2006-10-02 02:18:59 -07:00
committed by Linus Torvalds
parent 1c0d04c9e4
commit 1a657f78dc
3 changed files with 13 additions and 2 deletions

View File

@@ -958,7 +958,7 @@ static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_st
/*
* grab the reference to task.
*/
ei->pid = get_pid(task_pid(task));
ei->pid = get_task_pid(task, PIDTYPE_PID);
if (!ei->pid)
goto out_unlock;
@@ -1677,7 +1677,7 @@ static struct dentry *proc_base_instantiate(struct inode *dir,
/*
* grab the reference to the task.
*/
ei->pid = get_pid(task_pid(task));
ei->pid = get_task_pid(task, PIDTYPE_PID);
if (!ei->pid)
goto out_iput;