Skip to content

Commit 488e5bc

Browse files
ebiedermLinus Torvalds
authored andcommitted
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>
1 parent df5f831 commit 488e5bc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

fs/proc/base.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,15 +2101,23 @@ static const struct file_operations proc_coredump_filter_operations = {
21012101
static int proc_self_readlink(struct dentry *dentry, char __user *buffer,
21022102
int buflen)
21032103
{
2104+
struct pid_namespace *ns = dentry->d_sb->s_fs_info;
2105+
pid_t tgid = task_tgid_nr_ns(current, ns);
21042106
char tmp[PROC_NUMBUF];
2105-
sprintf(tmp, "%d", task_tgid_vnr(current));
2107+
if (!tgid)
2108+
return -ENOENT;
2109+
sprintf(tmp, "%d", tgid);
21062110
return vfs_readlink(dentry,buffer,buflen,tmp);
21072111
}
21082112

21092113
static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
21102114
{
2115+
struct pid_namespace *ns = dentry->d_sb->s_fs_info;
2116+
pid_t tgid = task_tgid_nr_ns(current, ns);
21112117
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));
21132121
return ERR_PTR(vfs_follow_link(nd,tmp));
21142122
}
21152123

0 commit comments

Comments
 (0)