summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@tv-sign.ru>2006-10-02 09:18:59 (GMT)
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-02 14:57:25 (GMT)
commit1a657f78dcc8ea7c53eaa1f2a45ea2315738c15f (patch)
treea19972027792082fed505c8d540f7d877e37c0ab
parent1c0d04c9e44f4a248335c33d2be7c7f7b06ff359 (diff)
downloadlinux-1a657f78dcc8ea7c53eaa1f2a45ea2315738c15f.tar.xz
[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>
-rw-r--r--fs/proc/base.c4
-rw-r--r--include/linux/pid.h2
-rw-r--r--kernel/pid.c9
3 files changed, 13 insertions, 2 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index a317eb2..82da55b 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -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;
diff --git a/include/linux/pid.h b/include/linux/pid.h
index 7e39767..17b9e04 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -68,6 +68,8 @@ extern struct task_struct *FASTCALL(pid_task(struct pid *pid, enum pid_type));
extern struct task_struct *FASTCALL(get_pid_task(struct pid *pid,
enum pid_type));
+extern struct pid *get_task_pid(struct task_struct *task, enum pid_type type);
+
/*
* attach_pid() and detach_pid() must be called with the tasklist_lock
* write-held.
diff --git a/kernel/pid.c b/kernel/pid.c
index e4779bb..b914392 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -304,6 +304,15 @@ struct task_struct *find_task_by_pid_type(int type, int nr)
EXPORT_SYMBOL(find_task_by_pid_type);
+struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
+{
+ struct pid *pid;
+ rcu_read_lock();
+ pid = get_pid(task->pids[type].pid);
+ rcu_read_unlock();
+ return pid;
+}
+
struct task_struct *fastcall get_pid_task(struct pid *pid, enum pid_type type)
{
struct task_struct *result;