Skip to contentSkip to conversation

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

PATCH In review Oleg Nesterov 1 participant 1 message Jan 16, 2009 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 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.

include/linux/sched.h renamed from include/linux/sched.h~SP_1_COMMENT +7 -0
@@ -1449,6 +1449,13 @@ static inline struct pid *task_tgid(stru
 	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;