From: Ian Kent <ikent@redhat.com>
To: Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: "J. Bruce Fields" <bfields@fieldses.org>,
Oleg Nesterov <onestero@redhat.com>,
Stanislav Kinsbursky <skinsbursky@parallels.com>,
Trond Myklebust <trond.myklebust@primarydata.com>,
David Howells <dhowells@redhat.com>,
Benjamin Coddington <bcodding@redhat.com>,
Al Viro <viro@ZenIV.linux.org.uk>,
"Eric W. Biederman" <ebiederm@xmission.com>
Subject: [RFC PATCH 1/4] vfs - fs/namespaces.c: break out mntns_setfs() from mntns_install()
Date: Tue, 25 Nov 2014 09:07:21 +0800 [thread overview]
Message-ID: <20141125010719.4974.68177.stgit@pluto.fritz.box> (raw)
In-Reply-To: <20141125005255.4974.54193.stgit@pluto.fritz.box>
Some users of kmod.c's usermodehelper need to setup their fs_struct
root and pwd based on the callers namespaces after the kernel thread
runner has created a new process but before do_execve() is called.
Break out the fs_struct portion of mntns_install so it can be used
for this purpose.
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Ian Kent <ikent@redhat.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: J. Bruce Fields <bfields@fieldses.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Trond Myklebust <trond.myklebust@primarydata.com>
Cc: Stanislav Kinsbursky <skinsbursky@parallels.com>
Cc: Oleg Nesterov <onestero@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
---
fs/namespace.c | 41 +++++++++++++++++++++++++++++------------
include/linux/mount.h | 1 +
2 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 5b66b2b..3cdbb9e 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3165,11 +3165,38 @@ static void mntns_put(void *ns)
put_mnt_ns(ns);
}
+/*
+ * Set fs root and pwd for a subsequent call to do_execve().
+ *
+ * This assumes that an nsproxy has been created within the
+ * namespace context that is the target for the exec so that
+ * mnt_ns is already set. Additionally, since the nsproxy is
+ * created within the requesting namespace context the security
+ * checks of mntns_install() aren't required.
+ */
+void mntns_setfs(struct mnt_namespace *mnt_ns)
+{
+ struct fs_struct *fs = current->fs;
+ struct path root;
+
+ /* Find the root */
+ root.mnt = &mnt_ns->root->mnt;
+ root.dentry = mnt_ns->root->mnt.mnt_root;
+ path_get(&root);
+ while(d_mountpoint(root.dentry) && follow_down_one(&root))
+ ;
+
+ /* Update the pwd and root */
+ set_fs_pwd(fs, &root);
+ set_fs_root(fs, &root);
+
+ path_put(&root);
+}
+
static int mntns_install(struct nsproxy *nsproxy, void *ns)
{
struct fs_struct *fs = current->fs;
struct mnt_namespace *mnt_ns = ns;
- struct path root;
if (!ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN) ||
!ns_capable(current_user_ns(), CAP_SYS_CHROOT) ||
@@ -3183,18 +3210,8 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
put_mnt_ns(nsproxy->mnt_ns);
nsproxy->mnt_ns = mnt_ns;
- /* Find the root */
- root.mnt = &mnt_ns->root->mnt;
- root.dentry = mnt_ns->root->mnt.mnt_root;
- path_get(&root);
- while(d_mountpoint(root.dentry) && follow_down_one(&root))
- ;
-
- /* Update the pwd and root */
- set_fs_pwd(fs, &root);
- set_fs_root(fs, &root);
+ mntns_setfs(mnt_ns);
- path_put(&root);
return 0;
}
diff --git a/include/linux/mount.h b/include/linux/mount.h
index c2c561d..a9f6548 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -80,6 +80,7 @@ extern void mntput(struct vfsmount *mnt);
extern struct vfsmount *mntget(struct vfsmount *mnt);
extern struct vfsmount *mnt_clone_internal(struct path *path);
extern int __mnt_is_readonly(struct vfsmount *mnt);
+void mntns_setfs(struct mnt_namespace *mnt_ns);
struct path;
extern struct vfsmount *clone_private_mount(struct path *path);
next prev parent reply other threads:[~2014-11-25 1:07 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 1:07 [RFC PATCH 0/4] Namespace contrained helper execution Ian Kent
2014-11-25 1:07 ` Ian Kent [this message]
2014-11-25 1:07 ` [RFC PATCH 2/4] nsproxy - make create_new_namespaces() non-static Ian Kent
2014-11-25 1:07 ` [RFC PATCH 3/4] kmod - add call_usermodehelper_ns() helper Ian Kent
2014-11-25 21:52 ` Oleg Nesterov
2014-11-25 22:06 ` Oleg Nesterov
2014-11-25 22:23 ` Eric W. Biederman
2014-11-25 23:07 ` Ian Kent
2014-11-25 23:19 ` Eric W. Biederman
2014-11-25 23:50 ` Ian Kent
2014-11-26 0:44 ` Ian Kent
2014-11-26 1:38 ` Eric W. Biederman
2014-12-01 21:56 ` Benjamin Coddington
2014-12-02 23:33 ` Ian Kent
2014-12-03 16:49 ` Eric W. Biederman
2014-12-03 18:14 ` Benjamin Coddington
2014-12-03 22:53 ` Ian Kent
2014-12-03 23:34 ` Ian Kent
2014-11-26 11:46 ` David Howells
2014-11-26 15:00 ` Eric W. Biederman
2014-11-26 22:57 ` J. Bruce Fields
2014-11-25 23:14 ` Ian Kent
2014-11-25 22:36 ` Ian Kent
2014-11-25 23:27 ` Eric W. Biederman
2014-11-28 0:19 ` Ian Kent
2014-11-27 1:30 ` Oleg Nesterov
2014-11-25 1:07 ` [RFC PATCH 4/4] KEYS: exec request-key within the requesting task's namespace Ian Kent
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=20141125010719.4974.68177.stgit@pluto.fritz.box \
--to=ikent@redhat.com \
--cc=bcodding@redhat.com \
--cc=bfields@fieldses.org \
--cc=dhowells@redhat.com \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=onestero@redhat.com \
--cc=skinsbursky@parallels.com \
--cc=trond.myklebust@primarydata.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.