mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Pavel Emelyanov <xemul@openvz.org>,
	linux-kernel@vger.kernel.org, Oleg Nesterov <oleg@tv-sign.ru>
Subject: [PATCH] proc: Proper pidns handling for /proc/self
Date: Mon, 19 Nov 2007 15:30:06 -0700	[thread overview]
Message-ID: <m1ejeluavl.fsf@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <20071117183109.GA2605@tv-sign.ru> (Oleg Nesterov's message of "Sat, 17 Nov 2007 21:31:09 +0300")


Currently if you access a /proc that is not mounted with your
processes current pid namespace /proc/self will point at a completely
different process.  Ouch!.

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>
---
 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 7e8eca4..34a1821 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2049,15 +2049,23 @@ static const struct file_operations proc_coredump_filter_operations = {
 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);
 	char tmp[PROC_NUMBUF];
-	sprintf(tmp, "%d", task_tgid_vnr(current));
+	if (!tgid)
+		return -ENOENT;
+	sprintf(tmp, "%d", tgid);
 	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);
 	char tmp[PROC_NUMBUF];
-	sprintf(tmp, "%d", task_tgid_vnr(current));
+	if (!tgid)
+		return ERR_PTR(-ENOENT);
+	sprintf(tmp, "%d", task_tgid_nr_ns(current, ns));
 	return ERR_PTR(vfs_follow_link(nd,tmp));
 }
 
-- 
1.5.3.rc6.17.g1911


      parent reply	other threads:[~2007-11-19 22:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-17 18:31 [PATCH] do_task_stat: don't use task_pid_nr_ns() lockless Oleg Nesterov
2007-11-17 20:11 ` Eric W. Biederman
2007-11-19  9:30   ` Pavel Emelyanov
2007-11-19 18:04     ` Eric W. Biederman
2007-11-19  9:31 ` Pavel Emelyanov
2007-11-19 21:59 ` [PATCH 0/4] proc: Cleanup status files Eric W. Biederman
2007-11-19 22:04   ` [PATCH 1/4] proc: Implement proc_single_file_operations Eric W. Biederman
2007-11-19 22:06     ` [PATCH 2/4] proc: Rewrite do_task_stat to correctly handle pid namespaces Eric W. Biederman
2007-11-19 22:10       ` [PATCH 3/4] proc: seqfile convert proc_pid_status to properly " Eric W. Biederman
2007-11-19 22:13         ` [PATCH] proc: seqfile convert proc_pid_statm Eric W. Biederman
2007-11-20 10:34   ` [PATCH 0/4] proc: Cleanup status files Pavel Emelyanov
2007-11-19 22:30 ` Eric W. Biederman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1ejeluavl.fsf@ebiederm.dsl.xmission.com \
    --to=ebiederm@xmission.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@tv-sign.ru \
    --cc=xemul@openvz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®