proc: fix the threaded /proc/self
authorEric W. Biederman <ebiederm@xmission.com>
Fri, 8 Feb 2008 12:18:35 +0000 (04:18 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 8 Feb 2008 17:22:24 +0000 (09:22 -0800)
Long ago when the CLONE_THREAD support first went it someone thought it
would be wise to point /proc/self at /proc/<tgid> instead of /proc/<pid>.

Given that /proc/<tgid> can return information about a very different task
(if enough things have been unshared) then our current process /proc/<tgid>
seems blatantly wrong.  So far I have yet to think up an example where the
current behavior would be advantageous, and I can see several places where
it is seriously non-intuitive.

We may be stuck with the current broken behavior for backwards
compatibility reasons but lets try fixing our ancient bug for the 2.6.25
time frame and see if anyone screams.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Acked-by: Ingo Molnar <mingo@elte.hu>
Cc: "Guillaume Chazarain" <guichaz@yahoo.fr>
Cc: "Pavel Emelyanov" <xemul@openvz.org>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/proc/base.c

index 75b1979749a579c34720002f44dde9ed42bf43d9..de07e959ff2f9e24c409f758c1d1981a8771ad06 100644 (file)
@@ -2102,22 +2102,22 @@ static int proc_self_readlink(struct dentry *dentry, char __user *buffer,
                              int buflen)
 {
        struct pid_namespace *ns = dentry->d_sb->s_fs_info;
-       pid_t tgid = task_tgid_nr_ns(current, ns);
+       pid_t pid = task_pid_nr_ns(current, ns);
        char tmp[PROC_NUMBUF];
-       if (!tgid)
+       if (!pid)
                return -ENOENT;
-       sprintf(tmp, "%d", tgid);
+       sprintf(tmp, "%d", pid);
        return vfs_readlink(dentry,buffer,buflen,tmp);
 }
 
 static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
        struct pid_namespace *ns = dentry->d_sb->s_fs_info;
-       pid_t tgid = task_tgid_nr_ns(current, ns);
+       pid_t pid = task_pid_nr_ns(current, ns);
        char tmp[PROC_NUMBUF];
-       if (!tgid)
+       if (!pid)
                return ERR_PTR(-ENOENT);
-       sprintf(tmp, "%d", task_tgid_nr_ns(current, ns));
+       sprintf(tmp, "%d", pid);
        return ERR_PTR(vfs_follow_link(nd,tmp));
 }