linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Waychison <michael.waychison@sun.com>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: raven@themaw.net
Subject: [PATCH 17/28] VFS: Mountpoint file descriptor walking
Date: Mon, 25 Oct 2004 10:47:09 -0400	[thread overview]
Message-ID: <10987156292985@sun.com> (raw)
In-Reply-To: <10987155992813@sun.com>

This patch allows one to walk the mountpoint tree given a mountfd.  There are
two operations permitted:

MOUNTFD_IOC_GETFIRSTCHILD - Given a mountfd, return the first child mountpoint
                            as a mountfd.
MOUNTFD_IOC_GETNEXTCHILD  - Given a mountfd, return the next mountpoint sibling
                            to it. (*)

(*) XXX: This should be modified to also take a parent mountfd so that you
can't walk out of a chroot.

We explicitly don't allow walks to the parent of a mountpoint as that would
allow for a user to easily walk out of a chroot.

Signed-off-by: Mike Waychison <michael.waychison@sun.com>
---

 fs/mountfd.c       |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h |    3 +++
 2 files changed, 49 insertions(+)

Index: linux-2.6.9-quilt/include/linux/fs.h
===================================================================
--- linux-2.6.9-quilt.orig/include/linux/fs.h	2004-10-22 17:17:42.012077336 -0400
+++ linux-2.6.9-quilt/include/linux/fs.h	2004-10-22 17:17:42.625984008 -0400
@@ -219,6 +219,9 @@ extern int leases_enable, dir_notify_ena
 #define MOUNTFD_IOC_DETACH        _IO('p', 0xa2)
 #define MOUNTFD_IOC_FORCEDUNMOUNT _IO('p', 0xa3)
 #define MOUNTFD_IOC_ATTACH        _IOW('p', 0xa4, int)
+#define MOUNTFD_IOC_GETFIRSTCHILD _IO('p', 0xa5)
+/* TODO: change this interface to require the parent mfd as well */
+#define MOUNTFD_IOC_GETNEXTCHILD  _IO('p', 0xa6)
 
 #ifdef __KERNEL__
 
Index: linux-2.6.9-quilt/fs/mountfd.c
===================================================================
--- linux-2.6.9-quilt.orig/fs/mountfd.c	2004-10-22 17:17:42.011077488 -0400
+++ linux-2.6.9-quilt/fs/mountfd.c	2004-10-22 17:17:42.625984008 -0400
@@ -284,6 +284,48 @@ out:
 	return ret;
 }
 
+static long mfd_firstchild(struct file *mountfilp)
+{
+	struct vfsmount *mnt, *childmnt = NULL;
+	int ret;
+	
+	mnt = mntget(VFSMOUNT(mountfilp));
+
+	spin_lock(&vfsmount_lock);
+	if (!list_empty(&mnt->mnt_mounts))
+		childmnt = mntget(container_of(mnt->mnt_mounts.next, struct vfsmount, mnt_child));
+	spin_unlock(&vfsmount_lock);
+
+	ret = -ENOENT;
+	if (childmnt)
+		ret = open_mfd(childmnt);
+
+	mntput(childmnt);
+	mntput(mnt);
+	return ret;
+}
+
+static long mfd_nextchild(struct file *mountfilp)
+{
+	struct vfsmount *mnt, *nextmnt = NULL;
+	int ret;
+
+	mnt = mntget(VFSMOUNT(mountfilp));
+
+	spin_lock(&vfsmount_lock);
+	if (mnt->mnt_child.next != &mnt->mnt_parent->mnt_mounts)
+		nextmnt = mntget(container_of(mnt->mnt_child.next, struct vfsmount, mnt_child));
+	spin_unlock(&vfsmount_lock);
+
+	ret = -ENOENT;
+	if (nextmnt)
+		ret = open_mfd(nextmnt);
+
+	mntput(nextmnt);
+	mntput(mnt);
+	return ret;
+}
+
 static int mfd_ioctl(struct inode *inode, struct file *filp,
 		     unsigned int cmd, unsigned long arg)
 {
@@ -298,6 +340,10 @@ static int mfd_ioctl(struct inode *inode
 		return mfd_umount(filp, MNT_FORCE);
 	case MOUNTFD_IOC_ATTACH:
 		return mfd_attach(filp, arg);
+	case MOUNTFD_IOC_GETFIRSTCHILD:
+		return mfd_firstchild(filp);
+	case MOUNTFD_IOC_GETNEXTCHILD:
+		return mfd_nextchild(filp);
 	}
 	return -ENOTTY;
 }


  reply	other threads:[~2004-10-25 14:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <10987155332448@sun.com>
2004-10-25 14:46 ` [PATCH 15/28] VFS: Mountpoint file descriptor umount support Mike Waychison
2004-10-25 14:46   ` [PATCH 16/28] VFS: Mountpoint file descriptor attach support Mike Waychison
2004-10-25 14:47     ` Mike Waychison [this message]
2004-10-25 14:47       ` [PATCH 18/28] VFS: Mountpoint file descriptor read properties Mike Waychison
2004-10-25 14:48         ` [PATCH 19/28] VFS: Mountpoint file descriptor expiry support Mike Waychison
2004-10-25 14:48           ` [PATCH 20/28] HOTPLUG: call_usermodehelper callback support Mike Waychison
2004-10-25 14:49             ` [PATCH 21/28] HOTPLUG: Hack to allow for call to execve Mike Waychison
2004-10-25 14:49               ` [PATCH 22/28] VFS: Export put_namespace Mike Waychison
2004-10-25 14:50                 ` [PATCH 23/28] VFS: Export get_sb_pseudo Mike Waychison
2004-10-25 14:50                   ` [PATCH 24/28] VFS: Fixup for ->follow_link on root of filesystem Mike Waychison
2004-10-25 14:51                     ` [PATCH 25/28] VFS: statfs(64) shouldn't follow last component symlink Mike Waychison
2004-10-25 14:51                       ` [PATCH 26/28] VFS: Introduce MNT_NOFOLLOW Mike Waychison
2004-10-25 14:52                         ` [PATCH 27/28] Testing syscall for expiry Mike Waychison
2004-10-25 15:01                           ` Christoph Hellwig
2004-10-25 15:37                           ` [PATCH 28/28] AUTOFSNG: New autofs filesystem (resend) Mike Waychison
2004-10-25 15:14                       ` [PATCH 25/28] VFS: statfs(64) shouldn't follow last component symlink Christoph Hellwig
2004-10-25 15:21                         ` Mike Waychison
2004-10-25 15:18             ` [PATCH 20/28] HOTPLUG: call_usermodehelper callback support Christoph Hellwig
2004-10-25 15:29               ` Mike Waychison
2004-10-26 10:28   ` [PATCH 15/28] VFS: Mountpoint file descriptor umount support Christoph Hellwig
2004-10-26 14:16     ` Mike Waychison

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=10987156292985@sun.com \
    --to=michael.waychison@sun.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=raven@themaw.net \
    /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;
as well as URLs for NNTP newsgroup(s).