fix the "remove task_ppid_nr_ns" commit

2008-01-14 Thread Linux Kernel Mailing List
Gitweb: 
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=a98fdcef941e107eeabae622d85a1f476f25a160
Commit: a98fdcef941e107eeabae622d85a1f476f25a160
Parent: 4fd3670eb1d3c33e8952cf1e79edbb2d517dcfb5
Author: Oleg Nesterov <[EMAIL PROTECTED]>
AuthorDate: Tue Jan 15 00:02:37 2008 +0300
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Mon Jan 14 13:23:00 2008 -0800

    fix the "remove task_ppid_nr_ns" commit

Commit 84427eaef1fb91704c7112bdb598c810003b99f3 (remove task_ppid_nr_ns)
moved the task_tgid_nr_ns(task->real_parent) outside of lock_task_sighand().
This is wrong, ->real_parent could be freed/reused.

Both ->parent/real_parent point to nothing after __exit_signal() because
we remove the child from ->children list, and thus the child can't be
reparented when its parent exits.

rcu_read_lock() protects ->parent/real_parent, but _only_ if we know it was
valid before we take rcu lock.

Revert this part of the patch.

Signed-off-by: Oleg Nesterov <[EMAIL PROTECTED]>
Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 fs/proc/array.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 810eb8f..eb97f28 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -426,7 +426,6 @@ static int do_task_stat(struct task_struct *task, char 
*buffer, int whole)
cgtime = gtime = cputime_zero;
 
rcu_read_lock();
-   ppid = task_tgid_nr_ns(task->real_parent, ns);
if (lock_task_sighand(task, &flags)) {
struct signal_struct *sig = task->signal;
 
@@ -465,6 +464,7 @@ static int do_task_stat(struct task_struct *task, char 
*buffer, int whole)
}
 
sid = task_session_nr_ns(task, ns);
+   ppid = task_tgid_nr_ns(task->real_parent, ns);
pgid = task_pgrp_nr_ns(task, ns);
 
unlock_task_sighand(task, &flags);
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


remove task_ppid_nr_ns

2008-01-13 Thread Linux Kernel Mailing List
Gitweb: 
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=84427eaef1fb91704c7112bdb598c810003b99f3
Commit: 84427eaef1fb91704c7112bdb598c810003b99f3
Parent: 974a9f0b47da74e28f68b9c8645c3786aa5ace1a
Author: Roland McGrath <[EMAIL PROTECTED]>
AuthorDate: Thu Jan 10 12:52:04 2008 -0800
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Sun Jan 13 09:56:43 2008 -0800

remove task_ppid_nr_ns

task_ppid_nr_ns is called in three places.  One of these should never
have called it.  In the other two, using it broke the existing
semantics.  This was presumably accidental.  If the function had not
been there, it would have been much more obvious to the eye that those
patches were changing the behavior.  We don't need this function.

In task_state, the pid of the ptracer is not the ppid of the ptracer.

In do_task_stat, ppid is the tgid of the real_parent, not its pid.
I also moved the call outside of lock_task_sighand, since it doesn't
need it.

In sys_getppid, ppid is the tgid of the real_parent, not its pid.

Signed-off-by: Roland McGrath <[EMAIL PROTECTED]>
Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 fs/proc/array.c   |4 ++--
 include/linux/sched.h |   13 -
 kernel/timer.c|2 +-
 3 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 65c62e1..810eb8f 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -169,7 +169,7 @@ static inline char *task_state(struct task_struct *p, char 
*buffer)
ppid = pid_alive(p) ?
task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
tpid = pid_alive(p) && p->ptrace ?
-   task_ppid_nr_ns(rcu_dereference(p->parent), ns) : 0;
+   task_pid_nr_ns(rcu_dereference(p->parent), ns) : 0;
buffer += sprintf(buffer,
"State:\t%s\n"
"Tgid:\t%d\n"
@@ -426,6 +426,7 @@ static int do_task_stat(struct task_struct *task, char 
*buffer, int whole)
cgtime = gtime = cputime_zero;
 
rcu_read_lock();
+   ppid = task_tgid_nr_ns(task->real_parent, ns);
if (lock_task_sighand(task, &flags)) {
struct signal_struct *sig = task->signal;
 
@@ -465,7 +466,6 @@ static int do_task_stat(struct task_struct *task, char 
*buffer, int whole)
 
sid = task_session_nr_ns(task, ns);
pgid = task_pgrp_nr_ns(task, ns);
-   ppid = task_ppid_nr_ns(task, ns);
 
unlock_task_sighand(task, &flags);
}
diff --git a/include/linux/sched.h b/include/linux/sched.h
index ac3d496..cc14656 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1255,13 +1255,6 @@ struct pid_namespace;
  *
  * set_task_vxid()   : assigns a virtual id to a task;
  *
- * task_ppid_nr_ns() : the parent's id as seen from the namespace specified.
- * the result depends on the namespace and whether the
- * task in question is the namespace's init. e.g. for the
- * namespace's init this will return 0 when called from
- * the namespace of this init, or appropriate id otherwise.
- *
- *
  * see also pid_nr() etc in include/linux/pid.h
  */
 
@@ -1317,12 +1310,6 @@ static inline pid_t task_session_vnr(struct task_struct 
*tsk)
 }
 
 
-static inline pid_t task_ppid_nr_ns(struct task_struct *tsk,
-   struct pid_namespace *ns)
-{
-   return pid_nr_ns(task_pid(rcu_dereference(tsk->real_parent)), ns);
-}
-
 /**
  * pid_alive - check that a task structure is not stale
  * @p: Task structure to be checked.
diff --git a/kernel/timer.c b/kernel/timer.c
index d4527dc..26671f4 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -978,7 +978,7 @@ asmlinkage long sys_getppid(void)
int pid;
 
rcu_read_lock();
-   pid = task_ppid_nr_ns(current, current->nsproxy->pid_ns);
+   pid = task_tgid_nr_ns(current->real_parent, current->nsproxy->pid_ns);
rcu_read_unlock();
 
return pid;
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html