diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2008-02-08 07:18:34 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-08 12:22:24 -0500 |
commit | 488e5bc4560d0b510c1ddc451c51a6cc14e3a930 (patch) | |
tree | 0b0df343406ff47578280e01388fc997064c8aa9 /fs/proc/base.c | |
parent | df5f8314ca30d6a76735748e5ba4ca9809c0f434 (diff) |
proc: proper pidns handling for /proc/self
Currently if you access a /proc that is not mounted with your processes
current pid namespace /proc/self will point at a completely random task.
This patch fixes /proc/self to point to the current process if it is
available in the particular mount of /proc or to return -ENOENT if the
current process is not visible.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Cc: Pavel Emelyanov <xemul@openvz.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r-- | fs/proc/base.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 8a19a8a1a3e6..75b1979749a5 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -2101,15 +2101,23 @@ static const struct file_operations proc_coredump_filter_operations = { | |||
2101 | static int proc_self_readlink(struct dentry *dentry, char __user *buffer, | 2101 | static int proc_self_readlink(struct dentry *dentry, char __user *buffer, |
2102 | int buflen) | 2102 | int buflen) |
2103 | { | 2103 | { |
2104 | struct pid_namespace *ns = dentry->d_sb->s_fs_info; | ||
2105 | pid_t tgid = task_tgid_nr_ns(current, ns); | ||
2104 | char tmp[PROC_NUMBUF]; | 2106 | char tmp[PROC_NUMBUF]; |
2105 | sprintf(tmp, "%d", task_tgid_vnr(current)); | 2107 | if (!tgid) |
2108 | return -ENOENT; | ||
2109 | sprintf(tmp, "%d", tgid); | ||
2106 | return vfs_readlink(dentry,buffer,buflen,tmp); | 2110 | return vfs_readlink(dentry,buffer,buflen,tmp); |
2107 | } | 2111 | } |
2108 | 2112 | ||
2109 | static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd) | 2113 | static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd) |
2110 | { | 2114 | { |
2115 | struct pid_namespace *ns = dentry->d_sb->s_fs_info; | ||
2116 | pid_t tgid = task_tgid_nr_ns(current, ns); | ||
2111 | char tmp[PROC_NUMBUF]; | 2117 | char tmp[PROC_NUMBUF]; |
2112 | sprintf(tmp, "%d", task_tgid_vnr(current)); | 2118 | if (!tgid) |
2119 | return ERR_PTR(-ENOENT); | ||
2120 | sprintf(tmp, "%d", task_tgid_nr_ns(current, ns)); | ||
2113 | return ERR_PTR(vfs_follow_link(nd,tmp)); | 2121 | return ERR_PTR(vfs_follow_link(nd,tmp)); |
2114 | } | 2122 | } |
2115 | 2123 | ||