pids: document task_pgrp/task_session is not safe without tasklist/rcu

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Thursday, April 2, 2009 - 10:02 pm

Gitweb:     http://git.kernel.org/linus/6dda81f4384b94930826eded254d8c16f89a9248
Commit:     6dda81f4384b94930826eded254d8c16f89a9248
Parent:     8e654fba4a376f436bdfe361fc5cdbc87ac09b35
Author:     Oleg Nesterov <oleg@redhat.com>
AuthorDate: Thu Apr 2 16:58:35 2009 -0700
Committer:  Linus Torvalds <torvalds@linux-foundation.org>
CommitDate: Thu Apr 2 19:05:02 2009 -0700

    pids: document task_pgrp/task_session is not safe without tasklist/rcu
    
    Even if task == current, it is not safe to dereference the result of
    task_pgrp/task_session.  We can race with another thread which changes the
    special pid via setpgid/setsid.
    
    Document this.  The next 2 patches give an example of the unsafe usage, we
    have more bad users.
    
    [akpm@linux-foundation.org: coding-style fixes]
    Signed-off-by: Oleg Nesterov <oleg@redhat.com>
    Cc: Louis Rilling <Louis.Rilling@kerlabs.com>
    Cc: "Eric W. Biederman" <ebiederm@xmission.com>
    Cc: Pavel Emelyanov <xemul@openvz.org>
    Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
    Cc: Roland McGrath <roland@redhat.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 include/linux/sched.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index b47c94e..722dd31 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1489,6 +1489,11 @@ static inline struct pid *task_tgid(struct task_struct *task)
 	return task->group_leader->pids[PIDTYPE_PID].pid;
 }
 
+/*
+ * Without tasklist or rcu lock it is not safe to dereference
+ * the result of task_pgrp/task_session even if task == current,
+ * we can race with another thread doing sys_setsid/sys_setpgid.
+ */
 static inline struct pid *task_pgrp(struct task_struct *task)
 {
 	return task->group_leader->pids[PIDTYPE_PGID].pid;
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
pids: document task_pgrp/task_session is not safe without ..., Linux Kernel Mailing ..., (Thu Apr 2, 10:02 pm)