From: ebiederm@xmission.com (Eric W. Biederman)
To: Andrew Morton <akpm@linux-foundation.org>
Cc: <linux-kernel@vger.kernel.org>,
Alexey Dobriyan <adobriyan@gmail.com>,
Al Viro <viro@ZenIV.linux.org.uk>,
Linux Containers <containers@lists.osdl.org>
Subject: [PATCH 5/7] proc_net: Don't show the wrong /proc/net after unshare.
Date: Thu, 06 Nov 2008 02:56:09 -0800 [thread overview]
Message-ID: <m1skq515ti.fsf_-_@frodo.ebiederm.org> (raw)
In-Reply-To: <m1y6zx15yj.fsf_-_@frodo.ebiederm.org> (Eric W. Biederman's message of "Thu, 06 Nov 2008 02:53:08 -0800")
This is accomplished by dropping the /proc/<pid>/net
dentry when we discover an older version of /proc/net
is mounted upon it. This prevents new lookups from
using the mount and ultimately proc_shrink_automounts
will catch up with it and remove the old mount point.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
fs/proc/base.c | 11 +++++++----
fs/proc/internal.h | 11 +++++++++++
fs/proc/proc_net.c | 33 +++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 9a68fa4..8b0d066 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1487,6 +1487,7 @@ static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
{
struct inode *inode = dentry->d_inode;
struct task_struct *task = get_proc_task(inode);
+ int ret = 0;
if (task) {
if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
task_dumpable(task)) {
@@ -1497,12 +1498,14 @@ static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
inode->i_gid = 0;
}
inode->i_mode &= ~(S_ISUID | S_ISGID);
- security_task_to_inode(task, inode);
+ ret = proc_net_revalidate(task, dentry, nd);
+ if (ret == 1)
+ security_task_to_inode(task, inode);
put_task_struct(task);
- return 1;
}
- d_drop(dentry);
- return 0;
+ if (ret == 0)
+ d_drop(dentry);
+ return ret;
}
static int pid_delete_dentry(struct dentry * dentry)
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index ffa285e..f9f8de6 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -64,6 +64,17 @@ extern const struct file_operations proc_kmsg_operations;
extern const struct file_operations proc_net_operations;
extern const struct inode_operations proc_net_inode_operations;
+#ifdef CONFIG_NET
+extern int proc_net_revalidate(struct task_struct *task, struct dentry *dentry,
+ struct nameidata *nd);
+#else
+static inline int proc_net_revalidate(struct task_struct *t, struct dentry *d,
+ struct nameidata *nd)
+{
+ return 1;
+}
+#endif
+
void free_proc_entry(struct proc_dir_entry *de);
void proc_init_inodecache(void);
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
index 57e0f22..4a7551a 100644
--- a/fs/proc/proc_net.c
+++ b/fs/proc/proc_net.c
@@ -174,6 +174,39 @@ const struct inode_operations proc_net_inode_operations = {
.follow_link = proc_net_follow_link,
};
+int proc_net_revalidate(struct task_struct *task, struct dentry *dentry,
+ struct nameidata *nd)
+{
+ struct inode *inode = dentry->d_inode;
+ struct dentry *tdentry;
+ struct vfsmount *tmnt;
+ int ret = 1;
+
+ /* Are we talking about a proc/net mount point? */
+ if (!nd || (inode->i_op != &proc_net_inode_operations))
+ goto out;
+
+ /* If the wrong filesystem is mounted on
+ * /proc/<pid>/net report the dentry is invalid.
+ */
+ tdentry = dget(dentry);
+ tmnt = mntget(nd->path.mnt);
+ if (follow_down(&tmnt, &tdentry)) {
+ struct nsproxy *ns;
+ rcu_read_lock();
+ ns = task_nsproxy(task);
+ if ((ns == NULL) ||
+ (tmnt->mnt_sb->s_magic != PROC_NET_SUPER_MAGIC) ||
+ (tmnt->mnt_sb->s_fs_info != ns->net_ns))
+ ret = 0;
+ rcu_read_unlock();
+ }
+ mntput(tmnt);
+ dput(tdentry);
+out:
+ return ret;
+}
+
struct proc_dir_entry *proc_net_fops_create(struct net *net,
const char *name, mode_t mode, const struct file_operations *fops)
{
--
1.5.3.rc6.17.g1911
next prev parent reply other threads:[~2008-11-06 11:05 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-06 10:38 [PATCH 1/7] vfs: Fix shrink_submounts Eric W. Biederman
2008-11-06 10:48 ` [PATCH 2/7] proc: Implement support for automounts in task directories Eric W. Biederman
2008-11-06 10:49 ` [PATCH 3/7] proc: Support multiple filesystems using the proc generic infrastructure Eric W. Biederman
2008-11-06 10:53 ` [PATCH 4/7] proc: Make /proc/net it's own filesystem Eric W. Biederman
2008-11-06 10:56 ` Eric W. Biederman [this message]
2008-11-06 10:57 ` [PATCH 6/7] proc_net: Simplify network namespace lookup Eric W. Biederman
2008-11-06 10:58 ` [PATCH 7/7] proc: Cleanup proc_flush_task Eric W. Biederman
2008-11-07 1:25 ` [PATCH 2/7] proc: Implement support for automounts in task directories Andrew Morton
2008-11-07 2:02 ` Eric W. Biederman
2008-11-07 1:26 ` Andrew Morton
2008-11-07 2:05 ` Eric W. Biederman
2008-11-07 2:49 ` Andrew Morton
2008-11-07 3:51 ` Eric W. Biederman
2008-11-07 4:28 ` Andrew Morton
2008-11-07 15:51 ` Eric W. Biederman
2008-11-07 16:05 ` Andrew Morton
2008-11-07 16:58 ` Eric W. Biederman
2008-11-13 23:39 ` Eric W. Biederman
2008-11-19 0:07 ` Alexey Dobriyan
2008-11-19 2:35 ` Alexey Dobriyan
2008-11-19 13:20 ` Eric W. Biederman
2008-11-07 4:41 ` Alexey Dobriyan
2008-11-07 16:04 ` [PATCH] proc: Supply proc_shrink_automounts when CONFIG_PROC_FS=N Eric W. Biederman
2008-11-07 1:22 ` [PATCH 1/7] vfs: Fix shrink_submounts Andrew Morton
2008-11-07 2:06 ` Eric W. Biederman
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=m1skq515ti.fsf_-_@frodo.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=containers@lists.osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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